~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Andrew Bennetts
  • Date: 2008-06-18 07:46:41 UTC
  • mto: (3452.2.9 inter-remote-pack)
  • mto: This revision was merged to the branch mainline in revision 3511.
  • Revision ID: andrew.bennetts@canonical.com-20080618074641-gletfspa4l47yq6q
Fix test failures.

Show diffs side-by-side

added added

removed removed

Lines of Context:
397
397
            request.execute(''))
398
398
 
399
399
 
400
 
class SetLastRevisionCommonTests(object):
401
 
    """Mixin class for tests common to Branch.set_last_revision* variants."""
402
 
 
403
 
    request_class = None
404
 
 
405
 
    def test_not_present_revision_id(self):
406
 
        backing = self.get_transport()
407
 
        request = self.request_class(backing)
408
 
        b = self.make_branch('.')
409
 
        branch_token = b.lock_write()
410
 
        repo_token = b.repository.lock_write()
411
 
        b.repository.unlock()
412
 
        try:
413
 
            revision_id = 'non-existent revision'
414
 
            self.assertEqual(
415
 
                SmartServerResponse(('NoSuchRevision', revision_id)),
416
 
                request.execute(
417
 
                    '', branch_token, repo_token,
418
 
                    revision_id))
419
 
        finally:
420
 
            b.unlock()
421
 
 
422
 
 
423
400
class TestSmartServerBranchRequestSetLastRevision(
424
 
    tests.TestCaseWithMemoryTransport, SetLastRevisionCommonTests):
 
401
    tests.TestCaseWithMemoryTransport):
425
402
 
426
403
    request_class = smart.branch.SmartServerBranchRequestSetLastRevision
427
404
 
 
405
    def test_not_present_revision_id(self):
 
406
        backing = self.get_transport()
 
407
        request = self.request_class(backing)
 
408
        b = self.make_branch('.')
 
409
        branch_token = b.lock_write()
 
410
        repo_token = b.repository.lock_write()
 
411
        b.repository.unlock()
 
412
        try:
 
413
            revision_id = 'non-existent revision'
 
414
            self.assertEqual(
 
415
                SmartServerResponse(('NoSuchRevision', revision_id)),
 
416
                request.execute(
 
417
                    '', branch_token, repo_token,
 
418
                    revision_id))
 
419
        finally:
 
420
            b.unlock()
 
421
 
428
422
    def test_revision_id_present2(self):
429
423
        backing = self.get_transport()
430
424
        request = self.request_class(backing)
475
469
 
476
470
 
477
471
class TestSmartServerBranchRequestSetLastRevisionDescendant(
478
 
    tests.TestCaseWithMemoryTransport, SetLastRevisionCommonTests):
 
472
    tests.TestCaseWithMemoryTransport):
479
473
 
480
474
    request_class = \
481
475
        smart.branch.SmartServerBranchRequestSetLastRevisionDescendant
488
482
        repo_token = b.repository.lock_write()
489
483
        b.repository.unlock()
490
484
        try:
491
 
            self.assertEqual(SmartServerResponse(('ok',)),
 
485
            self.assertEqual(SuccessfulSmartServerResponse(('ok', 0, 'null:')),
492
486
                request.execute(
493
 
                    '', branch_token, repo_token,
494
 
                    'null:'))
 
487
                    '', branch_token, repo_token, 'null:', 0, 0))
495
488
        finally:
496
489
            b.unlock()
497
490
 
498
 
    def test_empty(self):
 
491
    def test_not_present_revision_id(self):
499
492
        backing = self.get_transport()
500
493
        request = self.request_class(backing)
501
494
        b = self.make_branch('.')
503
496
        repo_token = b.repository.lock_write()
504
497
        b.repository.unlock()
505
498
        try:
506
 
            self.assertEqual(SmartServerResponse(('ok', 0)),
 
499
            revision_id = 'non-existent revision'
 
500
            self.assertEqual(
 
501
                SmartServerResponse(('NoSuchRevision', revision_id)),
507
502
                request.execute(
508
 
                    '', branch_token, repo_token,
509
 
                    'null:'))
 
503
                    '', branch_token, repo_token, revision_id, 0, 0))
510
504
        finally:
511
505
            b.unlock()
512
 
 
513
506
    def test_revision_id_present2(self):
514
507
        backing = self.get_transport()
515
508
        request = self.request_class(backing)
526
519
        tree.branch.repository.unlock()
527
520
        try:
528
521
            self.assertEqual(
529
 
                SuccessfulSmartServerResponse(('ok', 1)),
 
522
                SuccessfulSmartServerResponse(('ok', 1, rev_id_utf8)),
530
523
                request.execute(
531
 
                    '', branch_token, repo_token,
532
 
                    rev_id_utf8))
 
524
                    '', branch_token, repo_token, rev_id_utf8, 0, 0))
533
525
            self.assertEqual([rev_id_utf8], tree.branch.revision_history())
534
526
        finally:
535
527
            tree.branch.unlock()
536
528
 
537
 
    def test_revision_id_previous(self):
538
 
        backing = self.get_transport()
539
 
        request = self.request_class(backing)
540
 
        tree = self.make_branch_and_memory_tree('.')
541
 
        tree.lock_write()
542
 
        tree.add('')
543
 
        rev_id_utf8 = u'\xc8'.encode('utf-8')
544
 
        r1 = tree.commit('1st commit', rev_id=rev_id_utf8)
545
 
        r2 = tree.commit('2nd commit', rev_id='second-rev')
546
 
        tree.unlock()
547
 
        branch_token = tree.branch.lock_write()
548
 
        repo_token = tree.branch.repository.lock_write()
549
 
        tree.branch.repository.unlock()
550
 
        try:
551
 
            self.assertEqual(
552
 
                FailedSmartServerResponse(('NotDescendant',)),
553
 
                request.execute(
554
 
                    '', branch_token, repo_token,
555
 
                    rev_id_utf8))
556
 
            self.assertEqual('second-rev', tree.branch.last_revision())
557
 
        finally:
558
 
            tree.branch.unlock()
559
 
 
560
529
    def test_branch_diverged(self):
561
530
        backing = self.get_transport()
562
531
        request = self.request_class(backing)
578
547
        tree.branch.repository.unlock()
579
548
        try:
580
549
            self.assertEqual(
581
 
                FailedSmartServerResponse(('NotDescendant',)),
 
550
                FailedSmartServerResponse(('Diverged',)),
582
551
                request.execute(
583
 
                    '', branch_token, repo_token,
584
 
                    'child-1'))
 
552
                    '', branch_token, repo_token, 'child-1', 0, 0))
585
553
            self.assertEqual('child-2', tree.branch.last_revision())
586
554
        finally:
587
555
            tree.branch.unlock()