diff --git a/tests/test_progit_flask_ui_app.py b/tests/test_progit_flask_ui_app.py index 60fefa2..c3bc8d6 100644 --- a/tests/test_progit_flask_ui_app.py +++ b/tests/test_progit_flask_ui_app.py @@ -108,6 +108,74 @@ class ProgitFlaskApptests(tests.Modeltests): '
' in output.data) self.assertTrue('

Forks (0)

' in output.data) + def test_new_project(self): + """ Test the new_project endpoint. """ + # Before + projects = progit.lib.search_projects(self.session) + self.assertEqual(len(projects), 0) + self.assertFalse(os.path.exists( + os.path.join(tests.HERE, 'project#1.git'))) + self.assertFalse(os.path.exists( + os.path.join(tests.HERE, 'tickets', 'project#1.git'))) + self.assertFalse(os.path.exists( + os.path.join(tests.HERE, 'docs', 'project#1.git'))) + + user = tests.FakeUser() + with tests.user_set(progit.APP, user): + output = self.app.get('/new/') + self.assertEqual(output.status_code, 200) + self.assertTrue('

New project

' in output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + data = { + 'description': 'Project #1', + } + + output = self.app.post('/new/', data=data) + self.assertEqual(output.status_code, 200) + self.assertTrue('

New project

' in output.data) + self.assertTrue( + 'This field is required.' + in output.data) + + data['name'] = 'project#1' + output = self.app.post('/new/', data=data) + self.assertEqual(output.status_code, 200) + self.assertTrue('

New project

' in output.data) + self.assertFalse( + 'This field is required.' + in output.data) + + data['csrf_token'] = csrf_token + output = self.app.post('/new/', data=data) + self.assertEqual(output.status_code, 200) + self.assertTrue('

New project

' in output.data) + self.assertTrue( + '
  • No user "username" found
  • ' + in output.data) + + user.username = 'foo' + with tests.user_set(progit.APP, user): + data['csrf_token'] = csrf_token + output = self.app.post('/new/', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertTrue('

    Project #1

    ' in output.data) + self.assertTrue( + '
  • Project "project#1" created
  • ' + in output.data) + + # After + projects = progit.lib.search_projects(self.session) + self.assertEqual(len(projects), 1) + self.assertTrue(os.path.exists( + os.path.join(tests.HERE, 'project#1.git'))) + self.assertTrue(os.path.exists( + os.path.join(tests.HERE, 'tickets', 'project#1.git'))) + self.assertTrue(os.path.exists( + os.path.join(tests.HERE, 'docs', 'project#1.git'))) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(ProgitFlaskApptests)