From 652a237e35b7779a6afbc8ee137380440286d029 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 21 2015 15:11:27 +0000 Subject: Add unit-tests for the fork_project endpoint --- diff --git a/tests/test_progit_flask_ui_fork.py b/tests/test_progit_flask_ui_fork.py index 550f72f..18ccde1 100644 --- a/tests/test_progit_flask_ui_fork.py +++ b/tests/test_progit_flask_ui_fork.py @@ -1150,6 +1150,60 @@ index 0000000..2a552bb follow_redirects=True) self.assertEqual(output.status_code, 404) + @patch('pagure.lib.notify.send_email') + def test_fork_project(self, send_email): + """ Test the fork_project endpoint. """ + send_email.return_value = True + + tests.create_projects(self.session) + for folder in ['docs', 'tickets', 'requets', 'repos']: + tests.create_projects_git( + os.path.join(tests.HERE, folder), bare=True) + + user = tests.FakeUser() + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + output = self.app.post('/do_fork/test') + self.assertEqual(output.status_code, 400) + + 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 = { + 'csrf_token': csrf_token, + } + + output = self.app.post( + '/do_fork/foo', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 404) + + output = self.app.post( + '/do_fork/test', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + '
  • You may not fork your own repo
  • ', + output.data) + + user.username = 'foo' + with tests.user_set(pagure.APP, user): + output = self.app.post('/do_fork/test') + self.assertEqual(output.status_code, 400) + + data = { + 'csrf_token': csrf_token, + } + + output = self.app.post( + '/do_fork/test', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + '
  • Repo "test" cloned to ' + '"foo/test"
  • ', output.data) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskForktests)