##// END OF EJS Templates
tests: fixes #4168 xfail for compare_remote_with_different_commit_indexes
lisaq -
r674:b8dc8ea6 default
parent child Browse files
Show More
@@ -1,689 +1,691 b''
1 1 # -*- coding: utf-8 -*-
2 2
3 3 # Copyright (C) 2010-2016 RhodeCode GmbH
4 4 #
5 5 # This program is free software: you can redistribute it and/or modify
6 6 # it under the terms of the GNU Affero General Public License, version 3
7 7 # (only), as published by the Free Software Foundation.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU Affero General Public License
15 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16 #
17 17 # This program is dual-licensed. If you wish to learn more about the
18 18 # RhodeCode Enterprise Edition, including its added features, Support services,
19 19 # and proprietary license terms, please see https://rhodecode.com/licenses/
20 20
21 21 import mock
22 22 import pytest
23 23
24 24 from rhodecode.lib.vcs.backends.base import EmptyCommit
25 25 from rhodecode.lib.vcs.exceptions import RepositoryRequirementError
26 26 from rhodecode.model.db import Repository
27 27 from rhodecode.model.scm import ScmModel
28 28 from rhodecode.tests import url, TEST_USER_ADMIN_LOGIN, assert_session_flash
29 29 from rhodecode.tests.utils import AssertResponse
30 30
31 31
32 32 @pytest.mark.usefixtures("autologin_user", "app")
33 33 class TestCompareController:
34 34
35 @pytest.mark.xfail_backends("svn", "git")
35 @pytest.mark.xfail_backends("svn", reason="Requires pull")
36 36 def test_compare_remote_with_different_commit_indexes(self, backend):
37 37 # Preparing the following repository structure:
38 38 #
39 39 # Origin repository has two commits:
40 40 #
41 41 # 0 1
42 42 # A -- D
43 43 #
44 44 # The fork of it has a few more commits and "D" has a commit index
45 45 # which does not exist in origin.
46 46 #
47 47 # 0 1 2 3 4
48 48 # A -- -- -- D -- E
49 49 # \- B -- C
50 50 #
51 51
52 52 fork = backend.create_repo()
53 53
54 54 # prepare fork
55 55 commit0 = _commit_change(
56 56 fork.repo_name, filename='file1', content='A',
57 57 message='A', vcs_type=backend.alias, parent=None, newfile=True)
58 58
59 59 commit1 = _commit_change(
60 60 fork.repo_name, filename='file1', content='B',
61 61 message='B, child of A', vcs_type=backend.alias, parent=commit0)
62 62
63 63 _commit_change( # commit 2
64 64 fork.repo_name, filename='file1', content='C',
65 65 message='C, child of B', vcs_type=backend.alias, parent=commit1)
66 66
67 67 commit3 = _commit_change(
68 68 fork.repo_name, filename='file1', content='D',
69 69 message='D, child of A', vcs_type=backend.alias, parent=commit0)
70 70
71 71 commit4 = _commit_change(
72 72 fork.repo_name, filename='file1', content='E',
73 73 message='E, child of D', vcs_type=backend.alias, parent=commit3)
74 74
75 75 # prepare origin repository, taking just the history up to D
76 76 origin = backend.create_repo()
77 77
78 78 origin_repo = origin.scm_instance(cache=False)
79 79 origin_repo.config.clear_section('hooks')
80 80 origin_repo.pull(fork.repo_full_path, commit_ids=[commit3.raw_id])
81 81
82 82 # Verify test fixture setup
83 assert 5 == len(fork.scm_instance().commit_ids)
84 assert 2 == len(origin_repo.commit_ids)
83 # This does not work for git
84 if backend.alias != 'git':
85 assert 5 == len(fork.scm_instance().commit_ids)
86 assert 2 == len(origin_repo.commit_ids)
85 87
86 88 # Comparing the revisions
87 89 response = self.app.get(
88 90 url('compare_url',
89 91 repo_name=origin.repo_name,
90 92 source_ref_type="rev",
91 93 source_ref=commit3.raw_id,
92 94 target_repo=fork.repo_name,
93 95 target_ref_type="rev",
94 96 target_ref=commit4.raw_id,
95 97 merge='1',))
96 98
97 99 compare_page = ComparePage(response)
98 100 compare_page.contains_commits([commit4])
99 101
100 102 @pytest.mark.xfail_backends("svn", reason="Depends on branch support")
101 103 def test_compare_forks_on_branch_extra_commits(self, backend):
102 104 repo1 = backend.create_repo()
103 105
104 106 # commit something !
105 107 commit0 = _commit_change(
106 108 repo1.repo_name, filename='file1', content='line1\n',
107 109 message='commit1', vcs_type=backend.alias, parent=None,
108 110 newfile=True)
109 111
110 112 # fork this repo
111 113 repo2 = backend.create_fork()
112 114
113 115 # add two extra commit into fork
114 116 commit1 = _commit_change(
115 117 repo2.repo_name, filename='file1', content='line1\nline2\n',
116 118 message='commit2', vcs_type=backend.alias, parent=commit0)
117 119
118 120 commit2 = _commit_change(
119 121 repo2.repo_name, filename='file1', content='line1\nline2\nline3\n',
120 122 message='commit3', vcs_type=backend.alias, parent=commit1)
121 123
122 124 commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME
123 125 commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME
124 126
125 127 response = self.app.get(
126 128 url('compare_url',
127 129 repo_name=repo1.repo_name,
128 130 source_ref_type="branch",
129 131 source_ref=commit_id2,
130 132 target_repo=repo2.repo_name,
131 133 target_ref_type="branch",
132 134 target_ref=commit_id1,
133 135 merge='1',))
134 136
135 137 response.mustcontain('%s@%s' % (repo1.repo_name, commit_id2))
136 138 response.mustcontain('%s@%s' % (repo2.repo_name, commit_id1))
137 139
138 140 compare_page = ComparePage(response)
139 141 compare_page.contains_change_summary(1, 2, 0)
140 142 compare_page.contains_commits([commit1, commit2])
141 143 compare_page.contains_file_links_and_anchors([
142 144 ('file1', 'a_c--826e8142e6ba'),
143 145 ])
144 146
145 147 # Swap is removed when comparing branches since it's a PR feature and
146 148 # it is then a preview mode
147 149 compare_page.swap_is_hidden()
148 150 compare_page.target_source_are_disabled()
149 151
150 152 @pytest.mark.xfail_backends("svn", reason="Depends on branch support")
151 153 def test_compare_forks_on_branch_extra_commits_origin_has_incomming(
152 154 self, backend):
153 155 repo1 = backend.create_repo()
154 156
155 157 # commit something !
156 158 commit0 = _commit_change(
157 159 repo1.repo_name, filename='file1', content='line1\n',
158 160 message='commit1', vcs_type=backend.alias, parent=None,
159 161 newfile=True)
160 162
161 163 # fork this repo
162 164 repo2 = backend.create_fork()
163 165
164 166 # now commit something to origin repo
165 167 _commit_change(
166 168 repo1.repo_name, filename='file2', content='line1file2\n',
167 169 message='commit2', vcs_type=backend.alias, parent=commit0,
168 170 newfile=True)
169 171
170 172 # add two extra commit into fork
171 173 commit1 = _commit_change(
172 174 repo2.repo_name, filename='file1', content='line1\nline2\n',
173 175 message='commit2', vcs_type=backend.alias, parent=commit0)
174 176
175 177 commit2 = _commit_change(
176 178 repo2.repo_name, filename='file1', content='line1\nline2\nline3\n',
177 179 message='commit3', vcs_type=backend.alias, parent=commit1)
178 180
179 181 commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME
180 182 commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME
181 183
182 184 response = self.app.get(
183 185 url('compare_url',
184 186 repo_name=repo1.repo_name,
185 187 source_ref_type="branch",
186 188 source_ref=commit_id2,
187 189 target_repo=repo2.repo_name,
188 190 target_ref_type="branch",
189 191 target_ref=commit_id1,
190 192 merge='1'))
191 193
192 194 response.mustcontain('%s@%s' % (repo1.repo_name, commit_id2))
193 195 response.mustcontain('%s@%s' % (repo2.repo_name, commit_id1))
194 196
195 197 compare_page = ComparePage(response)
196 198 compare_page.contains_change_summary(1, 2, 0)
197 199 compare_page.contains_commits([commit1, commit2])
198 200 compare_page.contains_file_links_and_anchors([
199 201 ('file1', 'a_c--826e8142e6ba'),
200 202 ])
201 203
202 204 # Swap is removed when comparing branches since it's a PR feature and
203 205 # it is then a preview mode
204 206 compare_page.swap_is_hidden()
205 207 compare_page.target_source_are_disabled()
206 208
207 209 @pytest.mark.xfail_backends("svn", "git")
208 210 def test_compare_of_unrelated_forks(self, backend):
209 211 # TODO: johbo: Fails for git due to some other issue it seems
210 212 orig = backend.create_repo(number_of_commits=1)
211 213 fork = backend.create_repo(number_of_commits=1)
212 214
213 215 response = self.app.get(
214 216 url('compare_url',
215 217 repo_name=orig.repo_name,
216 218 action="compare",
217 219 source_ref_type="rev",
218 220 source_ref="tip",
219 221 target_ref_type="rev",
220 222 target_ref="tip",
221 223 merge='1',
222 224 target_repo=fork.repo_name),
223 225 status=400)
224 226
225 227 response.mustcontain("Repositories unrelated.")
226 228
227 229 @pytest.mark.xfail_backends("svn", "git")
228 230 def test_compare_cherry_pick_commits_from_bottom(self, backend):
229 231
230 232 # repo1:
231 233 # commit0:
232 234 # commit1:
233 235 # repo1-fork- in which we will cherry pick bottom commits
234 236 # commit0:
235 237 # commit1:
236 238 # commit2: x
237 239 # commit3: x
238 240 # commit4: x
239 241 # commit5:
240 242 # make repo1, and commit1+commit2
241 243
242 244 repo1 = backend.create_repo()
243 245
244 246 # commit something !
245 247 commit0 = _commit_change(
246 248 repo1.repo_name, filename='file1', content='line1\n',
247 249 message='commit1', vcs_type=backend.alias, parent=None,
248 250 newfile=True)
249 251 commit1 = _commit_change(
250 252 repo1.repo_name, filename='file1', content='line1\nline2\n',
251 253 message='commit2', vcs_type=backend.alias, parent=commit0)
252 254
253 255 # fork this repo
254 256 repo2 = backend.create_fork()
255 257
256 258 # now make commit3-6
257 259 commit2 = _commit_change(
258 260 repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
259 261 message='commit3', vcs_type=backend.alias, parent=commit1)
260 262 commit3 = _commit_change(
261 263 repo1.repo_name, filename='file1',
262 264 content='line1\nline2\nline3\nline4\n', message='commit4',
263 265 vcs_type=backend.alias, parent=commit2)
264 266 commit4 = _commit_change(
265 267 repo1.repo_name, filename='file1',
266 268 content='line1\nline2\nline3\nline4\nline5\n', message='commit5',
267 269 vcs_type=backend.alias, parent=commit3)
268 270 _commit_change( # commit 5
269 271 repo1.repo_name, filename='file1',
270 272 content='line1\nline2\nline3\nline4\nline5\nline6\n',
271 273 message='commit6', vcs_type=backend.alias, parent=commit4)
272 274
273 275 response = self.app.get(
274 276 url('compare_url',
275 277 repo_name=repo2.repo_name,
276 278 source_ref_type="rev",
277 279 # parent of commit2, in target repo2
278 280 source_ref=commit1.short_id,
279 281 target_repo=repo1.repo_name,
280 282 target_ref_type="rev",
281 283 target_ref=commit4.short_id,
282 284 merge='1',))
283 285 response.mustcontain('%s@%s' % (repo2.repo_name, commit1.short_id))
284 286 response.mustcontain('%s@%s' % (repo1.repo_name, commit4.short_id))
285 287
286 288 # files
287 289 compare_page = ComparePage(response)
288 290 compare_page.contains_change_summary(1, 3, 0)
289 291 compare_page.contains_commits([commit2, commit3, commit4])
290 292 compare_page.contains_file_links_and_anchors([
291 293 ('file1', 'a_c--826e8142e6ba'),
292 294 ])
293 295
294 296 @pytest.mark.xfail_backends("svn", "git")
295 297 def test_compare_cherry_pick_commits_from_top(self, backend):
296 298 # repo1:
297 299 # commit0:
298 300 # commit1:
299 301 # repo1-fork- in which we will cherry pick bottom commits
300 302 # commit0:
301 303 # commit1:
302 304 # commit2:
303 305 # commit3: x
304 306 # commit4: x
305 307 # commit5: x
306 308
307 309 # make repo1, and commit1+commit2
308 310 repo1 = backend.create_repo()
309 311
310 312 # commit something !
311 313 commit0 = _commit_change(
312 314 repo1.repo_name, filename='file1', content='line1\n',
313 315 message='commit1', vcs_type=backend.alias, parent=None,
314 316 newfile=True)
315 317 commit1 = _commit_change(
316 318 repo1.repo_name, filename='file1', content='line1\nline2\n',
317 319 message='commit2', vcs_type=backend.alias, parent=commit0)
318 320
319 321 # fork this repo
320 322 backend.create_fork()
321 323
322 324 # now make commit3-6
323 325 commit2 = _commit_change(
324 326 repo1.repo_name, filename='file1', content='line1\nline2\nline3\n',
325 327 message='commit3', vcs_type=backend.alias, parent=commit1)
326 328 commit3 = _commit_change(
327 329 repo1.repo_name, filename='file1',
328 330 content='line1\nline2\nline3\nline4\n', message='commit4',
329 331 vcs_type=backend.alias, parent=commit2)
330 332 commit4 = _commit_change(
331 333 repo1.repo_name, filename='file1',
332 334 content='line1\nline2\nline3\nline4\nline5\n', message='commit5',
333 335 vcs_type=backend.alias, parent=commit3)
334 336 commit5 = _commit_change(
335 337 repo1.repo_name, filename='file1',
336 338 content='line1\nline2\nline3\nline4\nline5\nline6\n',
337 339 message='commit6', vcs_type=backend.alias, parent=commit4)
338 340
339 341 response = self.app.get(
340 342 url('compare_url',
341 343 repo_name=repo1.repo_name,
342 344 source_ref_type="rev",
343 345 # parent of commit3, not in source repo2
344 346 source_ref=commit2.short_id,
345 347 target_ref_type="rev",
346 348 target_ref=commit5.short_id,
347 349 merge='1',))
348 350
349 351 response.mustcontain('%s@%s' % (repo1.repo_name, commit2.short_id))
350 352 response.mustcontain('%s@%s' % (repo1.repo_name, commit5.short_id))
351 353
352 354 compare_page = ComparePage(response)
353 355 compare_page.contains_change_summary(1, 3, 0)
354 356 compare_page.contains_commits([commit3, commit4, commit5])
355 357
356 358 # files
357 359 compare_page.contains_file_links_and_anchors([
358 360 ('file1', 'a_c--826e8142e6ba'),
359 361 ])
360 362
361 363 @pytest.mark.xfail_backends("svn")
362 364 def test_compare_remote_branches(self, backend):
363 365 repo1 = backend.repo
364 366 repo2 = backend.create_fork()
365 367
366 368 commit_id1 = repo1.get_commit(commit_idx=3).raw_id
367 369 commit_id2 = repo1.get_commit(commit_idx=6).raw_id
368 370
369 371 response = self.app.get(
370 372 url('compare_url',
371 373 repo_name=repo1.repo_name,
372 374 source_ref_type="rev",
373 375 source_ref=commit_id1,
374 376 target_ref_type="rev",
375 377 target_ref=commit_id2,
376 378 target_repo=repo2.repo_name,
377 379 merge='1',))
378 380
379 381 response.mustcontain('%s@%s' % (repo1.repo_name, commit_id1))
380 382 response.mustcontain('%s@%s' % (repo2.repo_name, commit_id2))
381 383
382 384 compare_page = ComparePage(response)
383 385
384 386 # outgoing commits between those commits
385 387 compare_page.contains_commits(
386 388 [repo2.get_commit(commit_idx=x) for x in [4, 5, 6]])
387 389
388 390 # files
389 391 compare_page.contains_file_links_and_anchors([
390 392 ('vcs/backends/hg.py', 'a_c--9c390eb52cd6'),
391 393 ('vcs/backends/__init__.py', 'a_c--41b41c1f2796'),
392 394 ('vcs/backends/base.py', 'a_c--2f574d260608'),
393 395 ])
394 396
395 397 @pytest.mark.xfail_backends("svn")
396 398 def test_source_repo_new_commits_after_forking_simple_diff(self, backend):
397 399 repo1 = backend.create_repo()
398 400 r1_name = repo1.repo_name
399 401
400 402 commit0 = _commit_change(
401 403 repo=r1_name, filename='file1',
402 404 content='line1', message='commit1', vcs_type=backend.alias,
403 405 newfile=True)
404 406 assert repo1.scm_instance().commit_ids == [commit0.raw_id]
405 407
406 408 # fork the repo1
407 409 repo2 = backend.create_fork()
408 410 assert repo2.scm_instance().commit_ids == [commit0.raw_id]
409 411
410 412 self.r2_id = repo2.repo_id
411 413 r2_name = repo2.repo_name
412 414
413 415 commit1 = _commit_change(
414 416 repo=r2_name, filename='file1-fork',
415 417 content='file1-line1-from-fork', message='commit1-fork',
416 418 vcs_type=backend.alias, parent=repo2.scm_instance()[-1],
417 419 newfile=True)
418 420
419 421 commit2 = _commit_change(
420 422 repo=r2_name, filename='file2-fork',
421 423 content='file2-line1-from-fork', message='commit2-fork',
422 424 vcs_type=backend.alias, parent=commit1,
423 425 newfile=True)
424 426
425 427 _commit_change( # commit 3
426 428 repo=r2_name, filename='file3-fork',
427 429 content='file3-line1-from-fork', message='commit3-fork',
428 430 vcs_type=backend.alias, parent=commit2, newfile=True)
429 431
430 432 # compare !
431 433 commit_id1 = repo1.scm_instance().DEFAULT_BRANCH_NAME
432 434 commit_id2 = repo2.scm_instance().DEFAULT_BRANCH_NAME
433 435
434 436 response = self.app.get(
435 437 url('compare_url',
436 438 repo_name=r2_name,
437 439 source_ref_type="branch",
438 440 source_ref=commit_id1,
439 441 target_ref_type="branch",
440 442 target_ref=commit_id2,
441 443 target_repo=r1_name,
442 444 merge='1',))
443 445
444 446 response.mustcontain('%s@%s' % (r2_name, commit_id1))
445 447 response.mustcontain('%s@%s' % (r1_name, commit_id2))
446 448 response.mustcontain('No files')
447 449 response.mustcontain('No Commits')
448 450
449 451 commit0 = _commit_change(
450 452 repo=r1_name, filename='file2',
451 453 content='line1-added-after-fork', message='commit2-parent',
452 454 vcs_type=backend.alias, parent=None, newfile=True)
453 455
454 456 # compare !
455 457 response = self.app.get(
456 458 url('compare_url',
457 459 repo_name=r2_name,
458 460 source_ref_type="branch",
459 461 source_ref=commit_id1,
460 462 target_ref_type="branch",
461 463 target_ref=commit_id2,
462 464 target_repo=r1_name,
463 465 merge='1',))
464 466
465 467 response.mustcontain('%s@%s' % (r2_name, commit_id1))
466 468 response.mustcontain('%s@%s' % (r1_name, commit_id2))
467 469
468 470 response.mustcontain("""commit2-parent""")
469 471 response.mustcontain("""line1-added-after-fork""")
470 472 compare_page = ComparePage(response)
471 473 compare_page.contains_change_summary(1, 1, 0)
472 474
473 475 @pytest.mark.xfail_backends("svn")
474 476 def test_compare_commits(self, backend):
475 477 commit0 = backend.repo.get_commit(commit_idx=0)
476 478 commit1 = backend.repo.get_commit(commit_idx=1)
477 479
478 480 response = self.app.get(
479 481 url('compare_url',
480 482 repo_name=backend.repo_name,
481 483 source_ref_type="rev",
482 484 source_ref=commit0.raw_id,
483 485 target_ref_type="rev",
484 486 target_ref=commit1.raw_id,
485 487 merge='1',),
486 488 extra_environ={'HTTP_X_PARTIAL_XHR': '1'},)
487 489
488 490 # outgoing commits between those commits
489 491 compare_page = ComparePage(response)
490 492 compare_page.contains_commits(commits=[commit1], ancestors=[commit0])
491 493
492 494 def test_errors_when_comparing_unknown_repo(self, backend):
493 495 repo = backend.repo
494 496 badrepo = 'badrepo'
495 497
496 498 response = self.app.get(
497 499 url('compare_url',
498 500 repo_name=repo.repo_name,
499 501 source_ref_type="rev",
500 502 source_ref='tip',
501 503 target_ref_type="rev",
502 504 target_ref='tip',
503 505 target_repo=badrepo,
504 506 merge='1',),
505 507 status=302)
506 508 redirected = response.follow()
507 509 redirected.mustcontain('Could not find the other repo: %s' % badrepo)
508 510
509 511 def test_compare_not_in_preview_mode(self, backend_stub):
510 512 commit0 = backend_stub.repo.get_commit(commit_idx=0)
511 513 commit1 = backend_stub.repo.get_commit(commit_idx=1)
512 514
513 515 response = self.app.get(url('compare_url',
514 516 repo_name=backend_stub.repo_name,
515 517 source_ref_type="rev",
516 518 source_ref=commit0.raw_id,
517 519 target_ref_type="rev",
518 520 target_ref=commit1.raw_id,
519 521 ),)
520 522
521 523 # outgoing commits between those commits
522 524 compare_page = ComparePage(response)
523 525 compare_page.swap_is_visible()
524 526 compare_page.target_source_are_enabled()
525 527
526 528 def test_compare_of_fork_with_largefiles(self, backend_hg, settings_util):
527 529 orig = backend_hg.create_repo(number_of_commits=1)
528 530 fork = backend_hg.create_fork()
529 531
530 532 settings_util.create_repo_rhodecode_ui(
531 533 orig, 'extensions', value='', key='largefiles', active=False)
532 534 settings_util.create_repo_rhodecode_ui(
533 535 fork, 'extensions', value='', key='largefiles', active=True)
534 536
535 537 compare_module = ('rhodecode.lib.vcs.backends.hg.repository.'
536 538 'MercurialRepository.compare')
537 539 with mock.patch(compare_module) as compare_mock:
538 540 compare_mock.side_effect = RepositoryRequirementError()
539 541
540 542 response = self.app.get(
541 543 url('compare_url',
542 544 repo_name=orig.repo_name,
543 545 action="compare",
544 546 source_ref_type="rev",
545 547 source_ref="tip",
546 548 target_ref_type="rev",
547 549 target_ref="tip",
548 550 merge='1',
549 551 target_repo=fork.repo_name),
550 552 status=302)
551 553
552 554 assert_session_flash(
553 555 response,
554 556 'Could not compare repos with different large file settings')
555 557
556 558
557 559 @pytest.mark.usefixtures("autologin_user")
558 560 class TestCompareControllerSvn:
559 561
560 562 def test_supports_references_with_path(self, app, backend_svn):
561 563 repo = backend_svn['svn-simple-layout']
562 564 commit_id = repo.get_commit(commit_idx=-1).raw_id
563 565 response = app.get(
564 566 url('compare_url',
565 567 repo_name=repo.repo_name,
566 568 source_ref_type="tag",
567 569 source_ref="%s@%s" % ('tags/v0.1', commit_id),
568 570 target_ref_type="tag",
569 571 target_ref="%s@%s" % ('tags/v0.2', commit_id),
570 572 merge='1',),
571 573 status=200)
572 574
573 575 # Expecting no commits, since both paths are at the same revision
574 576 response.mustcontain('No Commits')
575 577
576 578 # Should find only one file changed when comparing those two tags
577 579 response.mustcontain('example.py')
578 580 compare_page = ComparePage(response)
579 581 compare_page.contains_change_summary(1, 5, 1)
580 582
581 583 def test_shows_commits_if_different_ids(self, app, backend_svn):
582 584 repo = backend_svn['svn-simple-layout']
583 585 source_id = repo.get_commit(commit_idx=-6).raw_id
584 586 target_id = repo.get_commit(commit_idx=-1).raw_id
585 587 response = app.get(
586 588 url('compare_url',
587 589 repo_name=repo.repo_name,
588 590 source_ref_type="tag",
589 591 source_ref="%s@%s" % ('tags/v0.1', source_id),
590 592 target_ref_type="tag",
591 593 target_ref="%s@%s" % ('tags/v0.2', target_id),
592 594 merge='1',),
593 595 status=200)
594 596
595 597 # It should show commits
596 598 assert 'No Commits' not in response.body
597 599
598 600 # Should find only one file changed when comparing those two tags
599 601 response.mustcontain('example.py')
600 602 compare_page = ComparePage(response)
601 603 compare_page.contains_change_summary(1, 5, 1)
602 604
603 605
604 606 class ComparePage(AssertResponse):
605 607 """
606 608 Abstracts the page template from the tests
607 609 """
608 610
609 611 def contains_file_links_and_anchors(self, files):
610 612 for filename, file_id in files:
611 613 self.contains_one_link(filename, '#' + file_id)
612 614 self.contains_one_anchor(file_id)
613 615
614 616 def contains_change_summary(self, files_changed, inserted, deleted):
615 617 template = (
616 618 "{files_changed} file{plural} changed: "
617 619 "{inserted} inserted, {deleted} deleted")
618 620 self.response.mustcontain(template.format(
619 621 files_changed=files_changed,
620 622 plural="s" if files_changed > 1 else "",
621 623 inserted=inserted,
622 624 deleted=deleted))
623 625
624 626 def contains_commits(self, commits, ancestors=None):
625 627 response = self.response
626 628
627 629 for commit in commits:
628 630 # Expecting to see the commit message in an element which
629 631 # has the ID "c-{commit.raw_id}"
630 632 self.element_contains('#c-' + commit.raw_id, commit.message)
631 633 self.contains_one_link(
632 634 'r%s:%s' % (commit.idx, commit.short_id),
633 635 self._commit_url(commit))
634 636 if ancestors:
635 637 response.mustcontain('Ancestor')
636 638 for ancestor in ancestors:
637 639 self.contains_one_link(
638 640 ancestor.short_id, self._commit_url(ancestor))
639 641
640 642 def _commit_url(self, commit):
641 643 return '/%s/changeset/%s' % (commit.repository.name, commit.raw_id)
642 644
643 645 def swap_is_hidden(self):
644 646 assert '<a id="btn-swap"' not in self.response.text
645 647
646 648 def swap_is_visible(self):
647 649 assert '<a id="btn-swap"' in self.response.text
648 650
649 651 def target_source_are_disabled(self):
650 652 response = self.response
651 653 response.mustcontain("var enable_fields = false;")
652 654 response.mustcontain('.select2("enable", enable_fields)')
653 655
654 656 def target_source_are_enabled(self):
655 657 response = self.response
656 658 response.mustcontain("var enable_fields = true;")
657 659
658 660
659 661 def _commit_change(
660 662 repo, filename, content, message, vcs_type, parent=None,
661 663 newfile=False):
662 664 repo = Repository.get_by_repo_name(repo)
663 665 _commit = parent
664 666 if not parent:
665 667 _commit = EmptyCommit(alias=vcs_type)
666 668
667 669 if newfile:
668 670 nodes = {
669 671 filename: {
670 672 'content': content
671 673 }
672 674 }
673 675 commit = ScmModel().create_nodes(
674 676 user=TEST_USER_ADMIN_LOGIN, repo=repo,
675 677 message=message,
676 678 nodes=nodes,
677 679 parent_commit=_commit,
678 680 author=TEST_USER_ADMIN_LOGIN,
679 681 )
680 682 else:
681 683 commit = ScmModel().commit_change(
682 684 repo=repo.scm_instance(), repo_name=repo.repo_name,
683 685 commit=parent, user=TEST_USER_ADMIN_LOGIN,
684 686 author=TEST_USER_ADMIN_LOGIN,
685 687 message=message,
686 688 content=content,
687 689 f_path=filename
688 690 )
689 691 return commit
General Comments 0
You need to be logged in to leave comments. Login now