/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: Canonical.com Patch Queue Manager
  • Date: 2009-12-21 06:03:07 UTC
  • mfrom: (4665.7.3 serve-init)
  • Revision ID: pqm@pqm.ubuntu.com-20091221060307-uvja3vdy1o6dzzy0
(mbp) example debian init script

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
from cStringIO import StringIO
28
28
 
29
29
from bzrlib import (
 
30
    branch,
30
31
    bzrdir,
31
32
    config,
32
33
    errors,
36
37
    pack,
37
38
    remote,
38
39
    repository,
39
 
    smart,
40
40
    tests,
41
41
    treebuilder,
42
42
    urlutils,
61
61
    condition_isinstance,
62
62
    split_suite_by_condition,
63
63
    multiply_tests,
64
 
    KnownFailure,
65
64
    )
66
 
from bzrlib.transport import get_transport, http
 
65
from bzrlib.transport import get_transport
67
66
from bzrlib.transport.memory import MemoryTransport
68
67
from bzrlib.transport.remote import (
69
68
    RemoteTransport,
280
279
        self.expecting_body = True
281
280
        return result[1], FakeProtocol(result[2], self)
282
281
 
 
282
    def call_with_body_bytes(self, method, args, body):
 
283
        self._check_call(method, args)
 
284
        self._calls.append(('call_with_body_bytes', method, args, body))
 
285
        result = self._get_next_response()
 
286
        return result[1], FakeProtocol(result[2], self)
 
287
 
283
288
    def call_with_body_bytes_expecting_body(self, method, args, body):
284
289
        self._check_call(method, args)
285
290
        self._calls.append(('call_with_body_bytes_expecting_body', method,
468
473
        self.assertFinished(client)
469
474
 
470
475
 
 
476
class TestBzrDirOpen(TestRemote):
 
477
 
 
478
    def make_fake_client_and_transport(self, path='quack'):
 
479
        transport = MemoryTransport()
 
480
        transport.mkdir(path)
 
481
        transport = transport.clone(path)
 
482
        client = FakeClient(transport.base)
 
483
        return client, transport
 
484
 
 
485
    def test_absent(self):
 
486
        client, transport = self.make_fake_client_and_transport()
 
487
        client.add_expected_call(
 
488
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
 
489
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
 
490
                remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
 
491
        self.assertFinished(client)
 
492
 
 
493
    def test_present_without_workingtree(self):
 
494
        client, transport = self.make_fake_client_and_transport()
 
495
        client.add_expected_call(
 
496
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
 
497
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
498
            _client=client, _force_probe=True)
 
499
        self.assertIsInstance(bd, RemoteBzrDir)
 
500
        self.assertFalse(bd.has_workingtree())
 
501
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
 
502
        self.assertFinished(client)
 
503
 
 
504
    def test_present_with_workingtree(self):
 
505
        client, transport = self.make_fake_client_and_transport()
 
506
        client.add_expected_call(
 
507
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
 
508
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
509
            _client=client, _force_probe=True)
 
510
        self.assertIsInstance(bd, RemoteBzrDir)
 
511
        self.assertTrue(bd.has_workingtree())
 
512
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
 
513
        self.assertFinished(client)
 
514
 
 
515
    def test_backwards_compat(self):
 
516
        client, transport = self.make_fake_client_and_transport()
 
517
        client.add_expected_call(
 
518
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
 
519
        client.add_expected_call(
 
520
            'BzrDir.open', ('quack/',), 'success', ('yes',))
 
521
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
 
522
            _client=client, _force_probe=True)
 
523
        self.assertIsInstance(bd, RemoteBzrDir)
 
524
        self.assertFinished(client)
 
525
 
 
526
 
471
527
class TestBzrDirOpenBranch(TestRemote):
472
528
 
473
529
    def test_backwards_compat(self):
683
739
        # fallback all the way to the first version.
684
740
        reference_format = self.get_repo_format()
685
741
        network_name = reference_format.network_name()
686
 
        client = FakeClient('bzr://example.com/')
 
742
        server_url = 'bzr://example.com/'
 
743
        self.permit_url(server_url)
 
744
        client = FakeClient(server_url)
687
745
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
688
746
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
689
747
        client.add_success_response('ok', '', 'no', 'no')
695
753
            reference_format.get_format_string(), 'ok')
696
754
        # PackRepository wants to do a stat
697
755
        client.add_success_response('stat', '0', '65535')
698
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
756
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
699
757
            _client=client)
700
758
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
701
759
            _client=client)
715
773
        # fallback to find_repositoryV2
716
774
        reference_format = self.get_repo_format()
717
775
        network_name = reference_format.network_name()
718
 
        client = FakeClient('bzr://example.com/')
 
776
        server_url = 'bzr://example.com/'
 
777
        self.permit_url(server_url)
 
778
        client = FakeClient(server_url)
719
779
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
720
780
        client.add_success_response('ok', '', 'no', 'no', 'no')
721
781
        # A real repository instance will be created to determine the network
726
786
            reference_format.get_format_string(), 'ok')
727
787
        # PackRepository wants to do a stat
728
788
        client.add_success_response('stat', '0', '65535')
729
 
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
 
789
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
730
790
            _client=client)
731
791
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
732
792
            _client=client)
851
911
 
852
912
class RemoteBranchTestCase(RemoteBzrDirTestCase):
853
913
 
 
914
    def lock_remote_branch(self, branch):
 
915
        """Trick a RemoteBranch into thinking it is locked."""
 
916
        branch._lock_mode = 'w'
 
917
        branch._lock_count = 2
 
918
        branch._lock_token = 'branch token'
 
919
        branch._repo_lock_token = 'repo token'
 
920
        branch.repository._lock_mode = 'w'
 
921
        branch.repository._lock_count = 2
 
922
        branch.repository._lock_token = 'repo token'
 
923
 
854
924
    def make_remote_branch(self, transport, client):
855
925
        """Make a RemoteBranch using 'client' as its _SmartClient.
856
926
 
995
1065
        self.assertEqual({}, result)
996
1066
 
997
1067
 
 
1068
class TestBranchSetTagsBytes(RemoteBranchTestCase):
 
1069
 
 
1070
    def test_trivial(self):
 
1071
        transport = MemoryTransport()
 
1072
        client = FakeClient(transport.base)
 
1073
        client.add_expected_call(
 
1074
            'Branch.get_stacked_on_url', ('quack/',),
 
1075
            'error', ('NotStacked',))
 
1076
        client.add_expected_call(
 
1077
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1078
            'success', ('',))
 
1079
        transport.mkdir('quack')
 
1080
        transport = transport.clone('quack')
 
1081
        branch = self.make_remote_branch(transport, client)
 
1082
        self.lock_remote_branch(branch)
 
1083
        branch._set_tags_bytes('tags bytes')
 
1084
        self.assertFinished(client)
 
1085
        self.assertEqual('tags bytes', client._calls[-1][-1])
 
1086
 
 
1087
    def test_backwards_compatible(self):
 
1088
        transport = MemoryTransport()
 
1089
        client = FakeClient(transport.base)
 
1090
        client.add_expected_call(
 
1091
            'Branch.get_stacked_on_url', ('quack/',),
 
1092
            'error', ('NotStacked',))
 
1093
        client.add_expected_call(
 
1094
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
 
1095
            'unknown', ('Branch.set_tags_bytes',))
 
1096
        transport.mkdir('quack')
 
1097
        transport = transport.clone('quack')
 
1098
        branch = self.make_remote_branch(transport, client)
 
1099
        self.lock_remote_branch(branch)
 
1100
        class StubRealBranch(object):
 
1101
            def __init__(self):
 
1102
                self.calls = []
 
1103
            def _set_tags_bytes(self, bytes):
 
1104
                self.calls.append(('set_tags_bytes', bytes))
 
1105
        real_branch = StubRealBranch()
 
1106
        branch._real_branch = real_branch
 
1107
        branch._set_tags_bytes('tags bytes')
 
1108
        # Call a second time, to exercise the 'remote version already inferred'
 
1109
        # code path.
 
1110
        branch._set_tags_bytes('tags bytes')
 
1111
        self.assertFinished(client)
 
1112
        self.assertEqual(
 
1113
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
 
1114
 
 
1115
 
998
1116
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
999
1117
 
1000
1118
    def test_empty_branch(self):
1342
1460
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1343
1461
        branch.unlock()
1344
1462
 
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
1463
    def test_backwards_compatibility(self):
1356
1464
        """If the server does not support the Branch.set_last_revision_info
1357
1465
        verb (which is new in 1.4), then the client falls back to VFS methods.
1673
1781
        return repo, client
1674
1782
 
1675
1783
 
 
1784
def remoted_description(format):
 
1785
    return 'Remote: ' + format.get_format_description()
 
1786
 
 
1787
 
 
1788
class TestBranchFormat(tests.TestCase):
 
1789
 
 
1790
    def test_get_format_description(self):
 
1791
        remote_format = RemoteBranchFormat()
 
1792
        real_format = branch.BranchFormat.get_default_format()
 
1793
        remote_format._network_name = real_format.network_name()
 
1794
        self.assertEqual(remoted_description(real_format),
 
1795
            remote_format.get_format_description())
 
1796
 
 
1797
 
1676
1798
class TestRepositoryFormat(TestRemoteRepository):
1677
1799
 
1678
1800
    def test_fast_delta(self):
1685
1807
        false_format._network_name = false_name
1686
1808
        self.assertEqual(False, false_format.fast_deltas)
1687
1809
 
 
1810
    def test_get_format_description(self):
 
1811
        remote_repo_format = RemoteRepositoryFormat()
 
1812
        real_format = repository.RepositoryFormat.get_default_format()
 
1813
        remote_repo_format._network_name = real_format.network_name()
 
1814
        self.assertEqual(remoted_description(real_format),
 
1815
            remote_repo_format.get_format_description())
 
1816
 
1688
1817
 
1689
1818
class TestRepositoryGatherStats(TestRemoteRepository):
1690
1819
 
2092
2221
            repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2093
2222
        self.assertFinished(client)
2094
2223
 
 
2224
    def test_branch_fallback_locking(self):
 
2225
        """RemoteBranch.get_rev_id takes a read lock, and tries to call the
 
2226
        get_rev_id_for_revno verb.  If the verb is unknown the VFS fallback
 
2227
        will be invoked, which will fail if the repo is unlocked.
 
2228
        """
 
2229
        self.setup_smart_server_with_call_log()
 
2230
        tree = self.make_branch_and_memory_tree('.')
 
2231
        tree.lock_write()
 
2232
        rev1 = tree.commit('First')
 
2233
        rev2 = tree.commit('Second')
 
2234
        tree.unlock()
 
2235
        branch = tree.branch
 
2236
        self.assertFalse(branch.is_locked())
 
2237
        self.reset_smart_call_log()
 
2238
        verb = 'Repository.get_rev_id_for_revno'
 
2239
        self.disable_verb(verb)
 
2240
        self.assertEqual(rev1, branch.get_rev_id(1))
 
2241
        self.assertLength(1, [call for call in self.hpss_calls if
 
2242
                              call.call.method == verb])
 
2243
 
2095
2244
 
2096
2245
class TestRepositoryIsShared(TestRemoteRepository):
2097
2246
 
2325
2474
        class FakeRealRepository:
2326
2475
            def _get_sink(self):
2327
2476
                return fake_real_sink
 
2477
            def is_in_write_group(self):
 
2478
                return False
 
2479
            def refresh_data(self):
 
2480
                return True
2328
2481
        repo._real_repository = FakeRealRepository()
2329
2482
        sink = repo._get_sink()
2330
2483
        fmt = repository.RepositoryFormat.get_default_format()
2889
3042
            local_tree.commit('more local changes are better')
2890
3043
            branch = Branch.open(self.get_url('tree3'))
2891
3044
            branch.lock_read()
 
3045
            self.addCleanup(branch.unlock)
2892
3046
            return None, branch
2893
3047
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered',
2894
3048
            branch_factory=make_stacked_stacked)