From cec97dda12d6af6a11168b3fc2fa97ff8493de45 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 21 2015 16:49:50 +0000 Subject: Add unit-tests for the new_request_pull endpoint --- diff --git a/tests/test_progit_flask_ui_fork.py b/tests/test_progit_flask_ui_fork.py index c74c4af..3f4de77 100644 --- a/tests/test_progit_flask_ui_fork.py +++ b/tests/test_progit_flask_ui_fork.py @@ -1205,6 +1205,81 @@ index 0000000..2a552bb '
  • Repo "test" cloned to ' '"foo/test"
  • ', output.data) + @patch('pagure.lib.notify.send_email') + def test_new_request_pull(self, send_email): + """ Test the new_request_pull endpoint. """ + send_email.return_value = True + + self.test_fork_project() + + tests.create_projects_git( + os.path.join(tests.HERE, 'requests'), bare=True) + + repo = pagure.lib.get_project(self.session, 'test') + fork = pagure.lib.get_project(self.session, 'test', user='foo') + + self.set_up_git_repo( + new_project=fork, branch_from='feature', mtype='FF') + + user = tests.FakeUser() + user.username = 'foo' + with tests.user_set(pagure.APP, user): + output = self.app.get('/foo/diff/master..feature') + self.assertEqual(output.status_code, 404) + + output = self.app.get('/test/diff/master..foo') + self.assertEqual(output.status_code, 400) + + output = self.app.get('/test/diff/foo..master') + self.assertEqual(output.status_code, 400) + + output = self.app.get('/test/diff/feature..master') + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Pull request # - test - Pagure', + output.data) + self.assertIn( + '

    No commits found

    ', output.data) + + output = self.app.get('/test/diff/master..feature') + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Pull request # - test - Pagure', + output.data) + self.assertNotIn( + '', output.data) + + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + output = self.app.get('/test/diff/master..feature') + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Pull request # - test - Pagure', + output.data) + self.assertIn( + '', output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + + data = { + 'csrf_token': csrf_token, + 'title': 'foo bar PR', + } + + output = self.app.post( + '/test/diff/master..feature', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Pull requests - test - Pagure', output.data) + self.assertIn( + '
  • Request created
  • ', output.data) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskForktests)