##// END OF EJS Templates
tests: fixed pull_reques API tests
marcink -
r2862:260b7e82 stable
parent child Browse files
Show More
@@ -1,297 +1,335 b''
1 # -*- coding: utf-8 -*-
1 # -*- coding: utf-8 -*-
2
2
3 # Copyright (C) 2010-2018 RhodeCode GmbH
3 # Copyright (C) 2010-2018 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 User
23 from rhodecode.model.db import User
24 from rhodecode.model.pull_request import PullRequestModel
24 from rhodecode.model.pull_request import PullRequestModel
25 from rhodecode.model.repo import RepoModel
25 from rhodecode.model.repo import RepoModel
26 from rhodecode.model.user import UserModel
26 from rhodecode.model.user import UserModel
27 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
27 from rhodecode.tests import TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN
28 from rhodecode.api.tests.utils import build_data, api_call, assert_error
28 from rhodecode.api.tests.utils import 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 TestCreatePullRequestApi(object):
32 class TestCreatePullRequestApi(object):
33 finalizers = []
33 finalizers = []
34
34
35 def teardown_method(self, method):
35 def teardown_method(self, method):
36 if self.finalizers:
36 if self.finalizers:
37 for finalizer in self.finalizers:
37 for finalizer in self.finalizers:
38 finalizer()
38 finalizer()
39 self.finalizers = []
39 self.finalizers = []
40
40
41 def test_create_with_wrong_data(self):
41 def test_create_with_wrong_data(self):
42 required_data = {
42 required_data = {
43 'source_repo': 'tests/source_repo',
43 'source_repo': 'tests/source_repo',
44 'target_repo': 'tests/target_repo',
44 'target_repo': 'tests/target_repo',
45 'source_ref': 'branch:default:initial',
45 'source_ref': 'branch:default:initial',
46 'target_ref': 'branch:default:new-feature',
46 'target_ref': 'branch:default:new-feature',
47 'title': 'Test PR 1'
48 }
47 }
49 for key in required_data:
48 for key in required_data:
50 data = required_data.copy()
49 data = required_data.copy()
51 data.pop(key)
50 data.pop(key)
52 id_, params = build_data(
51 id_, params = build_data(
53 self.apikey, 'create_pull_request', **data)
52 self.apikey, 'create_pull_request', **data)
54 response = api_call(self.app, params)
53 response = api_call(self.app, params)
55
54
56 expected = 'Missing non optional `{}` arg in JSON DATA'.format(key)
55 expected = 'Missing non optional `{}` arg in JSON DATA'.format(key)
57 assert_error(id_, expected, given=response.body)
56 assert_error(id_, expected, given=response.body)
58
57
59 @pytest.mark.backends("git", "hg")
58 @pytest.mark.backends("git", "hg")
60 def test_create_with_correct_data(self, backend):
59 def test_create_with_correct_data(self, backend):
61 data = self._prepare_data(backend)
60 data = self._prepare_data(backend)
62 RepoModel().revoke_user_permission(
61 RepoModel().revoke_user_permission(
63 self.source.repo_name, User.DEFAULT_USER)
62 self.source.repo_name, User.DEFAULT_USER)
64 id_, params = build_data(
63 id_, params = build_data(
65 self.apikey_regular, 'create_pull_request', **data)
64 self.apikey_regular, 'create_pull_request', **data)
66 response = api_call(self.app, params)
65 response = api_call(self.app, params)
67 expected_message = "Created new pull request `{title}`".format(
66 expected_message = "Created new pull request `{title}`".format(
68 title=data['title'])
67 title=data['title'])
69 result = response.json
68 result = response.json
70 assert result['result']['msg'] == expected_message
69 assert result['result']['msg'] == expected_message
71 pull_request_id = result['result']['pull_request_id']
70 pull_request_id = result['result']['pull_request_id']
72 pull_request = PullRequestModel().get(pull_request_id)
71 pull_request = PullRequestModel().get(pull_request_id)
73 assert pull_request.title == data['title']
72 assert pull_request.title == data['title']
74 assert pull_request.description == data['description']
73 assert pull_request.description == data['description']
75 assert pull_request.source_ref == data['source_ref']
74 assert pull_request.source_ref == data['source_ref']
76 assert pull_request.target_ref == data['target_ref']
75 assert pull_request.target_ref == data['target_ref']
77 assert pull_request.source_repo.repo_name == data['source_repo']
76 assert pull_request.source_repo.repo_name == data['source_repo']
78 assert pull_request.target_repo.repo_name == data['target_repo']
77 assert pull_request.target_repo.repo_name == data['target_repo']
79 assert pull_request.revisions == [self.commit_ids['change']]
78 assert pull_request.revisions == [self.commit_ids['change']]
80 assert len(pull_request.reviewers) == 1
79 assert len(pull_request.reviewers) == 1
81
80
82 @pytest.mark.backends("git", "hg")
81 @pytest.mark.backends("git", "hg")
83 def test_create_with_empty_description(self, backend):
82 def test_create_with_empty_description(self, backend):
84 data = self._prepare_data(backend)
83 data = self._prepare_data(backend)
85 data.pop('description')
84 data.pop('description')
86 id_, params = build_data(
85 id_, params = build_data(
87 self.apikey_regular, 'create_pull_request', **data)
86 self.apikey_regular, 'create_pull_request', **data)
88 response = api_call(self.app, params)
87 response = api_call(self.app, params)
89 expected_message = "Created new pull request `{title}`".format(
88 expected_message = "Created new pull request `{title}`".format(
90 title=data['title'])
89 title=data['title'])
91 result = response.json
90 result = response.json
92 assert result['result']['msg'] == expected_message
91 assert result['result']['msg'] == expected_message
93 pull_request_id = result['result']['pull_request_id']
92 pull_request_id = result['result']['pull_request_id']
94 pull_request = PullRequestModel().get(pull_request_id)
93 pull_request = PullRequestModel().get(pull_request_id)
95 assert pull_request.description == ''
94 assert pull_request.description == ''
96
95
97 @pytest.mark.backends("git", "hg")
96 @pytest.mark.backends("git", "hg")
97 def test_create_with_empty_title(self, backend):
98 data = self._prepare_data(backend)
99 data.pop('title')
100 id_, params = build_data(
101 self.apikey_regular, 'create_pull_request', **data)
102 response = api_call(self.app, params)
103 result = response.json
104 pull_request_id = result['result']['pull_request_id']
105 pull_request = PullRequestModel().get(pull_request_id)
106 data['ref'] = backend.default_branch_name
107 title = '{source_repo}#{ref} to {target_repo}'.format(**data)
108 assert pull_request.title == title
109
110 @pytest.mark.backends("git", "hg")
98 def test_create_with_reviewers_specified_by_names(
111 def test_create_with_reviewers_specified_by_names(
99 self, backend, no_notifications):
112 self, backend, no_notifications):
100 data = self._prepare_data(backend)
113 data = self._prepare_data(backend)
101 reviewers = [
114 reviewers = [
102 {'username': TEST_USER_REGULAR_LOGIN,
115 {'username': TEST_USER_REGULAR_LOGIN,
103 'reasons': ['added manually']},
116 'reasons': ['{} added manually'.format(TEST_USER_REGULAR_LOGIN)]},
104 {'username': TEST_USER_ADMIN_LOGIN,
117 {'username': TEST_USER_ADMIN_LOGIN,
105 'reasons': ['added manually']},
118 'reasons': ['{} added manually'.format(TEST_USER_ADMIN_LOGIN)],
119 'mandatory': True},
106 ]
120 ]
107 data['reviewers'] = reviewers
121 data['reviewers'] = reviewers
108 id_, params = build_data(
122 id_, params = build_data(
109 self.apikey_regular, 'create_pull_request', **data)
123 self.apikey_regular, 'create_pull_request', **data)
110 response = api_call(self.app, params)
124 response = api_call(self.app, params)
111
125
112 expected_message = "Created new pull request `{title}`".format(
126 expected_message = "Created new pull request `{title}`".format(
113 title=data['title'])
127 title=data['title'])
114 result = response.json
128 result = response.json
115 assert result['result']['msg'] == expected_message
129 assert result['result']['msg'] == expected_message
116 pull_request_id = result['result']['pull_request_id']
130 pull_request_id = result['result']['pull_request_id']
117 pull_request = PullRequestModel().get(pull_request_id)
131 pull_request = PullRequestModel().get(pull_request_id)
118 actual_reviewers = [
132
119 {'username': r.user.username,
133 actual_reviewers = []
120 'reasons': ['added manually'],
134 for rev in pull_request.reviewers:
121 } for r in pull_request.reviewers
135 entry = {
122 ]
136 'username': rev.user.username,
123 assert sorted(actual_reviewers) == sorted(reviewers)
137 'reasons': rev.reasons,
138 }
139 if rev.mandatory:
140 entry['mandatory'] = rev.mandatory
141 actual_reviewers.append(entry)
142
143 # default reviewer will be added who is an owner of the repo
144 reviewers.append(
145 {'username': pull_request.author.username,
146 'reasons': [u'Default reviewer', u'Repository owner']},
147 )
148 assert sorted(actual_reviewers, key=lambda e: e['username']) \
149 == sorted(reviewers, key=lambda e: e['username'])
124
150
125 @pytest.mark.backends("git", "hg")
151 @pytest.mark.backends("git", "hg")
126 def test_create_with_reviewers_specified_by_ids(
152 def test_create_with_reviewers_specified_by_ids(
127 self, backend, no_notifications):
153 self, backend, no_notifications):
128 data = self._prepare_data(backend)
154 data = self._prepare_data(backend)
129 reviewers = [
155 reviewers = [
130 {'username': UserModel().get_by_username(
156 {'username': UserModel().get_by_username(
131 TEST_USER_REGULAR_LOGIN).user_id,
157 TEST_USER_REGULAR_LOGIN).user_id,
132 'reasons': ['added manually']},
158 'reasons': ['added manually']},
133 {'username': UserModel().get_by_username(
159 {'username': UserModel().get_by_username(
134 TEST_USER_ADMIN_LOGIN).user_id,
160 TEST_USER_ADMIN_LOGIN).user_id,
135 'reasons': ['added manually']},
161 'reasons': ['added manually']},
136 ]
162 ]
137
163
138 data['reviewers'] = reviewers
164 data['reviewers'] = reviewers
139 id_, params = build_data(
165 id_, params = build_data(
140 self.apikey_regular, 'create_pull_request', **data)
166 self.apikey_regular, 'create_pull_request', **data)
141 response = api_call(self.app, params)
167 response = api_call(self.app, params)
142
168
143 expected_message = "Created new pull request `{title}`".format(
169 expected_message = "Created new pull request `{title}`".format(
144 title=data['title'])
170 title=data['title'])
145 result = response.json
171 result = response.json
146 assert result['result']['msg'] == expected_message
172 assert result['result']['msg'] == expected_message
147 pull_request_id = result['result']['pull_request_id']
173 pull_request_id = result['result']['pull_request_id']
148 pull_request = PullRequestModel().get(pull_request_id)
174 pull_request = PullRequestModel().get(pull_request_id)
149 actual_reviewers = [
175
150 {'username': r.user.user_id,
176 actual_reviewers = []
151 'reasons': ['added manually'],
177 for rev in pull_request.reviewers:
152 } for r in pull_request.reviewers
178 entry = {
153 ]
179 'username': rev.user.user_id,
154 assert sorted(actual_reviewers) == sorted(reviewers)
180 'reasons': rev.reasons,
181 }
182 if rev.mandatory:
183 entry['mandatory'] = rev.mandatory
184 actual_reviewers.append(entry)
185 # default reviewer will be added who is an owner of the repo
186 reviewers.append(
187 {'username': pull_request.author.user_id,
188 'reasons': [u'Default reviewer', u'Repository owner']},
189 )
190 assert sorted(actual_reviewers, key=lambda e: e['username']) \
191 == sorted(reviewers, key=lambda e: e['username'])
155
192
156 @pytest.mark.backends("git", "hg")
193 @pytest.mark.backends("git", "hg")
157 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
194 def test_create_fails_when_the_reviewer_is_not_found(self, backend):
158 data = self._prepare_data(backend)
195 data = self._prepare_data(backend)
159 data['reviewers'] = [{'username': 'somebody'}]
196 data['reviewers'] = [{'username': 'somebody'}]
160 id_, params = build_data(
197 id_, params = build_data(
161 self.apikey_regular, 'create_pull_request', **data)
198 self.apikey_regular, 'create_pull_request', **data)
162 response = api_call(self.app, params)
199 response = api_call(self.app, params)
163 expected_message = 'user `somebody` does not exist'
200 expected_message = 'user `somebody` does not exist'
164 assert_error(id_, expected_message, given=response.body)
201 assert_error(id_, expected_message, given=response.body)
165
202
166 @pytest.mark.backends("git", "hg")
203 @pytest.mark.backends("git", "hg")
167 def test_cannot_create_with_reviewers_in_wrong_format(self, backend):
204 def test_cannot_create_with_reviewers_in_wrong_format(self, backend):
168 data = self._prepare_data(backend)
205 data = self._prepare_data(backend)
169 reviewers = ','.join([TEST_USER_REGULAR_LOGIN, TEST_USER_ADMIN_LOGIN])
206 reviewers = ','.join([TEST_USER_REGULAR_LOGIN, TEST_USER_ADMIN_LOGIN])
170 data['reviewers'] = reviewers
207 data['reviewers'] = reviewers
171 id_, params = build_data(
208 id_, params = build_data(
172 self.apikey_regular, 'create_pull_request', **data)
209 self.apikey_regular, 'create_pull_request', **data)
173 response = api_call(self.app, params)
210 response = api_call(self.app, params)
174 expected_message = {u'': '"test_regular,test_admin" is not iterable'}
211 expected_message = {u'': '"test_regular,test_admin" is not iterable'}
175 assert_error(id_, expected_message, given=response.body)
212 assert_error(id_, expected_message, given=response.body)
176
213
177 @pytest.mark.backends("git", "hg")
214 @pytest.mark.backends("git", "hg")
178 def test_create_with_no_commit_hashes(self, backend):
215 def test_create_with_no_commit_hashes(self, backend):
179 data = self._prepare_data(backend)
216 data = self._prepare_data(backend)
180 expected_source_ref = data['source_ref']
217 expected_source_ref = data['source_ref']
181 expected_target_ref = data['target_ref']
218 expected_target_ref = data['target_ref']
182 data['source_ref'] = 'branch:{}'.format(backend.default_branch_name)
219 data['source_ref'] = 'branch:{}'.format(backend.default_branch_name)
183 data['target_ref'] = 'branch:{}'.format(backend.default_branch_name)
220 data['target_ref'] = 'branch:{}'.format(backend.default_branch_name)
184 id_, params = build_data(
221 id_, params = build_data(
185 self.apikey_regular, 'create_pull_request', **data)
222 self.apikey_regular, 'create_pull_request', **data)
186 response = api_call(self.app, params)
223 response = api_call(self.app, params)
187 expected_message = "Created new pull request `{title}`".format(
224 expected_message = "Created new pull request `{title}`".format(
188 title=data['title'])
225 title=data['title'])
189 result = response.json
226 result = response.json
190 assert result['result']['msg'] == expected_message
227 assert result['result']['msg'] == expected_message
191 pull_request_id = result['result']['pull_request_id']
228 pull_request_id = result['result']['pull_request_id']
192 pull_request = PullRequestModel().get(pull_request_id)
229 pull_request = PullRequestModel().get(pull_request_id)
193 assert pull_request.source_ref == expected_source_ref
230 assert pull_request.source_ref == expected_source_ref
194 assert pull_request.target_ref == expected_target_ref
231 assert pull_request.target_ref == expected_target_ref
195
232
196 @pytest.mark.backends("git", "hg")
233 @pytest.mark.backends("git", "hg")
197 @pytest.mark.parametrize("data_key", ["source_repo", "target_repo"])
234 @pytest.mark.parametrize("data_key", ["source_repo", "target_repo"])
198 def test_create_fails_with_wrong_repo(self, backend, data_key):
235 def test_create_fails_with_wrong_repo(self, backend, data_key):
199 repo_name = 'fake-repo'
236 repo_name = 'fake-repo'
200 data = self._prepare_data(backend)
237 data = self._prepare_data(backend)
201 data[data_key] = repo_name
238 data[data_key] = repo_name
202 id_, params = build_data(
239 id_, params = build_data(
203 self.apikey_regular, 'create_pull_request', **data)
240 self.apikey_regular, 'create_pull_request', **data)
204 response = api_call(self.app, params)
241 response = api_call(self.app, params)
205 expected_message = 'repository `{}` does not exist'.format(repo_name)
242 expected_message = 'repository `{}` does not exist'.format(repo_name)
206 assert_error(id_, expected_message, given=response.body)
243 assert_error(id_, expected_message, given=response.body)
207
244
208 @pytest.mark.backends("git", "hg")
245 @pytest.mark.backends("git", "hg")
209 @pytest.mark.parametrize("data_key", ["source_ref", "target_ref"])
246 @pytest.mark.parametrize("data_key", ["source_ref", "target_ref"])
210 def test_create_fails_with_non_existing_branch(self, backend, data_key):
247 def test_create_fails_with_non_existing_branch(self, backend, data_key):
211 branch_name = 'test-branch'
248 branch_name = 'test-branch'
212 data = self._prepare_data(backend)
249 data = self._prepare_data(backend)
213 data[data_key] = "branch:{}".format(branch_name)
250 data[data_key] = "branch:{}".format(branch_name)
214 id_, params = build_data(
251 id_, params = build_data(
215 self.apikey_regular, 'create_pull_request', **data)
252 self.apikey_regular, 'create_pull_request', **data)
216 response = api_call(self.app, params)
253 response = api_call(self.app, params)
217 expected_message = 'The specified branch `{}` does not exist'.format(
254 expected_message = 'The specified branch `{}` does not exist'.format(
218 branch_name)
255 branch_name)
219 assert_error(id_, expected_message, given=response.body)
256 assert_error(id_, expected_message, given=response.body)
220
257
221 @pytest.mark.backends("git", "hg")
258 @pytest.mark.backends("git", "hg")
222 @pytest.mark.parametrize("data_key", ["source_ref", "target_ref"])
259 @pytest.mark.parametrize("data_key", ["source_ref", "target_ref"])
223 def test_create_fails_with_ref_in_a_wrong_format(self, backend, data_key):
260 def test_create_fails_with_ref_in_a_wrong_format(self, backend, data_key):
224 data = self._prepare_data(backend)
261 data = self._prepare_data(backend)
225 ref = 'stange-ref'
262 ref = 'stange-ref'
226 data[data_key] = ref
263 data[data_key] = ref
227 id_, params = build_data(
264 id_, params = build_data(
228 self.apikey_regular, 'create_pull_request', **data)
265 self.apikey_regular, 'create_pull_request', **data)
229 response = api_call(self.app, params)
266 response = api_call(self.app, params)
230 expected_message = (
267 expected_message = (
231 'Ref `{ref}` given in a wrong format. Please check the API'
268 'Ref `{ref}` given in a wrong format. Please check the API'
232 ' documentation for more details'.format(ref=ref))
269 ' documentation for more details'.format(ref=ref))
233 assert_error(id_, expected_message, given=response.body)
270 assert_error(id_, expected_message, given=response.body)
234
271
235 @pytest.mark.backends("git", "hg")
272 @pytest.mark.backends("git", "hg")
236 @pytest.mark.parametrize("data_key", ["source_ref", "target_ref"])
273 @pytest.mark.parametrize("data_key", ["source_ref", "target_ref"])
237 def test_create_fails_with_non_existing_ref(self, backend, data_key):
274 def test_create_fails_with_non_existing_ref(self, backend, data_key):
238 commit_id = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
275 commit_id = 'aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa10'
239 ref = self._get_full_ref(backend, commit_id)
276 ref = self._get_full_ref(backend, commit_id)
240 data = self._prepare_data(backend)
277 data = self._prepare_data(backend)
241 data[data_key] = ref
278 data[data_key] = ref
242 id_, params = build_data(
279 id_, params = build_data(
243 self.apikey_regular, 'create_pull_request', **data)
280 self.apikey_regular, 'create_pull_request', **data)
244 response = api_call(self.app, params)
281 response = api_call(self.app, params)
245 expected_message = 'Ref `{}` does not exist'.format(ref)
282 expected_message = 'Ref `{}` does not exist'.format(ref)
246 assert_error(id_, expected_message, given=response.body)
283 assert_error(id_, expected_message, given=response.body)
247
284
248 @pytest.mark.backends("git", "hg")
285 @pytest.mark.backends("git", "hg")
249 def test_create_fails_when_no_revisions(self, backend):
286 def test_create_fails_when_no_revisions(self, backend):
250 data = self._prepare_data(backend, source_head='initial')
287 data = self._prepare_data(backend, source_head='initial')
251 id_, params = build_data(
288 id_, params = build_data(
252 self.apikey_regular, 'create_pull_request', **data)
289 self.apikey_regular, 'create_pull_request', **data)
253 response = api_call(self.app, params)
290 response = api_call(self.app, params)
254 expected_message = 'no commits found'
291 expected_message = 'no commits found'
255 assert_error(id_, expected_message, given=response.body)
292 assert_error(id_, expected_message, given=response.body)
256
293
257 @pytest.mark.backends("git", "hg")
294 @pytest.mark.backends("git", "hg")
258 def test_create_fails_when_no_permissions(self, backend):
295 def test_create_fails_when_no_permissions(self, backend):
259 data = self._prepare_data(backend)
296 data = self._prepare_data(backend)
260 RepoModel().revoke_user_permission(
297 RepoModel().revoke_user_permission(
261 self.source.repo_name, User.DEFAULT_USER)
298 self.source.repo_name, self.test_user)
262 RepoModel().revoke_user_permission(
299 RepoModel().revoke_user_permission(
263 self.source.repo_name, self.test_user)
300 self.source.repo_name, User.DEFAULT_USER)
301
264 id_, params = build_data(
302 id_, params = build_data(
265 self.apikey_regular, 'create_pull_request', **data)
303 self.apikey_regular, 'create_pull_request', **data)
266 response = api_call(self.app, params)
304 response = api_call(self.app, params)
267 expected_message = 'repository `{}` does not exist'.format(
305 expected_message = 'repository `{}` does not exist'.format(
268 self.source.repo_name)
306 self.source.repo_name)
269 assert_error(id_, expected_message, given=response.body)
307 assert_error(id_, expected_message, given=response.body)
270
308
271 def _prepare_data(
309 def _prepare_data(
272 self, backend, source_head='change', target_head='initial'):
310 self, backend, source_head='change', target_head='initial'):
273 commits = [
311 commits = [
274 {'message': 'initial'},
312 {'message': 'initial'},
275 {'message': 'change'},
313 {'message': 'change'},
276 {'message': 'new-feature', 'parents': ['initial']},
314 {'message': 'new-feature', 'parents': ['initial']},
277 ]
315 ]
278 self.commit_ids = backend.create_master_repo(commits)
316 self.commit_ids = backend.create_master_repo(commits)
279 self.source = backend.create_repo(heads=[source_head])
317 self.source = backend.create_repo(heads=[source_head])
280 self.target = backend.create_repo(heads=[target_head])
318 self.target = backend.create_repo(heads=[target_head])
281 data = {
319 data = {
282 'source_repo': self.source.repo_name,
320 'source_repo': self.source.repo_name,
283 'target_repo': self.target.repo_name,
321 'target_repo': self.target.repo_name,
284 'source_ref': self._get_full_ref(
322 'source_ref': self._get_full_ref(
285 backend, self.commit_ids[source_head]),
323 backend, self.commit_ids[source_head]),
286 'target_ref': self._get_full_ref(
324 'target_ref': self._get_full_ref(
287 backend, self.commit_ids[target_head]),
325 backend, self.commit_ids[target_head]),
288 'title': 'Test PR 1',
326 'title': 'Test PR 1',
289 'description': 'Test'
327 'description': 'Test'
290 }
328 }
291 RepoModel().grant_user_permission(
329 RepoModel().grant_user_permission(
292 self.source.repo_name, self.TEST_USER_LOGIN, 'repository.read')
330 self.source.repo_name, self.TEST_USER_LOGIN, 'repository.read')
293 return data
331 return data
294
332
295 def _get_full_ref(self, backend, commit_id):
333 def _get_full_ref(self, backend, commit_id):
296 return 'branch:{branch}:{commit_id}'.format(
334 return 'branch:{branch}:{commit_id}'.format(
297 branch=backend.default_branch_name, commit_id=commit_id)
335 branch=backend.default_branch_name, commit_id=commit_id)
General Comments 0
You need to be logged in to leave comments. Login now