/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Aaron Bentley
  • Date: 2009-09-29 04:40:55 UTC
  • mfrom: (4717 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4718.
  • Revision ID: aaron@aaronbentley.com-20090929044055-e9jtpmz6eyut711h
Merged bzr.dev into fix_get_mtime.

Show diffs side-by-side

added added

removed removed

Lines of Context:
280
280
        self.expecting_body = True
281
281
        return result[1], FakeProtocol(result[2], self)
282
282
 
 
283
    def call_with_body_bytes(self, method, args, body):
 
284
        self._check_call(method, args)
 
285
        self._calls.append(('call_with_body_bytes', method, args, body))
 
286
        result = self._get_next_response()
 
287
        return result[1], FakeProtocol(result[2], self)
 
288
 
283
289
    def call_with_body_bytes_expecting_body(self, method, args, body):
284
290
        self._check_call(method, args)
285
291
        self._calls.append(('call_with_body_bytes_expecting_body', method,
468
474
        self.assertFinished(client)
469
475
 
470
476
 
 
477
class TestBzrDirOpen(TestRemote):
 
478
 
 
479
    def make_fake_client_and_transport(self, path='quack'):
 
480
        transport = MemoryTransport()
 
481
        transport.mkdir(path)
 
482
        transport = transport.clone(path)
 
483
        client = FakeClient(transport.base)
 
484
        return client, transport
 
485
 
 
486
    def test_absent(self):
 
487
        client, transport = self.make_fake_client_and_transport()
 
488
        client.add_expected_call(
 
489
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
 
490
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
 
491
                remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
 
492
        self.assertFinished(client)
 
493
 
 
494
    def test_present_without_workingtree(self):
 
495
        client, transport = self.make_fake_client_and_transport()
 
496
        client.add_expected_call(
 
497
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
 
498
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
499
            _client=client, _force_probe=True)
 
500
        self.assertIsInstance(bd, RemoteBzrDir)
 
501
        self.assertFalse(bd.has_workingtree())
 
502
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
 
503
        self.assertFinished(client)
 
504
 
 
505
    def test_present_with_workingtree(self):
 
506
        client, transport = self.make_fake_client_and_transport()
 
507
        client.add_expected_call(
 
508
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
 
509
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
510
            _client=client, _force_probe=True)
 
511
        self.assertIsInstance(bd, RemoteBzrDir)
 
512
        self.assertTrue(bd.has_workingtree())
 
513
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
 
514
        self.assertFinished(client)
 
515
 
 
516
    def test_backwards_compat(self):
 
517
        client, transport = self.make_fake_client_and_transport()
 
518
        client.add_expected_call(
 
519
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
 
520
        client.add_expected_call(
 
521
            'BzrDir.open', ('quack/',), 'success', ('yes',))
 
522
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
523
            _client=client, _force_probe=True)
 
524
        self.assertIsInstance(bd, RemoteBzrDir)
 
525
        self.assertFinished(client)
 
526
 
 
527
 
471
528
class TestBzrDirOpenBranch(TestRemote):
472
529
 
473
530
    def test_backwards_compat(self):
683
740
        # fallback all the way to the first version.
684
741
        reference_format = self.get_repo_format()
685
742
        network_name = reference_format.network_name()
686
 
        client = FakeClient('bzr://example.com/')
 
743
        server_url = 'bzr://example.com/'
 
744
        self.permit_url(server_url)
 
745
        client = FakeClient(server_url)
687
746
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
688
747
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
689
748
        client.add_success_response('ok', '', 'no', 'no')
695
754
            reference_format.get_format_string(), 'ok')
696
755
        # PackRepository wants to do a stat
697
756
        client.add_success_response('stat', '0', '65535')
698
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
757
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
699
758
            _client=client)
700
759
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
701
760
            _client=client)
715
774
        # fallback to find_repositoryV2
716
775
        reference_format = self.get_repo_format()
717
776
        network_name = reference_format.network_name()
718
 
        client = FakeClient('bzr://example.com/')
 
777
        server_url = 'bzr://example.com/'
 
778
        self.permit_url(server_url)
 
779
        client = FakeClient(server_url)
719
780
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
720
781
        client.add_success_response('ok', '', 'no', 'no', 'no')
721
782
        # A real repository instance will be created to determine the network
726
787
            reference_format.get_format_string(), 'ok')
727
788
        # PackRepository wants to do a stat
728
789
        client.add_success_response('stat', '0', '65535')
729
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
790
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
730
791
            _client=client)
731
792
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
732
793
            _client=client)
851
912
 
852
913
class RemoteBranchTestCase(RemoteBzrDirTestCase):
853
914
 
 
915
    def lock_remote_branch(self, branch):
 
916
        """Trick a RemoteBranch into thinking it is locked."""
 
917
        branch._lock_mode = 'w'
 
918
        branch._lock_count = 2
 
919
        branch._lock_token = 'branch token'
 
920
        branch._repo_lock_token = 'repo token'
 
921
        branch.repository._lock_mode = 'w'
 
922
        branch.repository._lock_count = 2
 
923
        branch.repository._lock_token = 'repo token'
 
924
 
854
925
    def make_remote_branch(self, transport, client):
855
926
        """Make a RemoteBranch using 'client' as its _SmartClient.
856
927
 
995
1066
        self.assertEqual({}, result)
996
1067
 
997
1068
 
 
1069
class TestBranchSetTagsBytes(RemoteBranchTestCase):
 
1070
 
 
1071
    def test_trivial(self):
 
1072
        transport = MemoryTransport()
 
1073
        client = FakeClient(transport.base)
 
1074
        client.add_expected_call(
 
1075
            'Branch.get_stacked_on_url', ('quack/',),
 
1076
            'error', ('NotStacked',))
 
1077
        client.add_expected_call(
 
1078
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1079
            'success', ('',))
 
1080
        transport.mkdir('quack')
 
1081
        transport = transport.clone('quack')
 
1082
        branch = self.make_remote_branch(transport, client)
 
1083
        self.lock_remote_branch(branch)
 
1084
        branch._set_tags_bytes('tags bytes')
 
1085
        self.assertFinished(client)
 
1086
        self.assertEqual('tags bytes', client._calls[-1][-1])
 
1087
 
 
1088
    def test_backwards_compatible(self):
 
1089
        transport = MemoryTransport()
 
1090
        client = FakeClient(transport.base)
 
1091
        client.add_expected_call(
 
1092
            'Branch.get_stacked_on_url', ('quack/',),
 
1093
            'error', ('NotStacked',))
 
1094
        client.add_expected_call(
 
1095
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1096
            'unknown', ('Branch.set_tags_bytes',))
 
1097
        transport.mkdir('quack')
 
1098
        transport = transport.clone('quack')
 
1099
        branch = self.make_remote_branch(transport, client)
 
1100
        self.lock_remote_branch(branch)
 
1101
        class StubRealBranch(object):
 
1102
            def __init__(self):
 
1103
                self.calls = []
 
1104
            def _set_tags_bytes(self, bytes):
 
1105
                self.calls.append(('set_tags_bytes', bytes))
 
1106
        real_branch = StubRealBranch()
 
1107
        branch._real_branch = real_branch
 
1108
        branch._set_tags_bytes('tags bytes')
 
1109
        # Call a second time, to exercise the 'remote version already inferred'
 
1110
        # code path.
 
1111
        branch._set_tags_bytes('tags bytes')
 
1112
        self.assertFinished(client)
 
1113
        self.assertEqual(
 
1114
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
 
1115
 
 
1116
 
998
1117
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
999
1118
 
1000
1119
    def test_empty_branch(self):
1342
1461
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1343
1462
        branch.unlock()
1344
1463
 
1345
 
    def lock_remote_branch(self, branch):
1346
 
        """Trick a RemoteBranch into thinking it is locked."""
1347
 
        branch._lock_mode = 'w'
1348
 
        branch._lock_count = 2
1349
 
        branch._lock_token = 'branch token'
1350
 
        branch._repo_lock_token = 'repo token'
1351
 
        branch.repository._lock_mode = 'w'
1352
 
        branch.repository._lock_count = 2
1353
 
        branch.repository._lock_token = 'repo token'
1354
 
 
1355
1464
    def test_backwards_compatibility(self):
1356
1465
        """If the server does not support the Branch.set_last_revision_info
1357
1466
        verb (which is new in 1.4), then the client falls back to VFS methods.
1945
2054
    def test_allows_new_revisions(self):
1946
2055
        """get_parent_map's results can be updated by commit."""
1947
2056
        smart_server = server.SmartTCPServer_for_testing()
1948
 
        smart_server.setUp()
1949
 
        self.addCleanup(smart_server.tearDown)
 
2057
        self.start_server(smart_server)
1950
2058
        self.make_branch('branch')
1951
2059
        branch = Branch.open(smart_server.get_url() + '/branch')
1952
2060
        tree = branch.create_checkout('tree', lightweight=True)
2326
2434
        class FakeRealRepository:
2327
2435
            def _get_sink(self):
2328
2436
                return fake_real_sink
 
2437
            def is_in_write_group(self):
 
2438
                return False
 
2439
            def refresh_data(self):
 
2440
                return True
2329
2441
        repo._real_repository = FakeRealRepository()
2330
2442
        sink = repo._get_sink()
2331
2443
        fmt = repository.RepositoryFormat.get_default_format()
2668
2780
        expected_error = errors.ReadError(path)
2669
2781
        self.assertEqual(expected_error, translated_error)
2670
2782
 
 
2783
    def test_IncompatibleRepositories(self):
 
2784
        translated_error = self.translateTuple(('IncompatibleRepositories',
 
2785
            "repo1", "repo2", "details here"))
 
2786
        expected_error = errors.IncompatibleRepositories("repo1", "repo2",
 
2787
            "details here")
 
2788
        self.assertEqual(expected_error, translated_error)
 
2789
 
2671
2790
    def test_PermissionDenied_no_args(self):
2672
2791
        path = 'a path'
2673
2792
        translated_error = self.translateTuple(('PermissionDenied',), path=path)
2774
2893
        stacked_branch.set_stacked_on_url('../base')
2775
2894
        # start a server looking at this
2776
2895
        smart_server = server.SmartTCPServer_for_testing()
2777
 
        smart_server.setUp()
2778
 
        self.addCleanup(smart_server.tearDown)
 
2896
        self.start_server(smart_server)
2779
2897
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
2780
2898
        # can get its branch and repository
2781
2899
        remote_branch = remote_bzrdir.open_branch()
2936
3054
        # Create a smart server that publishes whatever the backing VFS server
2937
3055
        # does.
2938
3056
        self.smart_server = server.SmartTCPServer_for_testing()
2939
 
        self.smart_server.setUp(self.get_server())
2940
 
        self.addCleanup(self.smart_server.tearDown)
 
3057
        self.start_server(self.smart_server, self.get_server())
2941
3058
        # Log all HPSS calls into self.hpss_calls.
2942
3059
        _SmartClient.hooks.install_named_hook(
2943
3060
            'call', self.capture_hpss_call, None)