##// END OF EJS Templates
pull-requests: migrated code from pylons to pyramid
marcink -
r1974:cb4db595 default
parent child
Show More
@@ -21,10 +21,10
21
21
22 import pytest
22 import pytest
23 import urlobject
23 import urlobject
24 from pylons import url
25
24
26 from rhodecode.api.tests.utils import (
25 from rhodecode.api.tests.utils import (
27 build_data, api_call, assert_error, assert_ok)
26 build_data, api_call, assert_error, assert_ok)
27 from rhodecode.lib import helpers as h
28 from rhodecode.lib.utils2 import safe_unicode
28 from rhodecode.lib.utils2 import safe_unicode
29
29
30 pytestmark = pytest.mark.backends("git", "hg")
30 pytestmark = pytest.mark.backends("git", "hg")
@@ -46,10 +46,10 class TestGetPullRequest(object):
46 assert response.status == '200 OK'
46 assert response.status == '200 OK'
47
47
48 url_obj = urlobject.URLObject(
48 url_obj = urlobject.URLObject(
49 url(
49 h.route_url(
50 'pullrequest_show',
50 'pullrequest_show',
51 repo_name=pull_request.target_repo.repo_name,
51 repo_name=pull_request.target_repo.repo_name,
52 pull_request_id=pull_request.pull_request_id, qualified=True))
52 pull_request_id=pull_request.pull_request_id))
53
53
54 pr_url = safe_unicode(
54 pr_url = safe_unicode(
55 url_obj.with_netloc(http_host_only_stub))
55 url_obj.with_netloc(http_host_only_stub))
@@ -217,7 +217,7 def includeme(config):
217 # Pull Requests
217 # Pull Requests
218 config.add_route(
218 config.add_route(
219 name='pullrequest_show',
219 name='pullrequest_show',
220 pattern='/{repo_name:.*?[^/]}/pull-request/{pull_request_id}',
220 pattern='/{repo_name:.*?[^/]}/pull-request/{pull_request_id:\d+}',
221 repo_route=True)
221 repo_route=True)
222
222
223 config.add_route(
223 config.add_route(
@@ -230,6 +230,51 def includeme(config):
230 pattern='/{repo_name:.*?[^/]}/pull-request-data',
230 pattern='/{repo_name:.*?[^/]}/pull-request-data',
231 repo_route=True, repo_accepted_types=['hg', 'git'])
231 repo_route=True, repo_accepted_types=['hg', 'git'])
232
232
233 config.add_route(
234 name='pullrequest_repo_refs',
235 pattern='/{repo_name:.*?[^/]}/pull-request/refs/{target_repo_name:.*?[^/]}',
236 repo_route=True)
237
238 config.add_route(
239 name='pullrequest_repo_destinations',
240 pattern='/{repo_name:.*?[^/]}/pull-request/repo-destinations',
241 repo_route=True)
242
243 config.add_route(
244 name='pullrequest_new',
245 pattern='/{repo_name:.*?[^/]}/pull-request/new',
246 repo_route=True, repo_accepted_types=['hg', 'git'])
247
248 config.add_route(
249 name='pullrequest_create',
250 pattern='/{repo_name:.*?[^/]}/pull-request/create',
251 repo_route=True, repo_accepted_types=['hg', 'git'])
252
253 config.add_route(
254 name='pullrequest_update',
255 pattern='/{repo_name:.*?[^/]}/pull-request/{pull_request_id:\d+}/update',
256 repo_route=True)
257
258 config.add_route(
259 name='pullrequest_merge',
260 pattern='/{repo_name:.*?[^/]}/pull-request/{pull_request_id:\d+}/merge',
261 repo_route=True)
262
263 config.add_route(
264 name='pullrequest_delete',
265 pattern='/{repo_name:.*?[^/]}/pull-request/{pull_request_id:\d+}/delete',
266 repo_route=True)
267
268 config.add_route(
269 name='pullrequest_comment_create',
270 pattern='/{repo_name:.*?[^/]}/pull-request/{pull_request_id:\d+}/comment',
271 repo_route=True)
272
273 config.add_route(
274 name='pullrequest_comment_delete',
275 pattern='/{repo_name:.*?[^/]}/pull-request/{pull_request_id:\d+}/comment/{comment_id}/delete',
276 repo_route=True, repo_accepted_types=['hg', 'git'])
277
233 # Settings
278 # Settings
234 config.add_route(
279 config.add_route(
235 name='edit_repo',
280 name='edit_repo',
@@ -17,12 +17,11
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
21 import mock
20 import mock
22 import pytest
21 import pytest
23 from webob.exc import HTTPNotFound
24
22
25 import rhodecode
23 import rhodecode
24 from rhodecode.lib.vcs.backends.base import MergeResponse, MergeFailureReason
26 from rhodecode.lib.vcs.nodes import FileNode
25 from rhodecode.lib.vcs.nodes import FileNode
27 from rhodecode.lib import helpers as h
26 from rhodecode.lib import helpers as h
28 from rhodecode.model.changeset_status import ChangesetStatusModel
27 from rhodecode.model.changeset_status import ChangesetStatusModel
@@ -32,7 +31,7 from rhodecode.model.meta import Session
32 from rhodecode.model.pull_request import PullRequestModel
31 from rhodecode.model.pull_request import PullRequestModel
33 from rhodecode.model.user import UserModel
32 from rhodecode.model.user import UserModel
34 from rhodecode.tests import (
33 from rhodecode.tests import (
35 assert_session_flash, url, TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN)
34 assert_session_flash, TEST_USER_ADMIN_LOGIN, TEST_USER_REGULAR_LOGIN)
36 from rhodecode.tests.utils import AssertResponse
35 from rhodecode.tests.utils import AssertResponse
37
36
38
37
@@ -40,8 +39,20 def route_path(name, params=None, **kwar
40 import urllib
39 import urllib
41
40
42 base_url = {
41 base_url = {
43 'repo_changelog':'/{repo_name}/changelog',
42 'repo_changelog': '/{repo_name}/changelog',
44 'repo_changelog_file':'/{repo_name}/changelog/{commit_id}/{f_path}',
43 'repo_changelog_file': '/{repo_name}/changelog/{commit_id}/{f_path}',
44 'pullrequest_show': '/{repo_name}/pull-request/{pull_request_id}',
45 'pullrequest_show_all': '/{repo_name}/pull-request',
46 'pullrequest_show_all_data': '/{repo_name}/pull-request-data',
47 'pullrequest_repo_refs': '/{repo_name}/pull-request/refs/{target_repo_name:.*?[^/]}',
48 'pullrequest_repo_destinations': '/{repo_name}/pull-request/repo-destinations',
49 'pullrequest_new': '/{repo_name}/pull-request/new',
50 'pullrequest_create': '/{repo_name}/pull-request/create',
51 'pullrequest_update': '/{repo_name}/pull-request/{pull_request_id}/update',
52 'pullrequest_merge': '/{repo_name}/pull-request/{pull_request_id}/merge',
53 'pullrequest_delete': '/{repo_name}/pull-request/{pull_request_id}/delete',
54 'pullrequest_comment_create': '/{repo_name}/pull-request/{pull_request_id}/comment',
55 'pullrequest_comment_delete': '/{repo_name}/pull-request/{pull_request_id}/comment/{comment_id}/delete',
45 }[name].format(**kwargs)
56 }[name].format(**kwargs)
46
57
47 if params:
58 if params:
@@ -51,26 +62,26 def route_path(name, params=None, **kwar
51
62
52 @pytest.mark.usefixtures('app', 'autologin_user')
63 @pytest.mark.usefixtures('app', 'autologin_user')
53 @pytest.mark.backends("git", "hg")
64 @pytest.mark.backends("git", "hg")
54 class TestPullrequestsController(object):
65 class TestPullrequestsView(object):
55
66
56 def test_index(self, backend):
67 def test_index(self, backend):
57 self.app.get(url(
68 self.app.get(route_path(
58 controller='pullrequests', action='index',
69 'pullrequest_new',
59 repo_name=backend.repo_name))
70 repo_name=backend.repo_name))
60
71
61 def test_option_menu_create_pull_request_exists(self, backend):
72 def test_option_menu_create_pull_request_exists(self, backend):
62 repo_name = backend.repo_name
73 repo_name = backend.repo_name
63 response = self.app.get(h.route_path('repo_summary', repo_name=repo_name))
74 response = self.app.get(h.route_path('repo_summary', repo_name=repo_name))
64
75
65 create_pr_link = '<a href="%s">Create Pull Request</a>' % url(
76 create_pr_link = '<a href="%s">Create Pull Request</a>' % route_path(
66 'pullrequest', repo_name=repo_name)
77 'pullrequest_new', repo_name=repo_name)
67 response.mustcontain(create_pr_link)
78 response.mustcontain(create_pr_link)
68
79
69 def test_create_pr_form_with_raw_commit_id(self, backend):
80 def test_create_pr_form_with_raw_commit_id(self, backend):
70 repo = backend.repo
81 repo = backend.repo
71
82
72 self.app.get(
83 self.app.get(
73 url(controller='pullrequests', action='index',
84 route_path('pullrequest_new',
74 repo_name=repo.repo_name,
85 repo_name=repo.repo_name,
75 commit=repo.get_commit().raw_id),
86 commit=repo.get_commit().raw_id),
76 status=200)
87 status=200)
@@ -80,10 +91,10 class TestPullrequestsController(object)
80 pull_request = pr_util.create_pull_request(
91 pull_request = pr_util.create_pull_request(
81 mergeable=pr_merge_enabled, enable_notifications=False)
92 mergeable=pr_merge_enabled, enable_notifications=False)
82
93
83 response = self.app.get(url(
94 response = self.app.get(route_path(
84 controller='pullrequests', action='show',
95 'pullrequest_show',
85 repo_name=pull_request.target_repo.scm_instance().name,
96 repo_name=pull_request.target_repo.scm_instance().name,
86 pull_request_id=str(pull_request.pull_request_id)))
97 pull_request_id=pull_request.pull_request_id))
87
98
88 for commit_id in pull_request.revisions:
99 for commit_id in pull_request.revisions:
89 response.mustcontain(commit_id)
100 response.mustcontain(commit_id)
@@ -111,10 +122,10 class TestPullrequestsController(object)
111 pull_request = pr_util.create_pull_request(
122 pull_request = pr_util.create_pull_request(
112 author=TEST_USER_REGULAR_LOGIN)
123 author=TEST_USER_REGULAR_LOGIN)
113
124
114 response = self.app.get(url(
125 response = self.app.get(route_path(
115 controller='pullrequests', action='show',
126 'pullrequest_show',
116 repo_name=pull_request.target_repo.scm_instance().name,
127 repo_name=pull_request.target_repo.scm_instance().name,
117 pull_request_id=str(pull_request.pull_request_id)))
128 pull_request_id=pull_request.pull_request_id))
118
129
119 response.mustcontain('Server-side pull request merging is disabled.')
130 response.mustcontain('Server-side pull request merging is disabled.')
120
131
@@ -126,10 +137,10 class TestPullrequestsController(object)
126 pull_request.target_repo,
137 pull_request.target_repo,
127 UserModel().get_by_username(TEST_USER_REGULAR_LOGIN),
138 UserModel().get_by_username(TEST_USER_REGULAR_LOGIN),
128 'repository.write')
139 'repository.write')
129 response = self.app.get(url(
140 response = self.app.get(route_path(
130 controller='pullrequests', action='show',
141 'pullrequest_show',
131 repo_name=pull_request.target_repo.scm_instance().name,
142 repo_name=pull_request.target_repo.scm_instance().name,
132 pull_request_id=str(pull_request.pull_request_id)))
143 pull_request_id=pull_request.pull_request_id))
133
144
134 response.mustcontain('Server-side pull request merging is disabled.')
145 response.mustcontain('Server-side pull request merging is disabled.')
135
146
@@ -144,10 +155,10 class TestPullrequestsController(object)
144 Session().add(pull_request)
155 Session().add(pull_request)
145 Session().commit()
156 Session().commit()
146
157
147 response = self.app.get(url(
158 response = self.app.get(route_path(
148 controller='pullrequests', action='show',
159 'pullrequest_show',
149 repo_name=pull_request.target_repo.scm_instance().name,
160 repo_name=pull_request.target_repo.scm_instance().name,
150 pull_request_id=str(pull_request.pull_request_id)))
161 pull_request_id=pull_request.pull_request_id))
151
162
152 for commit_id in pull_request.revisions:
163 for commit_id in pull_request.revisions:
153 response.mustcontain(commit_id)
164 response.mustcontain(commit_id)
@@ -158,22 +169,21 class TestPullrequestsController(object)
158 Session().add(pull_request)
169 Session().add(pull_request)
159 Session().commit()
170 Session().commit()
160
171
161 self.app.get(url(
172 self.app.get(route_path(
162 controller='pullrequests', action='show',
173 'pullrequest_show',
163 repo_name=pull_request.target_repo.scm_instance().name,
174 repo_name=pull_request.target_repo.scm_instance().name,
164 pull_request_id=str(pull_request.pull_request_id)))
175 pull_request_id=pull_request.pull_request_id))
165
176
166 def test_edit_title_description(self, pr_util, csrf_token):
177 def test_edit_title_description(self, pr_util, csrf_token):
167 pull_request = pr_util.create_pull_request()
178 pull_request = pr_util.create_pull_request()
168 pull_request_id = pull_request.pull_request_id
179 pull_request_id = pull_request.pull_request_id
169
180
170 response = self.app.post(
181 response = self.app.post(
171 url(controller='pullrequests', action='update',
182 route_path('pullrequest_update',
172 repo_name=pull_request.target_repo.repo_name,
183 repo_name=pull_request.target_repo.repo_name,
173 pull_request_id=str(pull_request_id)),
184 pull_request_id=pull_request_id),
174 params={
185 params={
175 'edit_pull_request': 'true',
186 'edit_pull_request': 'true',
176 '_method': 'put',
177 'title': 'New title',
187 'title': 'New title',
178 'description': 'New description',
188 'description': 'New description',
179 'csrf_token': csrf_token})
189 'csrf_token': csrf_token})
@@ -192,12 +202,11 class TestPullrequestsController(object)
192 pr_util.close()
202 pr_util.close()
193
203
194 response = self.app.post(
204 response = self.app.post(
195 url(controller='pullrequests', action='update',
205 route_path('pullrequest_update',
196 repo_name=pull_request.target_repo.repo_name,
206 repo_name=pull_request.target_repo.repo_name,
197 pull_request_id=str(pull_request_id)),
207 pull_request_id=pull_request_id),
198 params={
208 params={
199 'edit_pull_request': 'true',
209 'edit_pull_request': 'true',
200 '_method': 'put',
201 'title': 'New title',
210 'title': 'New title',
202 'description': 'New description',
211 'description': 'New description',
203 'csrf_token': csrf_token})
212 'csrf_token': csrf_token})
@@ -217,10 +226,10 class TestPullrequestsController(object)
217 pull_request_id = pull_request.pull_request_id
226 pull_request_id = pull_request.pull_request_id
218
227
219 response = self.app.post(
228 response = self.app.post(
220 url(controller='pullrequests', action='update',
229 route_path('pullrequest_update',
221 repo_name=pull_request.target_repo.repo_name,
230 repo_name=pull_request.target_repo.repo_name,
222 pull_request_id=str(pull_request_id)),
231 pull_request_id=pull_request_id),
223 params={'update_commits': 'true', '_method': 'put',
232 params={'update_commits': 'true',
224 'csrf_token': csrf_token})
233 'csrf_token': csrf_token})
225
234
226 expected_msg = PullRequestModel.UPDATE_STATUS_MESSAGES[
235 expected_msg = PullRequestModel.UPDATE_STATUS_MESSAGES[
@@ -236,10 +245,10 class TestPullrequestsController(object)
236 Session().commit()
245 Session().commit()
237
246
238 pull_request_id = pull_request.pull_request_id
247 pull_request_id = pull_request.pull_request_id
239 pull_request_url = url(
248 pull_request_url = route_path(
240 controller='pullrequests', action='show',
249 'pullrequest_show',
241 repo_name=pull_request.target_repo.repo_name,
250 repo_name=pull_request.target_repo.repo_name,
242 pull_request_id=str(pull_request_id))
251 pull_request_id=pull_request_id)
243
252
244 response = self.app.get(pull_request_url)
253 response = self.app.get(pull_request_url)
245
254
@@ -258,10 +267,9 class TestPullrequestsController(object)
258 repo = pull_request.target_repo.repo_id
267 repo = pull_request.target_repo.repo_id
259
268
260 self.app.post(
269 self.app.post(
261 url(controller='pullrequests',
270 route_path('pullrequest_comment_create',
262 action='comment',
263 repo_name=pull_request.target_repo.scm_instance().name,
271 repo_name=pull_request.target_repo.scm_instance().name,
264 pull_request_id=str(pull_request_id)),
272 pull_request_id=pull_request_id),
265 params={
273 params={
266 'close_pull_request': '1',
274 'close_pull_request': '1',
267 'text': 'Closing a PR',
275 'text': 'Closing a PR',
@@ -298,10 +306,9 class TestPullrequestsController(object)
298 repo = pull_request.target_repo.repo_id
306 repo = pull_request.target_repo.repo_id
299
307
300 self.app.post(
308 self.app.post(
301 url(controller='pullrequests',
309 route_path('pullrequest_comment_create',
302 action='comment',
303 repo_name=pull_request.target_repo.scm_instance().name,
310 repo_name=pull_request.target_repo.scm_instance().name,
304 pull_request_id=str(pull_request_id)),
311 pull_request_id=pull_request_id),
305 params={
312 params={
306 'close_pull_request': '1',
313 'close_pull_request': '1',
307 'csrf_token': csrf_token},
314 'csrf_token': csrf_token},
@@ -326,10 +333,9 class TestPullrequestsController(object)
326 pull_request_id = pull_request.pull_request_id
333 pull_request_id = pull_request.pull_request_id
327
334
328 response = self.app.post(
335 response = self.app.post(
329 url(controller='pullrequests',
336 route_path('pullrequest_comment_create',
330 action='comment',
331 repo_name=pull_request.target_repo.scm_instance().name,
337 repo_name=pull_request.target_repo.scm_instance().name,
332 pull_request_id=str(pull_request.pull_request_id)),
338 pull_request_id=pull_request.pull_request_id),
333 params={
339 params={
334 'close_pull_request': 'true',
340 'close_pull_request': 'true',
335 'csrf_token': csrf_token},
341 'csrf_token': csrf_token},
@@ -356,11 +362,7 class TestPullrequestsController(object)
356 source = backend.create_repo(heads=['change2'])
362 source = backend.create_repo(heads=['change2'])
357
363
358 response = self.app.post(
364 response = self.app.post(
359 url(
365 route_path('pullrequest_create', repo_name=source.repo_name),
360 controller='pullrequests',
361 action='create',
362 repo_name=source.repo_name
363 ),
364 [
366 [
365 ('source_repo', source.repo_name),
367 ('source_repo', source.repo_name),
366 ('source_ref', 'branch:default:' + commit_ids['change2']),
368 ('source_ref', 'branch:default:' + commit_ids['change2']),
@@ -417,11 +419,7 class TestPullrequestsController(object)
417 source = backend.create_repo(heads=['change'])
419 source = backend.create_repo(heads=['change'])
418
420
419 response = self.app.post(
421 response = self.app.post(
420 url(
422 route_path('pullrequest_create', repo_name=source.repo_name),
421 controller='pullrequests',
422 action='create',
423 repo_name=source.repo_name
424 ),
425 [
423 [
426 ('source_repo', source.repo_name),
424 ('source_repo', source.repo_name),
427 ('source_ref', 'branch:default:' + commit_ids['change']),
425 ('source_ref', 'branch:default:' + commit_ids['change']),
@@ -485,11 +483,7 class TestPullrequestsController(object)
485 source = backend.create_repo(heads=['change'])
483 source = backend.create_repo(heads=['change'])
486
484
487 response = self.app.post(
485 response = self.app.post(
488 url(
486 route_path('pullrequest_create', repo_name=source.repo_name),
489 controller='pullrequests',
490 action='create',
491 repo_name=source.repo_name
492 ),
493 [
487 [
494 ('source_repo', source.repo_name),
488 ('source_repo', source.repo_name),
495 ('source_ref', 'branch:default:' + commit_ids['change']),
489 ('source_ref', 'branch:default:' + commit_ids['change']),
@@ -542,10 +536,9 class TestPullrequestsController(object)
542 repo_name = pull_request.target_repo.scm_instance().name,
536 repo_name = pull_request.target_repo.scm_instance().name,
543
537
544 response = self.app.post(
538 response = self.app.post(
545 url(controller='pullrequests',
539 route_path('pullrequest_merge',
546 action='merge',
547 repo_name=str(repo_name[0]),
540 repo_name=str(repo_name[0]),
548 pull_request_id=str(pull_request_id)),
541 pull_request_id=pull_request_id),
549 params={'csrf_token': csrf_token}).follow()
542 params={'csrf_token': csrf_token}).follow()
550
543
551 pull_request = PullRequest.get(pull_request_id)
544 pull_request = PullRequest.get(pull_request_id)
@@ -584,10 +577,9 class TestPullrequestsController(object)
584 pull_request = PullRequest.get(pull_request_id)
577 pull_request = PullRequest.get(pull_request_id)
585
578
586 response = self.app.post(
579 response = self.app.post(
587 url(controller='pullrequests',
580 route_path('pullrequest_merge',
588 action='merge',
589 repo_name=pull_request.target_repo.scm_instance().name,
581 repo_name=pull_request.target_repo.scm_instance().name,
590 pull_request_id=str(pull_request.pull_request_id)),
582 pull_request_id=pull_request.pull_request_id),
591 params={'csrf_token': csrf_token}).follow()
583 params={'csrf_token': csrf_token}).follow()
592
584
593 assert response.status_int == 200
585 assert response.status_int == 200
@@ -599,13 +591,12 class TestPullrequestsController(object)
599 def test_merge_pull_request_not_approved(self, pr_util, csrf_token):
591 def test_merge_pull_request_not_approved(self, pr_util, csrf_token):
600 pull_request = pr_util.create_pull_request(mergeable=True)
592 pull_request = pr_util.create_pull_request(mergeable=True)
601 pull_request_id = pull_request.pull_request_id
593 pull_request_id = pull_request.pull_request_id
602 repo_name = pull_request.target_repo.scm_instance().name,
594 repo_name = pull_request.target_repo.scm_instance().name
603
595
604 response = self.app.post(
596 response = self.app.post(
605 url(controller='pullrequests',
597 route_path('pullrequest_merge',
606 action='merge',
598 repo_name=repo_name,
607 repo_name=str(repo_name[0]),
599 pull_request_id=pull_request_id),
608 pull_request_id=str(pull_request_id)),
609 params={'csrf_token': csrf_token}).follow()
600 params={'csrf_token': csrf_token}).follow()
610
601
611 assert response.status_int == 200
602 assert response.status_int == 200
@@ -614,6 +605,28 class TestPullrequestsController(object)
614 'Merge is not currently possible because of below failed checks.')
605 'Merge is not currently possible because of below failed checks.')
615 response.mustcontain('Pull request reviewer approval is pending.')
606 response.mustcontain('Pull request reviewer approval is pending.')
616
607
608 def test_merge_pull_request_renders_failure_reason(
609 self, user_regular, csrf_token, pr_util):
610 pull_request = pr_util.create_pull_request(mergeable=True, approved=True)
611 pull_request_id = pull_request.pull_request_id
612 repo_name = pull_request.target_repo.scm_instance().name
613
614 model_patcher = mock.patch.multiple(
615 PullRequestModel,
616 merge=mock.Mock(return_value=MergeResponse(
617 True, False, 'STUB_COMMIT_ID', MergeFailureReason.PUSH_FAILED)),
618 merge_status=mock.Mock(return_value=(True, 'WRONG_MESSAGE')))
619
620 with model_patcher:
621 response = self.app.post(
622 route_path('pullrequest_merge',
623 repo_name=repo_name,
624 pull_request_id=pull_request_id),
625 params={'csrf_token': csrf_token}, status=302)
626
627 assert_session_flash(response, PullRequestModel.MERGE_STATUS_MESSAGES[
628 MergeFailureReason.PUSH_FAILED])
629
617 def test_update_source_revision(self, backend, csrf_token):
630 def test_update_source_revision(self, backend, csrf_token):
618 commits = [
631 commits = [
619 {'message': 'ancestor'},
632 {'message': 'ancestor'},
@@ -649,10 +662,10 class TestPullrequestsController(object)
649
662
650 # update PR
663 # update PR
651 self.app.post(
664 self.app.post(
652 url(controller='pullrequests', action='update',
665 route_path('pullrequest_update',
653 repo_name=target.repo_name,
666 repo_name=target.repo_name,
654 pull_request_id=str(pull_request_id)),
667 pull_request_id=pull_request_id),
655 params={'update_commits': 'true', '_method': 'put',
668 params={'update_commits': 'true',
656 'csrf_token': csrf_token})
669 'csrf_token': csrf_token})
657
670
658 # check that we have now both revisions
671 # check that we have now both revisions
@@ -661,8 +674,8 class TestPullrequestsController(object)
661 commit_ids['change-2'], commit_ids['change']]
674 commit_ids['change-2'], commit_ids['change']]
662
675
663 # TODO: johbo: this should be a test on its own
676 # TODO: johbo: this should be a test on its own
664 response = self.app.get(url(
677 response = self.app.get(route_path(
665 controller='pullrequests', action='index',
678 'pullrequest_new',
666 repo_name=target.repo_name))
679 repo_name=target.repo_name))
667 assert response.status_int == 200
680 assert response.status_int == 200
668 assert 'Pull request updated to' in response.body
681 assert 'Pull request updated to' in response.body
@@ -707,10 +720,10 class TestPullrequestsController(object)
707
720
708 # update PR
721 # update PR
709 self.app.post(
722 self.app.post(
710 url(controller='pullrequests', action='update',
723 route_path('pullrequest_update',
711 repo_name=target.repo_name,
724 repo_name=target.repo_name,
712 pull_request_id=str(pull_request_id)),
725 pull_request_id=pull_request_id),
713 params={'update_commits': 'true', '_method': 'put',
726 params={'update_commits': 'true',
714 'csrf_token': csrf_token},
727 'csrf_token': csrf_token},
715 status=200)
728 status=200)
716
729
@@ -722,8 +735,8 class TestPullrequestsController(object)
722 commit_id=commit_ids['ancestor-new'])
735 commit_id=commit_ids['ancestor-new'])
723
736
724 # TODO: johbo: This should be a test on its own
737 # TODO: johbo: This should be a test on its own
725 response = self.app.get(url(
738 response = self.app.get(route_path(
726 controller='pullrequests', action='index',
739 'pullrequest_new',
727 repo_name=target.repo_name))
740 repo_name=target.repo_name))
728 assert response.status_int == 200
741 assert response.status_int == 200
729 assert 'Pull request updated to' in response.body
742 assert 'Pull request updated to' in response.body
@@ -770,10 +783,10 class TestPullrequestsController(object)
770
783
771 # update PR
784 # update PR
772 self.app.post(
785 self.app.post(
773 url(controller='pullrequests', action='update',
786 route_path('pullrequest_update',
774 repo_name=target.repo_name,
787 repo_name=target.repo_name,
775 pull_request_id=str(pull_request_id)),
788 pull_request_id=pull_request_id),
776 params={'update_commits': 'true', '_method': 'put',
789 params={'update_commits': 'true',
777 'csrf_token': csrf_token},
790 'csrf_token': csrf_token},
778 status=200)
791 status=200)
779
792
@@ -814,10 +827,10 class TestPullrequestsController(object)
814 vcs = repo.scm_instance()
827 vcs = repo.scm_instance()
815 vcs.remove_ref('refs/heads/{}'.format(branch_name))
828 vcs.remove_ref('refs/heads/{}'.format(branch_name))
816
829
817 response = self.app.get(url(
830 response = self.app.get(route_path(
818 controller='pullrequests', action='show',
831 'pullrequest_show',
819 repo_name=repo.repo_name,
832 repo_name=repo.repo_name,
820 pull_request_id=str(pull_request.pull_request_id)))
833 pull_request_id=pull_request.pull_request_id))
821
834
822 assert response.status_int == 200
835 assert response.status_int == 200
823 assert_response = AssertResponse(response)
836 assert_response = AssertResponse(response)
@@ -846,10 +859,10 class TestPullrequestsController(object)
846 else:
859 else:
847 vcs.strip(pr_util.commit_ids['new-feature'])
860 vcs.strip(pr_util.commit_ids['new-feature'])
848
861
849 response = self.app.get(url(
862 response = self.app.get(route_path(
850 controller='pullrequests', action='show',
863 'pullrequest_show',
851 repo_name=pr_util.target_repository.repo_name,
864 repo_name=pr_util.target_repository.repo_name,
852 pull_request_id=str(pull_request.pull_request_id)))
865 pull_request_id=pull_request.pull_request_id))
853
866
854 assert response.status_int == 200
867 assert response.status_int == 200
855 assert_response = AssertResponse(response)
868 assert_response = AssertResponse(response)
@@ -882,20 +895,20 class TestPullrequestsController(object)
882 vcs.strip(pr_util.commit_ids['new-feature'])
895 vcs.strip(pr_util.commit_ids['new-feature'])
883
896
884 response = self.app.post(
897 response = self.app.post(
885 url(controller='pullrequests', action='update',
898 route_path('pullrequest_update',
886 repo_name=pull_request.target_repo.repo_name,
899 repo_name=pull_request.target_repo.repo_name,
887 pull_request_id=str(pull_request.pull_request_id)),
900 pull_request_id=pull_request.pull_request_id),
888 params={'update_commits': 'true', '_method': 'put',
901 params={'update_commits': 'true',
889 'csrf_token': csrf_token})
902 'csrf_token': csrf_token})
890
903
891 assert response.status_int == 200
904 assert response.status_int == 200
892 assert response.body == 'true'
905 assert response.body == 'true'
893
906
894 # Make sure that after update, it won't raise 500 errors
907 # Make sure that after update, it won't raise 500 errors
895 response = self.app.get(url(
908 response = self.app.get(route_path(
896 controller='pullrequests', action='show',
909 'pullrequest_show',
897 repo_name=pr_util.target_repository.repo_name,
910 repo_name=pr_util.target_repository.repo_name,
898 pull_request_id=str(pull_request.pull_request_id)))
911 pull_request_id=pull_request.pull_request_id))
899
912
900 assert response.status_int == 200
913 assert response.status_int == 200
901 assert_response = AssertResponse(response)
914 assert_response = AssertResponse(response)
@@ -910,10 +923,10 class TestPullrequestsController(object)
910 Session().add(pull_request)
923 Session().add(pull_request)
911 Session().commit()
924 Session().commit()
912
925
913 response = self.app.get(url(
926 response = self.app.get(route_path(
914 controller='pullrequests', action='show',
927 'pullrequest_show',
915 repo_name=pull_request.target_repo.scm_instance().name,
928 repo_name=pull_request.target_repo.scm_instance().name,
916 pull_request_id=str(pull_request.pull_request_id)))
929 pull_request_id=pull_request.pull_request_id))
917 assert response.status_int == 200
930 assert response.status_int == 200
918 assert_response = AssertResponse(response)
931 assert_response = AssertResponse(response)
919
932
@@ -944,10 +957,10 class TestPullrequestsController(object)
944 Session().add(pull_request)
957 Session().add(pull_request)
945 Session().commit()
958 Session().commit()
946
959
947 response = self.app.get(url(
960 response = self.app.get(route_path(
948 controller='pullrequests', action='show',
961 'pullrequest_show',
949 repo_name=pull_request.target_repo.scm_instance().name,
962 repo_name=pull_request.target_repo.scm_instance().name,
950 pull_request_id=str(pull_request.pull_request_id)))
963 pull_request_id=pull_request.pull_request_id))
951 assert response.status_int == 200
964 assert response.status_int == 200
952 assert_response = AssertResponse(response)
965 assert_response = AssertResponse(response)
953
966
@@ -966,10 +979,10 class TestPullrequestsController(object)
966 Session().add(pull_request)
979 Session().add(pull_request)
967 Session().commit()
980 Session().commit()
968
981
969 response = self.app.get(url(
982 response = self.app.get(route_path(
970 controller='pullrequests', action='show',
983 'pullrequest_show',
971 repo_name=pull_request.target_repo.scm_instance().name,
984 repo_name=pull_request.target_repo.scm_instance().name,
972 pull_request_id=str(pull_request.pull_request_id)))
985 pull_request_id=pull_request.pull_request_id))
973 assert response.status_int == 200
986 assert response.status_int == 200
974 assert_response = AssertResponse(response)
987 assert_response = AssertResponse(response)
975
988
@@ -996,10 +1009,10 class TestPullrequestsController(object)
996 shadow_url = '{host}/{repo}/pull-request/{pr_id}/repository'.format(
1009 shadow_url = '{host}/{repo}/pull-request/{pr_id}/repository'.format(
997 host=http_host_only_stub, repo=target_repo.name, pr_id=pr_id)
1010 host=http_host_only_stub, repo=target_repo.name, pr_id=pr_id)
998
1011
999 response = self.app.get(url(
1012 response = self.app.get(route_path(
1000 controller='pullrequests', action='show',
1013 'pullrequest_show',
1001 repo_name=target_repo.name,
1014 repo_name=target_repo.name,
1002 pull_request_id=str(pr_id)))
1015 pull_request_id=pr_id))
1003
1016
1004 assertr = AssertResponse(response)
1017 assertr = AssertResponse(response)
1005 if mergeable:
1018 if mergeable:
@@ -1019,10 +1032,10 class TestPullrequestsControllerDelete(o
1019 pull_request = pr_util.create_pull_request(
1032 pull_request = pr_util.create_pull_request(
1020 author=user_admin.username, enable_notifications=False)
1033 author=user_admin.username, enable_notifications=False)
1021
1034
1022 response = self.app.get(url(
1035 response = self.app.get(route_path(
1023 controller='pullrequests', action='show',
1036 'pullrequest_show',
1024 repo_name=pull_request.target_repo.scm_instance().name,
1037 repo_name=pull_request.target_repo.scm_instance().name,
1025 pull_request_id=str(pull_request.pull_request_id)))
1038 pull_request_id=pull_request.pull_request_id))
1026
1039
1027 response.mustcontain('id="delete_pullrequest"')
1040 response.mustcontain('id="delete_pullrequest"')
1028 response.mustcontain('Confirm to delete this pull request')
1041 response.mustcontain('Confirm to delete this pull request')
@@ -1032,10 +1045,10 class TestPullrequestsControllerDelete(o
1032 pull_request = pr_util.create_pull_request(
1045 pull_request = pr_util.create_pull_request(
1033 author=user_regular.username, enable_notifications=False)
1046 author=user_regular.username, enable_notifications=False)
1034
1047
1035 response = self.app.get(url(
1048 response = self.app.get(route_path(
1036 controller='pullrequests', action='show',
1049 'pullrequest_show',
1037 repo_name=pull_request.target_repo.scm_instance().name,
1050 repo_name=pull_request.target_repo.scm_instance().name,
1038 pull_request_id=str(pull_request.pull_request_id)))
1051 pull_request_id=pull_request.pull_request_id))
1039
1052
1040 response.mustcontain('id="delete_pullrequest"')
1053 response.mustcontain('id="delete_pullrequest"')
1041 response.mustcontain('Confirm to delete this pull request')
1054 response.mustcontain('Confirm to delete this pull request')
@@ -1045,10 +1058,10 class TestPullrequestsControllerDelete(o
1045 pull_request = pr_util.create_pull_request(
1058 pull_request = pr_util.create_pull_request(
1046 author=user_admin.username, enable_notifications=False)
1059 author=user_admin.username, enable_notifications=False)
1047
1060
1048 response = self.app.get(url(
1061 response = self.app.get(route_path(
1049 controller='pullrequests', action='show',
1062 'pullrequest_show',
1050 repo_name=pull_request.target_repo.scm_instance().name,
1063 repo_name=pull_request.target_repo.scm_instance().name,
1051 pull_request_id=str(pull_request.pull_request_id)))
1064 pull_request_id=pull_request.pull_request_id))
1052 response.mustcontain(no=['id="delete_pullrequest"'])
1065 response.mustcontain(no=['id="delete_pullrequest"'])
1053 response.mustcontain(no=['Confirm to delete this pull request'])
1066 response.mustcontain(no=['Confirm to delete this pull request'])
1054
1067
@@ -1063,10 +1076,10 class TestPullrequestsControllerDelete(o
1063 pull_request.target_repo, user_regular,
1076 pull_request.target_repo, user_regular,
1064 'repository.write')
1077 'repository.write')
1065
1078
1066 response = self.app.get(url(
1079 response = self.app.get(route_path(
1067 controller='pullrequests', action='show',
1080 'pullrequest_show',
1068 repo_name=pull_request.target_repo.scm_instance().name,
1081 repo_name=pull_request.target_repo.scm_instance().name,
1069 pull_request_id=str(pull_request.pull_request_id)))
1082 pull_request_id=pull_request.pull_request_id))
1070
1083
1071 response.mustcontain('id="open_edit_pullrequest"')
1084 response.mustcontain('id="open_edit_pullrequest"')
1072 response.mustcontain('id="delete_pullrequest"')
1085 response.mustcontain('id="delete_pullrequest"')
@@ -1078,9 +1091,10 class TestPullrequestsControllerDelete(o
1078 pull_request = pr_util.create_pull_request(
1091 pull_request = pr_util.create_pull_request(
1079 author=user_admin.username, enable_notifications=False)
1092 author=user_admin.username, enable_notifications=False)
1080
1093
1081 self.app.get(url(
1094 self.app.get(route_path(
1082 controller='pullrequests', action='delete_comment',
1095 'pullrequest_comment_delete',
1083 repo_name=pull_request.target_repo.scm_instance().name,
1096 repo_name=pull_request.target_repo.scm_instance().name,
1097 pull_request_id=pull_request.pull_request_id,
1084 comment_id=1024404), status=404)
1098 comment_id=1024404), status=404)
1085
1099
1086
1100
@@ -1090,17 +1104,9 def assert_pull_request_status(pull_requ
1090 assert status == expected_status
1104 assert status == expected_status
1091
1105
1092
1106
1093 @pytest.mark.parametrize('action', ['index', 'create'])
1107 @pytest.mark.parametrize('route', ['pullrequest_new', 'pullrequest_create'])
1094 @pytest.mark.usefixtures("autologin_user")
1108 @pytest.mark.usefixtures("autologin_user")
1095 def test_redirects_to_repo_summary_for_svn_repositories(backend_svn, app, action):
1109 def test_forbidde_to_repo_summary_for_svn_repositories(backend_svn, app, route):
1096 response = app.get(url(
1110 response = app.get(
1097 controller='pullrequests', action=action,
1111 route_path(route, repo_name=backend_svn.repo_name), status=404)
1098 repo_name=backend_svn.repo_name))
1099 assert response.status_int == 302
1100
1112
1101 # Not allowed, redirect to the summary
1102 redirected = response.follow()
1103 summary_url = h.route_path('repo_summary', repo_name=backend_svn.repo_name)
1104
1105 # URL adds leading slash and path doesn't have it
1106 assert redirected.request.path == summary_url
This diff has been collapsed as it changes many lines, (630 lines changed) Show them Hide them
@@ -19,23 +19,35
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 logging
21 import logging
22 import collections
22
23
23 import collections
24 import formencode
24 from pyramid.httpexceptions import HTTPFound, HTTPNotFound
25 import peppercorn
26 from pyramid.httpexceptions import (
27 HTTPFound, HTTPNotFound, HTTPForbidden, HTTPBadRequest)
25 from pyramid.view import view_config
28 from pyramid.view import view_config
29 from pyramid.renderers import render
26
30
31 from rhodecode import events
27 from rhodecode.apps._base import RepoAppView, DataGridAppView
32 from rhodecode.apps._base import RepoAppView, DataGridAppView
28 from rhodecode.lib import helpers as h, diffs, codeblocks
33
34 from rhodecode.lib import helpers as h, diffs, codeblocks, channelstream
35 from rhodecode.lib.base import vcs_operation_context
36 from rhodecode.lib.ext_json import json
29 from rhodecode.lib.auth import (
37 from rhodecode.lib.auth import (
30 LoginRequired, HasRepoPermissionAnyDecorator)
38 LoginRequired, HasRepoPermissionAnyDecorator, NotAnonymous, CSRFRequired)
31 from rhodecode.lib.utils2 import str2bool, safe_int, safe_str
39 from rhodecode.lib.utils2 import str2bool, safe_str, safe_unicode
32 from rhodecode.lib.vcs.backends.base import EmptyCommit
40 from rhodecode.lib.vcs.backends.base import EmptyCommit, UpdateFailureReason
33 from rhodecode.lib.vcs.exceptions import CommitDoesNotExistError, \
41 from rhodecode.lib.vcs.exceptions import (CommitDoesNotExistError,
34 RepositoryRequirementError, NodeDoesNotExistError
42 RepositoryRequirementError, NodeDoesNotExistError, EmptyRepositoryError)