| |
@@ -1529,6 +1529,93 @@
|
| |
follow_redirects=True)
|
| |
self.assertEqual(output.status_code, 404)
|
| |
|
| |
+ @patch('pagure.lib.notify.send_email')
|
| |
+ def test_pull_request_edit_comment(self, send_email):
|
| |
+ """ Test the pull request edit comment endpoint """
|
| |
+ send_email.return_value = True
|
| |
+
|
| |
+ self.test_request_pull()
|
| |
+
|
| |
+ user = tests.FakeUser()
|
| |
+ user.username = 'pingou'
|
| |
+ with tests.user_set(pagure.APP, user):
|
| |
+ # Repo 'foo' does not exist so it is verifying that condition
|
| |
+ output = self.app.post('/foo/pull-request/1/comment/1/edit')
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
+
|
| |
+ # Here no comment is present in the PR so its verifying that condition
|
| |
+ output = self.app.post('/test/pull-request/100/comment/100/edit')
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
+
|
| |
+ output = self.app.post('/test/pull-request/1/comment')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+ # Creating comment to play with
|
| |
+ self.assertTrue(
|
| |
+ output.data.startswith('<section class="add_comment">'))
|
| |
+
|
| |
+ csrf_token = output.data.split(
|
| |
+ 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
| |
+
|
| |
+ data = {
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ 'comment': 'This look alright but we can do better',
|
| |
+ }
|
| |
+ output = self.app.post(
|
| |
+ '/test/pull-request/1/comment', data=data,
|
| |
+ follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+
|
| |
+ self.assertIn(
|
| |
+ '<title>PR#1: PR from the feature branch - test - '
|
| |
+ 'Pagure</title>', output.data)
|
| |
+ self.assertIn(
|
| |
+ '<li class="message">Comment added</li>', output.data)
|
| |
+ # Check if the comment is there
|
| |
+ self.assertIn(
|
| |
+ '<p>This look alright but we can do better</p>', output.data)
|
| |
+ output = self.app.get('/test/pull-request/1/comment/1/edit')
|
| |
+ self.assertEqual(output.status_code, 200)
|
| |
+
|
| |
+ self.assertIn('<section class="request_comment add_comment">', output.data)
|
| |
+ # Checking if the comment is there in the update page
|
| |
+ self.assertIn(
|
| |
+ 'This look alright but we can do better</textarea>', output.data)
|
| |
+
|
| |
+ csrf_token = output.data.split(
|
| |
+ 'name="csrf_token" type="hidden" value="')[1].split('">')[0]
|
| |
+
|
| |
+ data = {
|
| |
+ 'csrf_token': csrf_token,
|
| |
+ 'update_comment': 'This look alright but we can do better than this.',
|
| |
+ }
|
| |
+ output = self.app.post(
|
| |
+ '/test/pull-request/1/comment/1/edit', data=data,
|
| |
+ follow_redirects=True)
|
| |
+ # Checking if the comment is updated in the main page
|
| |
+ self.assertIn(
|
| |
+ '<p>This look alright but we can do better than this.</p>', output.data)
|
| |
+ self.assertIn(
|
| |
+ '<title>PR#1: PR from the feature branch - test - '
|
| |
+ 'Pagure</title>', output.data)
|
| |
+ # Checking if Edited by User is there or not
|
| |
+ self.assertIn(
|
| |
+ '<span title="">Edited by pingou just now</span>', output.data)
|
| |
+ self.assertIn(
|
| |
+ '<li class="message">Comment updated</li>', output.data)
|
| |
+
|
| |
+
|
| |
+ # Project w/o pull-request
|
| |
+ repo = pagure.lib.get_project(self.session, 'test')
|
| |
+ settings = repo.settings
|
| |
+ settings['pull_requests'] = False
|
| |
+ repo.settings = settings
|
| |
+ self.session.add(repo)
|
| |
+ self.session.commit()
|
| |
+
|
| |
+ output = self.app.post(
|
| |
+ '/test/pull-request/1/comment/edit/1', data=data,
|
| |
+ follow_redirects=True)
|
| |
+ self.assertEqual(output.status_code, 404)
|
| |
|
| |
if __name__ == '__main__':
|
| |
SUITE = unittest.TestLoader().loadTestsFromTestCase(PagureFlaskForktests)
|
| |