# HG changeset patch # User Marcin Kuzminski # Date 2017-07-27 12:46:02 # Node ID 455f23f1afc3d49364435eca98ead8269b871b1e # Parent cd9c800f4532bd31cbf6894bfdc8ef94f656fc63 pull-requests: fix deletion of comments and make the test actually test this ! - broken test failed to detect obvious error on comment deletion diff --git a/rhodecode/apps/repository/tests/test_repo_pullrequests.py b/rhodecode/apps/repository/tests/test_repo_pullrequests.py --- a/rhodecode/apps/repository/tests/test_repo_pullrequests.py +++ b/rhodecode/apps/repository/tests/test_repo_pullrequests.py @@ -1084,16 +1084,41 @@ class TestPullrequestsControllerDelete(o response.mustcontain(no=['Confirm to delete this pull request']) def test_delete_comment_returns_404_if_comment_does_not_exist( - self, autologin_user, pr_util, user_admin): + self, autologin_user, pr_util, user_admin, csrf_token, xhr_header): pull_request = pr_util.create_pull_request( author=user_admin.username, enable_notifications=False) - self.app.get(route_path( + self.app.post( + route_path( 'pullrequest_comment_delete', repo_name=pull_request.target_repo.scm_instance().name, pull_request_id=pull_request.pull_request_id, - comment_id=1024404), status=404) + comment_id=1024404), + extra_environ=xhr_header, + params={'csrf_token': csrf_token}, + status=404 + ) + + def test_delete_comment( + self, autologin_user, pr_util, user_admin, csrf_token, xhr_header): + + pull_request = pr_util.create_pull_request( + author=user_admin.username, enable_notifications=False) + comment = pr_util.create_comment() + comment_id = comment.comment_id + + response = self.app.post( + route_path( + 'pullrequest_comment_delete', + repo_name=pull_request.target_repo.scm_instance().name, + pull_request_id=pull_request.pull_request_id, + comment_id=comment_id), + extra_environ=xhr_header, + params={'csrf_token': csrf_token}, + status=200 + ) + assert response.body == 'true' def assert_pull_request_status(pull_request, expected_status): diff --git a/rhodecode/apps/repository/views/repo_pull_requests.py b/rhodecode/apps/repository/views/repo_pull_requests.py --- a/rhodecode/apps/repository/views/repo_pull_requests.py +++ b/rhodecode/apps/repository/views/repo_pull_requests.py @@ -1142,9 +1142,8 @@ class RepoPullRequestsView(RepoAppView, route_name='pullrequest_comment_delete', request_method='POST', renderer='json_ext') def pull_request_comment_delete(self): - commit_id = self.request.matchdict['commit_id'] + pull_request_id = self.request.matchdict['pull_request_id'] comment_id = self.request.matchdict['comment_id'] - pull_request_id = self.request.matchdict['pull_request_id'] pull_request = PullRequest.get_or_404(pull_request_id) if pull_request.is_closed():