Show More
@@ -116,6 +116,223 b' class TestPullrequestsView(object):' | |||||
116 | if range_diff == "1": |
|
116 | if range_diff == "1": | |
117 | response.mustcontain('Turn off: Show the diff as commit range') |
|
117 | response.mustcontain('Turn off: Show the diff as commit range') | |
118 |
|
118 | |||
|
119 | def test_show_versions_of_pr(self, backend, csrf_token): | |||
|
120 | commits = [ | |||
|
121 | {'message': 'initial-commit', | |||
|
122 | 'added': [FileNode('test-file.txt', 'LINE1\n')]}, | |||
|
123 | ||||
|
124 | {'message': 'commit-1', | |||
|
125 | 'changed': [FileNode('test-file.txt', 'LINE1\nLINE2\n')]}, | |||
|
126 | # Above is the initial version of PR that changes a single line | |||
|
127 | ||||
|
128 | # from now on we'll add 3x commit adding a nother line on each step | |||
|
129 | {'message': 'commit-2', | |||
|
130 | 'changed': [FileNode('test-file.txt', 'LINE1\nLINE2\nLINE3\n')]}, | |||
|
131 | ||||
|
132 | {'message': 'commit-3', | |||
|
133 | 'changed': [FileNode('test-file.txt', 'LINE1\nLINE2\nLINE3\nLINE4\n')]}, | |||
|
134 | ||||
|
135 | {'message': 'commit-4', | |||
|
136 | 'changed': [FileNode('test-file.txt', 'LINE1\nLINE2\nLINE3\nLINE4\nLINE5\n')]}, | |||
|
137 | ] | |||
|
138 | ||||
|
139 | commit_ids = backend.create_master_repo(commits) | |||
|
140 | target = backend.create_repo(heads=['initial-commit']) | |||
|
141 | source = backend.create_repo(heads=['commit-1']) | |||
|
142 | source_repo_name = source.repo_name | |||
|
143 | target_repo_name = target.repo_name | |||
|
144 | ||||
|
145 | target_ref = 'branch:{branch}:{commit_id}'.format( | |||
|
146 | branch=backend.default_branch_name, commit_id=commit_ids['initial-commit']) | |||
|
147 | source_ref = 'branch:{branch}:{commit_id}'.format( | |||
|
148 | branch=backend.default_branch_name, commit_id=commit_ids['commit-1']) | |||
|
149 | ||||
|
150 | response = self.app.post( | |||
|
151 | route_path('pullrequest_create', repo_name=source.repo_name), | |||
|
152 | [ | |||
|
153 | ('source_repo', source.repo_name), | |||
|
154 | ('source_ref', source_ref), | |||
|
155 | ('target_repo', target.repo_name), | |||
|
156 | ('target_ref', target_ref), | |||
|
157 | ('common_ancestor', commit_ids['initial-commit']), | |||
|
158 | ('pullrequest_title', 'Title'), | |||
|
159 | ('pullrequest_desc', 'Description'), | |||
|
160 | ('description_renderer', 'markdown'), | |||
|
161 | ('__start__', 'review_members:sequence'), | |||
|
162 | ('__start__', 'reviewer:mapping'), | |||
|
163 | ('user_id', '1'), | |||
|
164 | ('__start__', 'reasons:sequence'), | |||
|
165 | ('reason', 'Some reason'), | |||
|
166 | ('__end__', 'reasons:sequence'), | |||
|
167 | ('__start__', 'rules:sequence'), | |||
|
168 | ('__end__', 'rules:sequence'), | |||
|
169 | ('mandatory', 'False'), | |||
|
170 | ('__end__', 'reviewer:mapping'), | |||
|
171 | ('__end__', 'review_members:sequence'), | |||
|
172 | ('__start__', 'revisions:sequence'), | |||
|
173 | ('revisions', commit_ids['commit-1']), | |||
|
174 | ('__end__', 'revisions:sequence'), | |||
|
175 | ('user', ''), | |||
|
176 | ('csrf_token', csrf_token), | |||
|
177 | ], | |||
|
178 | status=302) | |||
|
179 | ||||
|
180 | location = response.headers['Location'] | |||
|
181 | ||||
|
182 | pull_request_id = location.rsplit('/', 1)[1] | |||
|
183 | assert pull_request_id != 'new' | |||
|
184 | pull_request = PullRequest.get(int(pull_request_id)) | |||
|
185 | ||||
|
186 | pull_request_id = pull_request.pull_request_id | |||
|
187 | ||||
|
188 | # Show initial version of PR | |||
|
189 | response = self.app.get( | |||
|
190 | route_path('pullrequest_show', | |||
|
191 | repo_name=target_repo_name, | |||
|
192 | pull_request_id=pull_request_id)) | |||
|
193 | ||||
|
194 | response.mustcontain('commit-1') | |||
|
195 | response.mustcontain(no=['commit-2']) | |||
|
196 | response.mustcontain(no=['commit-3']) | |||
|
197 | response.mustcontain(no=['commit-4']) | |||
|
198 | ||||
|
199 | response.mustcontain('cb-addition"></span><span>LINE2</span>') | |||
|
200 | response.mustcontain(no=['LINE3']) | |||
|
201 | response.mustcontain(no=['LINE4']) | |||
|
202 | response.mustcontain(no=['LINE5']) | |||
|
203 | ||||
|
204 | # update PR #1 | |||
|
205 | source_repo = Repository.get_by_repo_name(source_repo_name) | |||
|
206 | backend.pull_heads(source_repo, heads=['commit-2']) | |||
|
207 | response = self.app.post( | |||
|
208 | route_path('pullrequest_update', | |||
|
209 | repo_name=target_repo_name, pull_request_id=pull_request_id), | |||
|
210 | params={'update_commits': 'true', 'csrf_token': csrf_token}) | |||
|
211 | ||||
|
212 | # update PR #2 | |||
|
213 | source_repo = Repository.get_by_repo_name(source_repo_name) | |||
|
214 | backend.pull_heads(source_repo, heads=['commit-3']) | |||
|
215 | response = self.app.post( | |||
|
216 | route_path('pullrequest_update', | |||
|
217 | repo_name=target_repo_name, pull_request_id=pull_request_id), | |||
|
218 | params={'update_commits': 'true', 'csrf_token': csrf_token}) | |||
|
219 | ||||
|
220 | # update PR #3 | |||
|
221 | source_repo = Repository.get_by_repo_name(source_repo_name) | |||
|
222 | backend.pull_heads(source_repo, heads=['commit-4']) | |||
|
223 | response = self.app.post( | |||
|
224 | route_path('pullrequest_update', | |||
|
225 | repo_name=target_repo_name, pull_request_id=pull_request_id), | |||
|
226 | params={'update_commits': 'true', 'csrf_token': csrf_token}) | |||
|
227 | ||||
|
228 | # Show final version ! | |||
|
229 | response = self.app.get( | |||
|
230 | route_path('pullrequest_show', | |||
|
231 | repo_name=target_repo_name, | |||
|
232 | pull_request_id=pull_request_id)) | |||
|
233 | ||||
|
234 | # 3 updates, and the latest == 4 | |||
|
235 | response.mustcontain('4 versions available for this pull request') | |||
|
236 | response.mustcontain(no=['rhodecode diff rendering error']) | |||
|
237 | ||||
|
238 | # initial show must have 3 commits, and 3 adds | |||
|
239 | response.mustcontain('commit-1') | |||
|
240 | response.mustcontain('commit-2') | |||
|
241 | response.mustcontain('commit-3') | |||
|
242 | response.mustcontain('commit-4') | |||
|
243 | ||||
|
244 | response.mustcontain('cb-addition"></span><span>LINE2</span>') | |||
|
245 | response.mustcontain('cb-addition"></span><span>LINE3</span>') | |||
|
246 | response.mustcontain('cb-addition"></span><span>LINE4</span>') | |||
|
247 | response.mustcontain('cb-addition"></span><span>LINE5</span>') | |||
|
248 | ||||
|
249 | # fetch versions | |||
|
250 | pr = PullRequest.get(pull_request_id) | |||
|
251 | versions = [x.pull_request_version_id for x in pr.versions.all()] | |||
|
252 | assert len(versions) == 3 | |||
|
253 | ||||
|
254 | # show v1,v2,v3,v4 | |||
|
255 | def cb_line(text): | |||
|
256 | return 'cb-addition"></span><span>{}</span>'.format(text) | |||
|
257 | ||||
|
258 | def cb_context(text): | |||
|
259 | return '<span class="cb-code"><span class="cb-action cb-context">' \ | |||
|
260 | '</span><span>{}</span></span>'.format(text) | |||
|
261 | ||||
|
262 | commit_tests = { | |||
|
263 | # in response, not in response | |||
|
264 | 1: (['commit-1'], ['commit-2', 'commit-3', 'commit-4']), | |||
|
265 | 2: (['commit-1', 'commit-2'], ['commit-3', 'commit-4']), | |||
|
266 | 3: (['commit-1', 'commit-2', 'commit-3'], ['commit-4']), | |||
|
267 | 4: (['commit-1', 'commit-2', 'commit-3', 'commit-4'], []), | |||
|
268 | } | |||
|
269 | diff_tests = { | |||
|
270 | 1: (['LINE2'], ['LINE3', 'LINE4', 'LINE5']), | |||
|
271 | 2: (['LINE2', 'LINE3'], ['LINE4', 'LINE5']), | |||
|
272 | 3: (['LINE2', 'LINE3', 'LINE4'], ['LINE5']), | |||
|
273 | 4: (['LINE2', 'LINE3', 'LINE4', 'LINE5'], []), | |||
|
274 | } | |||
|
275 | for idx, ver in enumerate(versions, 1): | |||
|
276 | ||||
|
277 | response = self.app.get( | |||
|
278 | route_path('pullrequest_show', | |||
|
279 | repo_name=target_repo_name, | |||
|
280 | pull_request_id=pull_request_id, | |||
|
281 | params={'version': ver})) | |||
|
282 | ||||
|
283 | response.mustcontain(no=['rhodecode diff rendering error']) | |||
|
284 | response.mustcontain('Showing changes at v{}'.format(idx)) | |||
|
285 | ||||
|
286 | yes, no = commit_tests[idx] | |||
|
287 | for y in yes: | |||
|
288 | response.mustcontain(y) | |||
|
289 | for n in no: | |||
|
290 | response.mustcontain(no=n) | |||
|
291 | ||||
|
292 | yes, no = diff_tests[idx] | |||
|
293 | for y in yes: | |||
|
294 | response.mustcontain(cb_line(y)) | |||
|
295 | for n in no: | |||
|
296 | response.mustcontain(no=n) | |||
|
297 | ||||
|
298 | # show diff between versions | |||
|
299 | diff_compare_tests = { | |||
|
300 | 1: (['LINE3'], ['LINE1', 'LINE2']), | |||
|
301 | 2: (['LINE3', 'LINE4'], ['LINE1', 'LINE2']), | |||
|
302 | 3: (['LINE3', 'LINE4', 'LINE5'], ['LINE1', 'LINE2']), | |||
|
303 | } | |||
|
304 | for idx, ver in enumerate(versions, 1): | |||
|
305 | adds, context = diff_compare_tests[idx] | |||
|
306 | ||||
|
307 | to_ver = ver+1 | |||
|
308 | if idx == 3: | |||
|
309 | to_ver = 'latest' | |||
|
310 | ||||
|
311 | response = self.app.get( | |||
|
312 | route_path('pullrequest_show', | |||
|
313 | repo_name=target_repo_name, | |||
|
314 | pull_request_id=pull_request_id, | |||
|
315 | params={'from_version': versions[0], 'version': to_ver})) | |||
|
316 | ||||
|
317 | response.mustcontain(no=['rhodecode diff rendering error']) | |||
|
318 | ||||
|
319 | for a in adds: | |||
|
320 | response.mustcontain(cb_line(a)) | |||
|
321 | for c in context: | |||
|
322 | response.mustcontain(cb_context(c)) | |||
|
323 | ||||
|
324 | # test version v2 -> v3 | |||
|
325 | response = self.app.get( | |||
|
326 | route_path('pullrequest_show', | |||
|
327 | repo_name=target_repo_name, | |||
|
328 | pull_request_id=pull_request_id, | |||
|
329 | params={'from_version': versions[1], 'version': versions[2]})) | |||
|
330 | ||||
|
331 | response.mustcontain(cb_context('LINE1')) | |||
|
332 | response.mustcontain(cb_context('LINE2')) | |||
|
333 | response.mustcontain(cb_context('LINE3')) | |||
|
334 | response.mustcontain(cb_line('LINE4')) | |||
|
335 | ||||
119 | def test_close_status_visibility(self, pr_util, user_util, csrf_token): |
|
336 | def test_close_status_visibility(self, pr_util, user_util, csrf_token): | |
120 | # Logout |
|
337 | # Logout | |
121 | response = self.app.post( |
|
338 | response = self.app.post( |
@@ -214,9 +214,12 b' class RepoPullRequestsView(RepoAppView, ' | |||||
214 | ancestor_commit, |
|
214 | ancestor_commit, | |
215 | source_ref_id, target_ref_id, |
|
215 | source_ref_id, target_ref_id, | |
216 | target_commit, source_commit, diff_limit, file_limit, |
|
216 | target_commit, source_commit, diff_limit, file_limit, | |
217 | fulldiff, hide_whitespace_changes, diff_context): |
|
217 | fulldiff, hide_whitespace_changes, diff_context, use_ancestor=True): | |
218 |
|
218 | |||
|
219 | if use_ancestor: | |||
|
220 | # we might want to not use it for versions | |||
219 | target_ref_id = ancestor_commit.raw_id |
|
221 | target_ref_id = ancestor_commit.raw_id | |
|
222 | ||||
220 | vcs_diff = PullRequestModel().get_diff( |
|
223 | vcs_diff = PullRequestModel().get_diff( | |
221 | source_repo, source_ref_id, target_ref_id, |
|
224 | source_repo, source_ref_id, target_ref_id, | |
222 | hide_whitespace_changes, diff_context) |
|
225 | hide_whitespace_changes, diff_context) | |
@@ -593,6 +596,10 b' class RepoPullRequestsView(RepoAppView, ' | |||||
593 | else: |
|
596 | else: | |
594 | c.inline_comments = display_inline_comments |
|
597 | c.inline_comments = display_inline_comments | |
595 |
|
598 | |||
|
599 | use_ancestor = True | |||
|
600 | if from_version_normalized != version_normalized: | |||
|
601 | use_ancestor = False | |||
|
602 | ||||
596 | has_proper_diff_cache = cached_diff and cached_diff.get('commits') |
|
603 | has_proper_diff_cache = cached_diff and cached_diff.get('commits') | |
597 | if not force_recache and has_proper_diff_cache: |
|
604 | if not force_recache and has_proper_diff_cache: | |
598 | c.diffset = cached_diff['diff'] |
|
605 | c.diffset = cached_diff['diff'] | |
@@ -603,7 +610,9 b' class RepoPullRequestsView(RepoAppView, ' | |||||
603 | source_ref_id, target_ref_id, |
|
610 | source_ref_id, target_ref_id, | |
604 | target_commit, source_commit, |
|
611 | target_commit, source_commit, | |
605 | diff_limit, file_limit, c.fulldiff, |
|
612 | diff_limit, file_limit, c.fulldiff, | |
606 |
hide_whitespace_changes, diff_context |
|
613 | hide_whitespace_changes, diff_context, | |
|
614 | use_ancestor=use_ancestor | |||
|
615 | ) | |||
607 |
|
616 | |||
608 | # save cached diff |
|
617 | # save cached diff | |
609 | if caching_enabled: |
|
618 | if caching_enabled: |
@@ -560,6 +560,7 b' class Backend(object):' | |||||
560 |
|
560 | |||
561 | invalid_repo_name = re.compile(r'[^0-9a-zA-Z]+') |
|
561 | invalid_repo_name = re.compile(r'[^0-9a-zA-Z]+') | |
562 | _master_repo = None |
|
562 | _master_repo = None | |
|
563 | _master_repo_path = '' | |||
563 | _commit_ids = {} |
|
564 | _commit_ids = {} | |
564 |
|
565 | |||
565 | def __init__(self, alias, repo_name, test_name, test_repo_container): |
|
566 | def __init__(self, alias, repo_name, test_name, test_repo_container): | |
@@ -624,6 +625,8 b' class Backend(object):' | |||||
624 | Returns a commit map which maps from commit message to raw_id. |
|
625 | Returns a commit map which maps from commit message to raw_id. | |
625 | """ |
|
626 | """ | |
626 | self._master_repo = self.create_repo(commits=commits) |
|
627 | self._master_repo = self.create_repo(commits=commits) | |
|
628 | self._master_repo_path = self._master_repo.repo_full_path | |||
|
629 | ||||
627 | return self._commit_ids |
|
630 | return self._commit_ids | |
628 |
|
631 | |||
629 | def create_repo( |
|
632 | def create_repo( | |
@@ -661,11 +664,10 b' class Backend(object):' | |||||
661 | """ |
|
664 | """ | |
662 | Make sure that repo contains all commits mentioned in `heads` |
|
665 | Make sure that repo contains all commits mentioned in `heads` | |
663 | """ |
|
666 | """ | |
664 | vcsmaster = self._master_repo.scm_instance() |
|
|||
665 | vcsrepo = repo.scm_instance() |
|
667 | vcsrepo = repo.scm_instance() | |
666 | vcsrepo.config.clear_section('hooks') |
|
668 | vcsrepo.config.clear_section('hooks') | |
667 | commit_ids = [self._commit_ids[h] for h in heads] |
|
669 | commit_ids = [self._commit_ids[h] for h in heads] | |
668 |
vcsrepo.pull( |
|
670 | vcsrepo.pull(self._master_repo_path, commit_ids=commit_ids) | |
669 |
|
671 | |||
670 | def create_fork(self): |
|
672 | def create_fork(self): | |
671 | repo_to_fork = self.repo_name |
|
673 | repo_to_fork = self.repo_name |
General Comments 0
You need to be logged in to leave comments.
Login now