##// END OF EJS Templates
tests: Remove pull request duplication and update expected values.
Martin Bornhold -
r1057:b92be77b default
parent child Browse files
Show More
@@ -1,109 +1,104 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2016 RhodeCode GmbH
3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 #
4 #
5 # This program is free software: you can redistribute it and/or modify
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU Affero General Public License, version 3
6 # it under the terms of the GNU Affero General Public License, version 3
7 # (only), as published by the Free Software Foundation.
7 # (only), as published by the Free Software Foundation.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU Affero General Public License
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 #
16 #
17 # This program is dual-licensed. If you wish to learn more about the
17 # This program is dual-licensed. If you wish to learn more about the
18 # RhodeCode Enterprise Edition, including its added features, Support services,
18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20
20
21 import pytest
21 import pytest
22
22
23 from rhodecode.model.db import UserLog
23 from rhodecode.model.db import UserLog
24 from rhodecode.model.meta import Session
24 from rhodecode.model.meta import Session
25 from rhodecode.model.pull_request import PullRequestModel
25 from rhodecode.model.pull_request import PullRequestModel
26 from rhodecode.tests import TEST_USER_ADMIN_LOGIN
26 from rhodecode.tests import TEST_USER_ADMIN_LOGIN
27 from rhodecode.api.tests.utils import (
27 from rhodecode.api.tests.utils import (
28 build_data, api_call, assert_error)
28 build_data, api_call, assert_error)
29
29
30
30
31 @pytest.mark.usefixtures("testuser_api", "app")
31 @pytest.mark.usefixtures("testuser_api", "app")
32 class TestMergePullRequest(object):
32 class TestMergePullRequest(object):
33 @pytest.mark.backends("git", "hg")
33 @pytest.mark.backends("git", "hg")
34 def test_api_merge_pull_request(self, pr_util, no_notifications):
34 def test_api_merge_pull_request(self, pr_util, no_notifications):
35 pull_request = pr_util.create_pull_request()
35 pull_request = pr_util.create_pull_request(mergeable=True)
36 pull_request_2 = PullRequestModel().create(
37 created_by=pull_request.author,
38 source_repo=pull_request.source_repo,
39 source_ref=pull_request.source_ref,
40 target_repo=pull_request.target_repo,
41 target_ref=pull_request.target_ref,
42 revisions=pull_request.revisions,
43 reviewers=(),
44 title=pull_request.title,
45 description=pull_request.description,
46 )
47 author = pull_request.user_id
36 author = pull_request.user_id
48 repo = pull_request_2.target_repo.repo_id
37 repo = pull_request.target_repo.repo_id
49 pull_request_2_id = pull_request_2.pull_request_id
38 pull_request_id = pull_request.pull_request_id
50 pull_request_2_repo = pull_request_2.target_repo.repo_name
39 pull_request_repo = pull_request.target_repo.repo_name
51 Session().commit()
52
40
53 id_, params = build_data(
41 id_, params = build_data(
54 self.apikey, 'merge_pull_request',
42 self.apikey, 'merge_pull_request',
55 repoid=pull_request_2_repo,
43 repoid=pull_request_repo,
56 pullrequestid=pull_request_2_id)
44 pullrequestid=pull_request_id)
45
57 response = api_call(self.app, params)
46 response = api_call(self.app, params)
58
47
48 # The above api call detaches the pull request DB object from the
49 # session because of an unconditional transaction rollback in our
50 # middleware. Therefore we need to add it back here if we want to use
51 # it.
52 Session().add(pull_request)
53
59 expected = {
54 expected = {
60 'executed': True,
55 'executed': True,
61 'failure_reason': 0,
56 'failure_reason': 0,
62 'possible': True
57 'possible': True,
58 'merge_commit_id': pull_request.shadow_merge_ref.commit_id,
59 'merge_ref': pull_request.shadow_merge_ref._asdict()
63 }
60 }
64
61
65 response_json = response.json['result']
62 response_json = response.json['result']
66 assert response_json['merge_commit_id']
67 response_json.pop('merge_commit_id')
68 assert response_json == expected
63 assert response_json == expected
69
64
70 action = 'user_merged_pull_request:%d' % (pull_request_2_id, )
65 action = 'user_merged_pull_request:%d' % (pull_request_id, )
71 journal = UserLog.query()\
66 journal = UserLog.query()\
72 .filter(UserLog.user_id == author)\
67 .filter(UserLog.user_id == author)\
73 .filter(UserLog.repository_id == repo)\
68 .filter(UserLog.repository_id == repo)\
74 .filter(UserLog.action == action)\
69 .filter(UserLog.action == action)\
75 .all()
70 .all()
76 assert len(journal) == 1
71 assert len(journal) == 1
77
72
78 id_, params = build_data(
73 id_, params = build_data(
79 self.apikey, 'merge_pull_request',
74 self.apikey, 'merge_pull_request',
80 repoid=pull_request_2_repo, pullrequestid=pull_request_2_id)
75 repoid=pull_request_repo, pullrequestid=pull_request_id)
81 response = api_call(self.app, params)
76 response = api_call(self.app, params)
82
77
83 expected = 'pull request `%s` merge failed, pull request is closed' % (
78 expected = 'pull request `%s` merge failed, pull request is closed' % (
84 pull_request_2_id)
79 pull_request_id)
85 assert_error(id_, expected, given=response.body)
80 assert_error(id_, expected, given=response.body)
86
81
87 @pytest.mark.backends("git", "hg")
82 @pytest.mark.backends("git", "hg")
88 def test_api_merge_pull_request_repo_error(self):
83 def test_api_merge_pull_request_repo_error(self):
89 id_, params = build_data(
84 id_, params = build_data(
90 self.apikey, 'merge_pull_request',
85 self.apikey, 'merge_pull_request',
91 repoid=666, pullrequestid=1)
86 repoid=666, pullrequestid=1)
92 response = api_call(self.app, params)
87 response = api_call(self.app, params)
93
88
94 expected = 'repository `666` does not exist'
89 expected = 'repository `666` does not exist'
95 assert_error(id_, expected, given=response.body)
90 assert_error(id_, expected, given=response.body)
96
91
97 @pytest.mark.backends("git", "hg")
92 @pytest.mark.backends("git", "hg")
98 def test_api_merge_pull_request_non_admin_with_userid_error(self,
93 def test_api_merge_pull_request_non_admin_with_userid_error(self,
99 pr_util):
94 pr_util):
100 pull_request = pr_util.create_pull_request(mergeable=True)
95 pull_request = pr_util.create_pull_request(mergeable=True)
101 id_, params = build_data(
96 id_, params = build_data(
102 self.apikey_regular, 'merge_pull_request',
97 self.apikey_regular, 'merge_pull_request',
103 repoid=pull_request.target_repo.repo_name,
98 repoid=pull_request.target_repo.repo_name,
104 pullrequestid=pull_request.pull_request_id,
99 pullrequestid=pull_request.pull_request_id,
105 userid=TEST_USER_ADMIN_LOGIN)
100 userid=TEST_USER_ADMIN_LOGIN)
106 response = api_call(self.app, params)
101 response = api_call(self.app, params)
107
102
108 expected = 'userid is not the same as your user'
103 expected = 'userid is not the same as your user'
109 assert_error(id_, expected, given=response.body)
104 assert_error(id_, expected, given=response.body)
General Comments 0
You need to be logged in to leave comments. Login now