~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Robert Collins
  • Date: 2008-09-19 06:53:41 UTC
  • mto: (3696.5.1 commit-updates)
  • mto: This revision was merged to the branch mainline in revision 3741.
  • Revision ID: robertc@robertcollins.net-20080919065341-5t5w1p2gi926nfia
First cut - make it work - at updating the tree stat cache during commit.

Show diffs side-by-side

added added

removed removed

Lines of Context:
427
427
        return OldSmartClient()
428
428
 
429
429
 
430
 
class TestBranchLastRevisionInfo(tests.TestCase):
 
430
class RemoteBranchTestCase(tests.TestCase):
 
431
 
 
432
    def make_remote_branch(self, transport, client):
 
433
        """Make a RemoteBranch using 'client' as its _SmartClient.
 
434
        
 
435
        A RemoteBzrDir and RemoteRepository will also be created to fill out
 
436
        the RemoteBranch, albeit with stub values for some of their attributes.
 
437
        """
 
438
        # we do not want bzrdir to make any remote calls, so use False as its
 
439
        # _client.  If it tries to make a remote call, this will fail
 
440
        # immediately.
 
441
        bzrdir = RemoteBzrDir(transport, _client=False)
 
442
        repo = RemoteRepository(bzrdir, None, _client=client)
 
443
        return RemoteBranch(bzrdir, repo, _client=client)
 
444
 
 
445
 
 
446
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
431
447
 
432
448
    def test_empty_branch(self):
433
449
        # in an empty branch we decode the response properly
436
452
        client.add_success_response('ok', '0', 'null:')
437
453
        transport.mkdir('quack')
438
454
        transport = transport.clone('quack')
439
 
        # we do not want bzrdir to make any remote calls
440
 
        bzrdir = RemoteBzrDir(transport, _client=False)
441
 
        branch = RemoteBranch(bzrdir, None, _client=client)
 
455
        branch = self.make_remote_branch(transport, client)
442
456
        result = branch.last_revision_info()
443
457
 
