##// END OF EJS Templates
tests: fixed api merge tests after introducing merge checks.
marcink -
r1336:6cf63f71 default
parent child Browse files
Show More
@@ -20,18 +20,17 b''
20 20
21 21 import pytest
22 22
23 from rhodecode.model.db import UserLog
23 from rhodecode.model.db import UserLog, PullRequest
24 24 from rhodecode.model.meta import Session
25 from rhodecode.model.pull_request import PullRequestModel
26 25 from rhodecode.tests import TEST_USER_ADMIN_LOGIN
27 26 from rhodecode.api.tests.utils import (
28 build_data, api_call, assert_error)
27 build_data, api_call, assert_error, assert_ok)
29 28
30 29
31 30 @pytest.mark.usefixtures("testuser_api", "app")
32 31 class TestMergePullRequest(object):
33 32 @pytest.mark.backends("git", "hg")
34 def test_api_merge_pull_request(self, pr_util, no_notifications):
33 def test_api_merge_pull_request_merge_failed(self, pr_util, no_notifications):
35 34 pull_request = pr_util.create_pull_request(mergeable=True)
36 35 author = pull_request.user_id
37 36 repo = pull_request.target_repo.repo_id
@@ -51,6 +50,41 b' class TestMergePullRequest(object):'
51 50 # it.
52 51 Session().add(pull_request)
53 52
53 expected = 'merge not possible for following reasons: ' \
54 'Pull request reviewer approval is pending.'
55 assert_error(id_, expected, given=response.body)
56
57 @pytest.mark.backends("git", "hg")
58 def test_api_merge_pull_request(self, pr_util, no_notifications):
59 pull_request = pr_util.create_pull_request(mergeable=True, approved=True)
60 author = pull_request.user_id
61 repo = pull_request.target_repo.repo_id
62 pull_request_id = pull_request.pull_request_id
63 pull_request_repo = pull_request.target_repo.repo_name
64
65 id_, params = build_data(
66 self.apikey, 'comment_pull_request',
67 repoid=pull_request_repo,
68 pullrequestid=pull_request_id,
69 status='approved')
70
71 response = api_call(self.app, params)
72 expected = {
73 'comment_id': response.json.get('result', {}).get('comment_id'),
74 'pull_request_id': pull_request_id,
75 'status': {'given': 'approved', 'was_changed': True}
76 }
77 assert_ok(id_, expected, given=response.body)
78
79 id_, params = build_data(
80 self.apikey, 'merge_pull_request',
81 repoid=pull_request_repo,
82 pullrequestid=pull_request_id)
83
84 response = api_call(self.app, params)
85
86 pull_request = PullRequest.get(pull_request_id)
87
54 88 expected = {
55 89 'executed': True,
56 90 'failure_reason': 0,
@@ -59,8 +93,7 b' class TestMergePullRequest(object):'
59 93 'merge_ref': pull_request.shadow_merge_ref._asdict()
60 94 }
61 95
62 response_json = response.json['result']
63 assert response_json == expected
96 assert_ok(id_, expected, response.body)
64 97
65 98 action = 'user_merged_pull_request:%d' % (pull_request_id, )
66 99 journal = UserLog.query()\
@@ -75,8 +108,7 b' class TestMergePullRequest(object):'
75 108 repoid=pull_request_repo, pullrequestid=pull_request_id)
76 109 response = api_call(self.app, params)
77 110
78 expected = 'pull request `%s` merge failed, pull request is closed' % (
79 pull_request_id)
111 expected = 'merge not possible for following reasons: This pull request is closed.'
80 112 assert_error(id_, expected, given=response.body)
81 113
82 114 @pytest.mark.backends("git", "hg")
General Comments 0
You need to be logged in to leave comments. Login now