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