444
458
        self.assertEqual(
454
468
        client.add_success_response('ok', '2', revid)
455
469
        transport.mkdir('kwaak')
456
470
        transport = transport.clone('kwaak')
457
 
        # we do not want bzrdir to make any remote calls
458
 
        bzrdir = RemoteBzrDir(transport, _client=False)
459
 
        branch = RemoteBranch(bzrdir, None, _client=client)
 
471
        branch = self.make_remote_branch(transport, client)
460
472
        result = branch.last_revision_info()
461
473
 
462
474
        self.assertEqual(
465
477
        self.assertEqual((2, revid), result)
466
478
 
467
479
 
468
 
class TestBranchSetLastRevision(tests.TestCase):
 
480
class TestBranchSetLastRevision(RemoteBranchTestCase):
469
481
 
470
482
    def test_set_empty(self):
471
483
        # set_revision_history([]) is translated to calling
481
493
        client.add_success_response('ok')
482
494
        # unlock
483
495
        client.add_success_response('ok')
484
 
        bzrdir = RemoteBzrDir(transport, _client=False)
485
 
        branch = RemoteBranch(bzrdir, None, _client=client)
486
 
        # This is a hack to work around the problem that RemoteBranch currently
487
 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
488
 
        branch._ensure_real = lambda: None
 
496
        branch = self.make_remote_branch(transport, client)
489
497
        branch.lock_write()
490
498
        client._calls = []
491
499
        result = branch.set_revision_history([])
510
518
        client.add_success_response('ok')
511
519
        # unlock
512
520
        client.add_success_response('ok')
513
 
        bzrdir = RemoteBzrDir(transport, _client=False)
514
 
        branch = RemoteBranch(bzrdir, None, _client=client)
515
 
        # This is a hack to work around the problem that RemoteBranch currently
516
 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
517
 
        branch._ensure_real = lambda: None
 
521
        branch = self.make_remote_branch(transport, client)
518
522
        # Lock the branch, reset the record of remote calls.
519
523
        branch.lock_write()
520
524
        client._calls = []
540
544
        # unlock
541
545
        client.add_success_response('ok')
542
546
 
543
 
        bzrdir = RemoteBzrDir(transport, _client=False)
544
 
        repo = RemoteRepository(bzrdir, None, _client=client)
545
 
        branch = RemoteBranch(bzrdir, repo, _client=client)
546
 
        branch._ensure_real = lambda: None
 
547
        branch = self.make_remote_branch(transport, client)
547
548
        branch.lock_write()
548
549
        client._calls = []
549
550
 
568
569
        # unlock
569
570
        client.add_success_response('ok')
570
571
 
571
 
        bzrdir = RemoteBzrDir(transport, _client=False)
572
 
        repo = RemoteRepository(bzrdir, None, _client=client)
573
 
        branch = RemoteBranch(bzrdir, repo, _client=client)
574
 
        branch._ensure_real = lambda: None
 
572
        branch = self.make_remote_branch(transport, client)
575
573
        branch.lock_write()
576
574
        self.addCleanup(branch.unlock)
577
575
        client._calls = []
586
584
        self.assertEqual(rejection_msg_unicode, err.msg)
587
585
 
588
586
 
589
 
class TestBranchSetLastRevisionInfo(tests.TestCase):
 
587
class TestBranchSetLastRevisionInfo(RemoteBranchTestCase):
590
588
 
591
589
    def test_set_last_revision_info(self):
592
590
        # set_last_revision_info(num, 'rev-id') is translated to calling
602
600
        # unlock
603
601
        client.add_success_response('ok')
604
602
 
605
 
        bzrdir = RemoteBzrDir(transport, _client=False)
606
 
        branch = RemoteBranch(bzrdir, None, _client=client)
607
 
        # This is a hack to work around the problem that RemoteBranch currently
608
 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
609
 
        branch._ensure_real = lambda: None
 
603
        branch = self.make_remote_branch(transport, client)
610
604
        # Lock the branch, reset the record of remote calls.
611
605
        branch.lock_write()
612
606
        client._calls = []
631
625
        # unlock
632
626
        client.add_success_response('ok')
633
627
 
634
 
        bzrdir = RemoteBzrDir(transport, _client=False)
635
 
        repo = RemoteRepository(bzrdir, None, _client=client)
636
 
        branch = RemoteBranch(bzrdir, repo, _client=client)
637
 
        # This is a hack to work around the problem that RemoteBranch currently
638
 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
639
 
        branch._ensure_real = lambda: None
 
628
        branch = self.make_remote_branch(transport, client)
640
629
        # Lock the branch, reset the record of remote calls.
641
630
        branch.lock_write()
642
631
        client._calls = []
651
640
        branch._lock_count = 2
652
641
        branch._lock_token = 'branch token'
653
642
        branch._repo_lock_token = 'repo token'
 
643
        branch.repository._lock_mode = 'w'
 
644
        branch.repository._lock_count = 2
 
645
        branch.repository._lock_token = 'repo token'
654
646
 
655
647
    def test_backwards_compatibility(self):
656
648
        """If the server does not support the Branch.set_last_revision_info
669
661
        transport = transport.clone('branch')
670
662
        client = FakeClient(transport.base)
671
663
        client.add_unknown_method_response('Branch.set_last_revision_info')
672
 
        bzrdir = RemoteBzrDir(transport, _client=False)
673
 
        branch = RemoteBranch(bzrdir, None, _client=client)
 
664
        branch = self.make_remote_branch(transport, client)
674
665
        class StubRealBranch(object):
675
666
            def __init__(self):
676
667
                self.calls = []
707
698
        # unlock
708
699
        client.add_success_response('ok')
709
700
 
710
 
        bzrdir = RemoteBzrDir(transport, _client=False)
711
 
        repo = RemoteRepository(bzrdir, None, _client=client)
712
 
        branch = RemoteBranch(bzrdir, repo, _client=client)
713
 
        # This is a hack to work around the problem that RemoteBranch currently
714
 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
715
 
        branch._ensure_real = lambda: None
 
701
        branch = self.make_remote_branch(transport, client)
716
702
        # Lock the branch, reset the record of remote calls.
717
703
        branch.lock_write()
718
704
        client._calls = []
719
705
 
720
706
        err = self.assertRaises(
721
 
            errors.ErrorFromSmartServer,
 
707
            errors.UnknownErrorFromSmartServer,
722
708
            branch.set_last_revision_info, 123, 'revid')
723
709
        self.assertEqual(('UnexpectedError',), err.error_tuple)
724
710
        branch.unlock()
738
724
        # unlock
739
725
        client.add_success_response('ok')
740
726
 
741
 
        bzrdir = RemoteBzrDir(transport, _client=False)
742
 
        repo = RemoteRepository(bzrdir, None, _client=client)
743
 
        branch = RemoteBranch(bzrdir, repo, _client=client)
744
 
        # This is a hack to work around the problem that RemoteBranch currently
745
 
        # unnecessarily invokes _ensure_real upon a call to lock_write.
746
 
        branch._ensure_real = lambda: None
 
727
        branch = self.make_remote_branch(transport, client)
747
728
        # Lock the branch, reset the record of remote calls.
748
729
        branch.lock_write()
749
730
        self.addCleanup(branch.unlock)
783
764
        ##     client._calls)
784
765
 
785
766
 
786
 
class TestBranchLockWrite(tests.TestCase):
 
767
class TestBranchLockWrite(RemoteBranchTestCase):
787
768
 
788
769
    def test_lock_write_unlockable(self):
789
770
        transport = MemoryTransport()
791
772
        client.add_error_response('UnlockableTransport')
792
773
        transport.mkdir('quack')
793
774
        transport = transport.clone('quack')
794
 
        # we do not want bzrdir to make any remote calls
795
 
        bzrdir = RemoteBzrDir(transport, _client=False)
796
 
        repo = RemoteRepository(bzrdir, None, _client=client)
797
 
        branch = RemoteBranch(bzrdir, repo, _client=client)
 
775
        branch = self.make_remote_branch(transport, client)
798
776
        self.assertRaises(errors.UnlockableTransport, branch.lock_write)
799
777
        self.assertEqual(
800
778
            [('call', 'Branch.lock_write', ('quack/', '', ''))],
1102
1080
        transport_path = 'sinhala'
1103
1081
        repo, client = self.setup_fake_client_and_repository(transport_path)
1104
1082
        client.add_error_response('AnUnexpectedError')
1105
 
        e = self.assertRaises(errors.ErrorFromSmartServer,
 
1083
        e = self.assertRaises(errors.UnknownErrorFromSmartServer,
1106
1084
            self.applyDeprecated, one_four, repo.get_revision_graph, revid)
1107
1085
        self.assertEqual(('AnUnexpectedError',), e.error_tuple)
1108
1086
 
1372
1350
        error_tuple = ('An unknown error tuple',)
1373
1351
        server_error = errors.ErrorFromSmartServer(error_tuple)
1374
1352
        translated_error = self.translateErrorFromSmartServer(server_error)
1375
 
        self.assertEqual(server_error, translated_error)
 
1353
        expected_error = errors.UnknownErrorFromSmartServer(server_error)
 
1354
        self.assertEqual(expected_error, translated_error)
1376
1355
 
1377
1356
    def test_context_missing_a_key(self):
1378
1357
        """In case of a bug in the client, or perhaps an unexpected response