changeset 7610:fd948cfea29a

tests: add missing tests for closing and deleting pullrequests Delete and close of pull requests was recently found broken and fixed in commit 56233b874eba. Add some tests that would have detected the breakage automatically.
author Thomas De Schampheleire <thomas.de_schampheleire@nokia.com>
date Tue, 26 Mar 2019 21:32:47 +0100
parents 56233b874eba
children 9efcf6b78f71
files kallithea/tests/functional/test_changeset_pullrequests_comments.py
diffstat 1 files changed, 66 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/tests/functional/test_changeset_pullrequests_comments.py	Sun Mar 24 17:57:34 2019 +0100
+++ b/kallithea/tests/functional/test_changeset_pullrequests_comments.py	Tue Mar 26 21:32:47 2019 +0100
@@ -2,7 +2,7 @@
 
 from kallithea.tests.base import *
 from kallithea.model.changeset_status import ChangesetStatusModel
-from kallithea.model.db import ChangesetComment
+from kallithea.model.db import ChangesetComment, PullRequest
 from kallithea.model.meta import Session
 
 
@@ -310,3 +310,68 @@
             ''' 1 comment (0 inline, 1 general)'''
         )
         response.mustcontain(no=text)
+
+    def test_close_pr(self):
+        self.log_user()
+        pr_id = self._create_pr()
+
+        text = u'general comment on pullrequest'
+        params = {'text': text, 'save_close': 'close',
+                '_authentication_token': self.authentication_token()}
+        response = self.app.post(url(controller='pullrequests', action='comment',
+                                     repo_name=HG_REPO, pull_request_id=pr_id),
+                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
+        # Test response...
+        assert response.status == '200 OK'
+
+        response = self.app.get(url(controller='pullrequests', action='show',
+                                repo_name=HG_REPO, pull_request_id=pr_id, extra=''))
+        response.mustcontain(
+            '''title (Closed)'''
+        )
+        response.mustcontain(text)
+
+        # test DB
+        assert PullRequest.get(pr_id).status == PullRequest.STATUS_CLOSED
+
+    def test_delete_pr(self):
+        self.log_user()
+        pr_id = self._create_pr()
+
+        text = u'general comment on pullrequest'
+        params = {'text': text, 'save_delete': 'delete',
+                '_authentication_token': self.authentication_token()}
+        response = self.app.post(url(controller='pullrequests', action='comment',
+                                     repo_name=HG_REPO, pull_request_id=pr_id),
+                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
+        # Test response...
+        assert response.status == '200 OK'
+
+        response = self.app.get(url(controller='pullrequests', action='show',
+                                repo_name=HG_REPO, pull_request_id=pr_id, extra=''), status=404)
+
+        # test DB
+        assert PullRequest.get(pr_id) is None
+
+    def test_delete_closed_pr(self):
+        self.log_user()
+        pr_id = self._create_pr()
+
+        # first close
+        text = u'general comment on pullrequest'
+        params = {'text': text, 'save_close': 'close',
+                '_authentication_token': self.authentication_token()}
+        response = self.app.post(url(controller='pullrequests', action='comment',
+                                     repo_name=HG_REPO, pull_request_id=pr_id),
+                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'})
+        assert response.status == '200 OK'
+
+        # attempt delete, should fail
+        params = {'text': text, 'save_delete': 'delete',
+                '_authentication_token': self.authentication_token()}
+        response = self.app.post(url(controller='pullrequests', action='comment',
+                                     repo_name=HG_REPO, pull_request_id=pr_id),
+                                     params=params, extra_environ={'HTTP_X_PARTIAL_XHR': '1'}, status=403)
+
+        # verify that PR still exists, in closed state
+        assert PullRequest.get(pr_id).status == PullRequest.STATUS_CLOSED