diff --git a/tests/test_pagure_flask_ui_app.py b/tests/test_pagure_flask_ui_app.py index 77522e0..93a9f5f 100644 --- a/tests/test_pagure_flask_ui_app.py +++ b/tests/test_pagure_flask_ui_app.py @@ -296,6 +296,87 @@ class PagureFlaskApptests(tests.Modeltests): self.assertTrue(os.path.exists( os.path.join(self.path, 'requests', 'project-1.git'))) + @patch.dict('pagure.APP.config', {'PRIVATE_PROJECTS': True}) + def test_new_project_private(self): + """ Test the new_project endpoint for a private project. """ + # Before + projects = pagure.lib.search_projects(self.session) + self.assertEqual(len(projects), 0) + self.assertFalse(os.path.exists( + os.path.join(self.path, 'foo', 'project#1.git'))) + self.assertFalse(os.path.exists( + os.path.join(self.path, 'tickets', 'foo', 'project#1.git'))) + self.assertFalse(os.path.exists( + os.path.join(self.path, 'docs', 'foo', 'project#1.git'))) + self.assertFalse(os.path.exists( + os.path.join(self.path, 'requests', 'foo', 'project#1.git'))) + + user = tests.FakeUser() + with tests.user_set(pagure.APP, user): + output = self.app.get('/new/') + self.assertEqual(output.status_code, 200) + self.assertIn( + u'Create new Project', output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + data = { + 'description': 'Project #1', + 'private': True, + } + + output = self.app.post('/new/', data=data) + self.assertEqual(output.status_code, 200) + self.assertIn( + u'Create new Project', output.data) + self.assertIn( + u'\n This field is required. \n' + ' ', output.data) + + data['name'] = 'project-1' + output = self.app.post('/new/', data=data) + self.assertEqual(output.status_code, 200) + self.assertIn('Create new Project', output.data) + self.assertNotIn( + u'\n This field is required. \n' + ' ', output.data) + + data['csrf_token'] = csrf_token + output = self.app.post('/new/', data=data) + self.assertEqual(output.status_code, 200) + self.assertIn('Create new Project', output.data) + self.assertIn( + u'\n No user ' + '"username" found\n ', + output.data) + + user.username = 'foo' + with tests.user_set(pagure.APP, user): + data['csrf_token'] = csrf_token + output = self.app.post('/new/', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + u'
This repo is brand new!
', output.data) + self.assertIn( + u'