From 4a0d3ba7ce6b9047d2840d562963c339d026edf7 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 22 2015 09:59:18 +0000 Subject: Add unit-tests for the delete_issue endpoint --- diff --git a/tests/test_progit_flask_ui_issues.py b/tests/test_progit_flask_ui_issues.py index 496e68f..6376023 100644 --- a/tests/test_progit_flask_ui_issues.py +++ b/tests/test_progit_flask_ui_issues.py @@ -1038,7 +1038,6 @@ class PagureFlaskIssuestests(tests.Modeltests): output = self.app.get('/test' + url) self.assertEqual(output.status_code, 404) - @patch('pagure.lib.git.update_git') @patch('pagure.lib.notify.send_email') def test_edit_issue(self, p_send_email, p_ugt): @@ -1300,6 +1299,85 @@ class PagureFlaskIssuestests(tests.Modeltests): self.assertTrue( '
  • Removed tag: tag1
  • ' in output.data) + @patch('pagure.lib.git.update_git') + @patch('pagure.lib.notify.send_email') + def test_delete_issue(self, p_send_email, p_ugt): + """ Test the delete_issue endpoint. """ + p_send_email.return_value = True + p_ugt.return_value = True + + tests.create_projects(self.session) + tests.create_projects_git(tests.HERE) + tests.create_projects_git(os.path.join(tests.HERE, 'tickets')) + + # Create issues to play with + repo = pagure.lib.get_project(self.session, 'test') + msg = pagure.lib.new_issue( + session=self.session, + repo=repo, + title='Test issue', + content='We should work on this', + user='pingou', + ticketfolder=None + ) + self.session.commit() + self.assertEqual(msg.title, 'Test issue') + + user = tests.FakeUser() + with tests.user_set(pagure.APP, user): + output = self.app.post( + '/foo/issue/1/drop', follow_redirects=True) + self.assertEqual(output.status_code, 404) + + output = self.app.post( + '/test/issue/100/drop', follow_redirects=True) + self.assertEqual(output.status_code, 404) + + output = self.app.post( + '/test/issue/1/drop', follow_redirects=True) + self.assertEqual(output.status_code, 403) + + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + output = self.app.post( + '/test/issue/1/drop', follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Issue #1 - test - Pagure', output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + data = { + } + + # No CSRF token + output = self.app.post( + '/test/issue/1/drop', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Issue #1 - test - Pagure', output.data) + + data['csrf_token'] = csrf_token + output = self.app.post( + '/test/issue/1/drop', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertIn( + 'Issues - test - Pagure', output.data) + self.assertIn( + '
  • Issue deleted
  • ', output.data) + + # Project w/o issue tracker + repo = pagure.lib.get_project(self.session, 'test') + repo.settings = {'issue_tracker': False} + self.session.add(repo) + self.session.commit() + + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + output = self.app.post('/test/issue/1/drop', data=data) + self.assertEqual(output.status_code, 404) + if __name__ == '__main__': SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskIssuestests)