From 3c91f08fe048d1e4975144b624a57ed90081e1d2 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 20 2015 11:09:18 +0000 Subject: Add unit-tests for adding dependency on ticket via update_issue --- diff --git a/tests/test_progit_flask_ui_issues.py b/tests/test_progit_flask_ui_issues.py index 7a095d2..7e825f7 100644 --- a/tests/test_progit_flask_ui_issues.py +++ b/tests/test_progit_flask_ui_issues.py @@ -643,6 +643,86 @@ class PagureFlaskIssuestests(tests.Modeltests): @patch('pagure.lib.git.update_git') @patch('pagure.lib.notify.send_email') + def test_update_issue_depend(self, p_send_email, p_ugt): + """ Test adding dependency via the update_issue endpoint. """ + p_send_email.return_value = True + p_ugt.return_value = True + + tests.create_projects(self.session) + + # 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') + + repo = pagure.lib.get_project(self.session, 'test') + msg = pagure.lib.new_issue( + session=self.session, + repo=repo, + title='Test issue #2', + content='We should work on this again', + user='foo', + ticketfolder=None + ) + self.session.commit() + self.assertEqual(msg.title, 'Test issue #2') + + user = tests.FakeUser() + user.username = 'pingou' + with tests.user_set(pagure.APP, user): + output = self.app.get('/test/issue/1') + self.assertEqual(output.status_code, 200) + self.assertTrue( + '

test project #1

' + in output.data) + + csrf_token = output.data.split( + 'name="csrf_token" type="hidden" value="')[1].split('">')[0] + + # Add a dependent ticket + data = { + 'csrf_token': csrf_token, + 'depends': '2', + } + output = self.app.post( + '/test/issue/1/update', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertTrue( + '

test project #1

' + in output.data) + #print output.data + self.assertTrue( + '
  • Dependency added
  • ' in output.data) + + # Add an invalid dependent ticket + data = { + 'csrf_token': csrf_token, + 'depends': '2,abc', + } + output = self.app.post( + '/test/issue/1/update', data=data, follow_redirects=True) + self.assertEqual(output.status_code, 200) + self.assertTrue( + '

    test project #1

    ' + in output.data) + self.assertFalse( + '
  • Dependency added
  • ' in output.data) + + repo = pagure.lib.get_project(self.session, 'test') + issue = pagure.lib.search_issues(self.session, repo, issueid=1) + self.assertEqual(issue.depends_text, [2]) + self.assertEqual(issue.blocks_text, []) + + @patch('pagure.lib.git.update_git') + @patch('pagure.lib.notify.send_email') def test_edit_issue(self, p_send_email, p_ugt): """ Test the edit_issue endpoint. """ p_send_email.return_value = True