~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Martin Pool
  • Date: 2009-09-14 02:30:23 UTC
  • mto: This revision was merged to the branch mainline in revision 4693.
  • Revision ID: mbp@sourcefrog.net-20090914023023-ros0f3ndo04j3bww
Clearer docs about bzr help.  (Thanks to Naoki)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006, 2007, 2008, 2009 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
27
27
from cStringIO import StringIO
28
28
 
29
29
from bzrlib import (
30
 
    branch,
31
30
    bzrdir,
32
31
    config,
33
 
    controldir,
34
32
    errors,
35
33
    graph,
36
34
    inventory,
37
35
    inventory_delta,
 
36
    pack,
38
37
    remote,
39
38
    repository,
 
39
    smart,
40
40
    tests,
41
 
    transport,
42
41
    treebuilder,
 
42
    urlutils,
43
43
    versionedfile,
44
44
    )
45
45
from bzrlib.branch import Branch
46
 
from bzrlib.bzrdir import (
47
 
    BzrDir,
48
 
    BzrDirFormat,
49
 
    RemoteBzrProber,
50
 
    )
 
46
from bzrlib.bzrdir import BzrDir, BzrDirFormat
51
47
from bzrlib.remote import (
52
48
    RemoteBranch,
53
49
    RemoteBranchFormat,
54
50
    RemoteBzrDir,
 
51
    RemoteBzrDirFormat,
55
52
    RemoteRepository,
56
53
    RemoteRepositoryFormat,
57
54
    )
58
55
from bzrlib.repofmt import groupcompress_repo, pack_repo
59
56
from bzrlib.revision import NULL_REVISION
60
 
from bzrlib.smart import medium
 
57
from bzrlib.smart import server, medium
61
58
from bzrlib.smart.client import _SmartClient
62
59
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
63
60
from bzrlib.tests import (
64
61
    condition_isinstance,
65
62
    split_suite_by_condition,
66
63
    multiply_tests,
67
 
    test_server,
 
64
    KnownFailure,
68
65
    )
 
66
from bzrlib.transport import get_transport, http
69
67
from bzrlib.transport.memory import MemoryTransport
70
68
from bzrlib.transport.remote import (
71
69
    RemoteTransport,
78
76
        standard_tests, condition_isinstance(BasicRemoteObjectTests))
79
77
    smart_server_version_scenarios = [
80
78
        ('HPSS-v2',
81
 
         {'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
 
79
            {'transport_server': server.SmartTCPServer_for_testing_v2_only}),
82
80
        ('HPSS-v3',
83
 
         {'transport_server': test_server.SmartTCPServer_for_testing})]
 
81
            {'transport_server': server.SmartTCPServer_for_testing})]
84
82
    return multiply_tests(to_adapt, smart_server_version_scenarios, result)
85
83
 
86
84
 
91
89
        self.transport = self.get_transport()
92
90
        # make a branch that can be opened over the smart transport
93
91
        self.local_wt = BzrDir.create_standalone_workingtree('.')
94
 
        self.addCleanup(self.transport.disconnect)
 
92
 
 
93
    def tearDown(self):
 
94
        self.transport.disconnect()
 
95
        tests.TestCaseWithTransport.tearDown(self)
95
96
 
96
97
    def test_create_remote_bzrdir(self):
97
98
        b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
121
122
    def test_find_correct_format(self):
122
123
        """Should open a RemoteBzrDir over a RemoteTransport"""
123
124
        fmt = BzrDirFormat.find_format(self.transport)
124
 
        self.assertTrue(bzrdir.RemoteBzrProber
125
 
                        in controldir.ControlDirFormat._server_probers)
 
125
        self.assertTrue(RemoteBzrDirFormat
 
126
                        in BzrDirFormat._control_server_formats)
126
127
        self.assertIsInstance(fmt, remote.RemoteBzrDirFormat)
127
128
 
128
129
    def test_open_detected_smart_format(self):
134
135
        b = BzrDir.open_from_transport(self.transport).open_branch()
135
136
        self.assertStartsWith(str(b), 'RemoteBranch(')
136
137
 
137
 
    def test_remote_bzrdir_repr(self):
138
 
        b = BzrDir.open_from_transport(self.transport)
139
 
        self.assertStartsWith(str(b), 'RemoteBzrDir(')
140
 
 
141
138
    def test_remote_branch_format_supports_stacking(self):
142
139
        t = self.transport
143
140
        self.make_branch('unstackable', format='pack-0.92')
283
280
        self.expecting_body = True
284
281
        return result[1], FakeProtocol(result[2], self)
285
282
 
286
 
    def call_with_body_bytes(self, method, args, body):
287
 
        self._check_call(method, args)
288
 
        self._calls.append(('call_with_body_bytes', method, args, body))
289
 
        result = self._get_next_response()
290
 
        return result[1], FakeProtocol(result[2], self)
291
 
 
292
283
    def call_with_body_bytes_expecting_body(self, method, args, body):
293
284
        self._check_call(method, args)
294
285
        self._calls.append(('call_with_body_bytes_expecting_body', method,
358
349
        a given client_base and transport_base.
359
350
        """
360
351
        client_medium = medium.SmartClientMedium(client_base)
361
 
        t = transport.get_transport(transport_base)
362
 
        result = client_medium.remote_path_from_transport(t)
 
352
        transport = get_transport(transport_base)
 
353
        result = client_medium.remote_path_from_transport(transport)
363
354
        self.assertEqual(expected, result)
364
355
 
365
356
    def test_remote_path_from_transport(self):
376
367
        a given transport_base and relpath of that transport.  (Note that
377
368
        HttpTransportBase is a subclass of SmartClientMedium)
378
369
        """
379
 
        base_transport = transport.get_transport(transport_base)
 
370
        base_transport = get_transport(transport_base)
380
371
        client_medium = base_transport.get_smart_medium()
381
372
        cloned_transport = base_transport.clone(relpath)
382
373
        result = client_medium.remote_path_from_transport(cloned_transport)
417
408
        # Calling _remember_remote_is_before again with a lower value works.
418
409
        client_medium._remember_remote_is_before((1, 5))
419
410
        self.assertTrue(client_medium._is_remote_before((1, 5)))
420
 
        # If you call _remember_remote_is_before with a higher value it logs a
421
 
        # warning, and continues to remember the lower value.
422
 
        self.assertNotContainsRe(self.get_log(), '_remember_remote_is_before')
423
 
        client_medium._remember_remote_is_before((1, 9))
424
 
        self.assertContainsRe(self.get_log(), '_remember_remote_is_before')
425
 
        self.assertTrue(client_medium._is_remote_before((1, 5)))
 
411
        # You cannot call _remember_remote_is_before with a larger value.
 
412
        self.assertRaises(
 
413
            AssertionError, client_medium._remember_remote_is_before, (1, 9))
426
414
 
427
415
 
428
416
class TestBzrDirCloningMetaDir(TestRemote):
447
435
            'BzrDir.cloning_metadir', ('quack/', 'False'),
448
436
            'error', ('BranchReference',)),
449
437
        client.add_expected_call(
450
 
            'BzrDir.open_branchV3', ('quack/',),
 
438
            'BzrDir.open_branchV2', ('quack/',),
451
439
            'success', ('ref', self.get_url('referenced'))),
452
440
        a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
453
441
            _client=client)
480
468
        self.assertFinished(client)
481
469
 
482
470
 
483
 
class TestBzrDirOpen(TestRemote):
484
 
 
485
 
    def make_fake_client_and_transport(self, path='quack'):
486
 
        transport = MemoryTransport()
487
 
        transport.mkdir(path)
488
 
        transport = transport.clone(path)
489
 
        client = FakeClient(transport.base)
490
 
        return client, transport
491
 
 
492
 
    def test_absent(self):
493
 
        client, transport = self.make_fake_client_and_transport()
494
 
        client.add_expected_call(
495
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
496
 
        self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
497
 
                remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
498
 
        self.assertFinished(client)
499
 
 
500
 
    def test_present_without_workingtree(self):
501
 
        client, transport = self.make_fake_client_and_transport()
502
 
        client.add_expected_call(
503
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
504
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
505
 
            _client=client, _force_probe=True)
506
 
        self.assertIsInstance(bd, RemoteBzrDir)
507
 
        self.assertFalse(bd.has_workingtree())
508
 
        self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
509
 
        self.assertFinished(client)
510
 
 
511
 
    def test_present_with_workingtree(self):
512
 
        client, transport = self.make_fake_client_and_transport()
513
 
        client.add_expected_call(
514
 
            'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
515
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
516
 
            _client=client, _force_probe=True)
517
 
        self.assertIsInstance(bd, RemoteBzrDir)
518
 
        self.assertTrue(bd.has_workingtree())
519
 
        self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
520
 
        self.assertFinished(client)
521
 
 
522
 
    def test_backwards_compat(self):
523
 
        client, transport = self.make_fake_client_and_transport()
524
 
        client.add_expected_call(
525
 
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
526
 
        client.add_expected_call(
527
 
            'BzrDir.open', ('quack/',), 'success', ('yes',))
528
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
529
 
            _client=client, _force_probe=True)
530
 
        self.assertIsInstance(bd, RemoteBzrDir)
531
 
        self.assertFinished(client)
532
 
 
533
 
    def test_backwards_compat_hpss_v2(self):
534
 
        client, transport = self.make_fake_client_and_transport()
535
 
        # Monkey-patch fake client to simulate real-world behaviour with v2
536
 
        # server: upon first RPC call detect the protocol version, and because
537
 
        # the version is 2 also do _remember_remote_is_before((1, 6)) before
538
 
        # continuing with the RPC.
539
 
        orig_check_call = client._check_call
540
 
        def check_call(method, args):
541
 
            client._medium._protocol_version = 2
542
 
            client._medium._remember_remote_is_before((1, 6))
543
 
            client._check_call = orig_check_call
544
 
            client._check_call(method, args)
545
 
        client._check_call = check_call
546
 
        client.add_expected_call(
547
 
            'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
548
 
        client.add_expected_call(
549
 
            'BzrDir.open', ('quack/',), 'success', ('yes',))
550
 
        bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
551
 
            _client=client, _force_probe=True)
552
 
        self.assertIsInstance(bd, RemoteBzrDir)
553
 
        self.assertFinished(client)
554
 
 
555
 
 
556
471
class TestBzrDirOpenBranch(TestRemote):
557
472
 
558
473
    def test_backwards_compat(self):
560
475
        self.make_branch('.')
561
476
        a_dir = BzrDir.open(self.get_url('.'))
562
477
        self.reset_smart_call_log()
563
 
        verb = 'BzrDir.open_branchV3'
 
478
        verb = 'BzrDir.open_branchV2'
564
479
        self.disable_verb(verb)
565
480
        format = a_dir.open_branch()
566
481
        call_count = len([call for call in self.hpss_calls if
576
491
        transport = transport.clone('quack')
577
492
        client = FakeClient(transport.base)
578
493
        client.add_expected_call(
579
 
            'BzrDir.open_branchV3', ('quack/',),
 
494
            'BzrDir.open_branchV2', ('quack/',),
580
495
            'success', ('branch', branch_network_name))
581
496
        client.add_expected_call(
582
497
            'BzrDir.find_repositoryV3', ('quack/',),
601
516
            _client=client)
602
517
        self.assertRaises(errors.NotBranchError, bzrdir.open_branch)
603
518
        self.assertEqual(
604
 
            [('call', 'BzrDir.open_branchV3', ('quack/',))],
 
519
            [('call', 'BzrDir.open_branchV2', ('quack/',))],
605
520
            client._calls)
606
521
 
607
522
    def test__get_tree_branch(self):
608
523
        # _get_tree_branch is a form of open_branch, but it should only ask for
609
524
        # branch opening, not any other network requests.
610
525
        calls = []
611
 
        def open_branch(name=None):
 
526
        def open_branch():
612
527
            calls.append("Called")
613
528
            return "a-branch"
614
529
        transport = MemoryTransport()
631
546
        network_name = reference_format.network_name()
632
547
        branch_network_name = self.get_branch_format().network_name()
633
548
        client.add_expected_call(
634
 
            'BzrDir.open_branchV3', ('~hello/',),
 
549
            'BzrDir.open_branchV2', ('~hello/',),
635
550
            'success', ('branch', branch_network_name))
636
551
        client.add_expected_call(
637
552
            'BzrDir.find_repositoryV3', ('~hello/',),
685
600
        old.
686
601
        """
687
602
        self.assertRaises(errors.NotBranchError,
688
 
            RemoteBzrProber.probe_transport, OldServerTransport())
 
603
            RemoteBzrDirFormat.probe_transport, OldServerTransport())
689
604
 
690
605
 
691
606
class TestBzrDirCreateBranch(TestRemote):
768
683
        # fallback all the way to the first version.
769
684
        reference_format = self.get_repo_format()
770
685
        network_name = reference_format.network_name()
771
 
        server_url = 'bzr://example.com/'
772
 
        self.permit_url(server_url)
773
 
        client = FakeClient(server_url)
 
686
        client = FakeClient('bzr://example.com/')
774
687
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
775
688
        client.add_unknown_method_response('BzrDir.find_repositoryV2')
776
689
        client.add_success_response('ok', '', 'no', 'no')
782
695
            reference_format.get_format_string(), 'ok')
783
696
        # PackRepository wants to do a stat
784
697
        client.add_success_response('stat', '0', '65535')
785
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
 
698
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
786
699
            _client=client)
787
700
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
788
701
            _client=client)
802
715
        # fallback to find_repositoryV2
803
716
        reference_format = self.get_repo_format()
804
717
        network_name = reference_format.network_name()
805
 
        server_url = 'bzr://example.com/'
806
 
        self.permit_url(server_url)
807
 
        client = FakeClient(server_url)
 
718
        client = FakeClient('bzr://example.com/')
808
719
        client.add_unknown_method_response('BzrDir.find_repositoryV3')
809
720
        client.add_success_response('ok', '', 'no', 'no', 'no')
810
721
        # A real repository instance will be created to determine the network
815
726
            reference_format.get_format_string(), 'ok')
816
727
        # PackRepository wants to do a stat
817
728
        client.add_success_response('stat', '0', '65535')
818
 
        remote_transport = RemoteTransport(server_url + 'quack/', medium=False,
 
729
        remote_transport = RemoteTransport('bzr://example.com/quack/', medium=False,
819
730
            _client=client)
820
731
        bzrdir = RemoteBzrDir(remote_transport, remote.RemoteBzrDirFormat(),
821
732
            _client=client)
940
851
 
941
852
class RemoteBranchTestCase(RemoteBzrDirTestCase):
942
853
 
943
 
    def lock_remote_branch(self, branch):
944
 
        """Trick a RemoteBranch into thinking it is locked."""
945
 
        branch._lock_mode = 'w'
946
 
        branch._lock_count = 2
947
 
        branch._lock_token = 'branch token'
948
 
        branch._repo_lock_token = 'repo token'
949
 
        branch.repository._lock_mode = 'w'
950
 
        branch.repository._lock_count = 2
951
 
        branch.repository._lock_token = 'repo token'
952
 
 
953
854
    def make_remote_branch(self, transport, client):
954
855
        """Make a RemoteBranch using 'client' as its _SmartClient.
955
856
 
1094
995
        self.assertEqual({}, result)
1095
996
 
1096
997
 
1097
 
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1098
 
 
1099
 
    def test_trivial(self):
1100
 
        transport = MemoryTransport()
1101
 
        client = FakeClient(transport.base)
1102
 
        client.add_expected_call(
1103
 
            'Branch.get_stacked_on_url', ('quack/',),
1104
 
            'error', ('NotStacked',))
1105
 
        client.add_expected_call(
1106
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1107
 
            'success', ('',))
1108
 
        transport.mkdir('quack')
1109
 
        transport = transport.clone('quack')
1110
 
        branch = self.make_remote_branch(transport, client)
1111
 
        self.lock_remote_branch(branch)
1112
 
        branch._set_tags_bytes('tags bytes')
1113
 
        self.assertFinished(client)
1114
 
        self.assertEqual('tags bytes', client._calls[-1][-1])
1115
 
 
1116
 
    def test_backwards_compatible(self):
1117
 
        transport = MemoryTransport()
1118
 
        client = FakeClient(transport.base)
1119
 
        client.add_expected_call(
1120
 
            'Branch.get_stacked_on_url', ('quack/',),
1121
 
            'error', ('NotStacked',))
1122
 
        client.add_expected_call(
1123
 
            'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1124
 
            'unknown', ('Branch.set_tags_bytes',))
1125
 
        transport.mkdir('quack')
1126
 
        transport = transport.clone('quack')
1127
 
        branch = self.make_remote_branch(transport, client)
1128
 
        self.lock_remote_branch(branch)
1129
 
        class StubRealBranch(object):
1130
 
            def __init__(self):
1131
 
                self.calls = []
1132
 
            def _set_tags_bytes(self, bytes):
1133
 
                self.calls.append(('set_tags_bytes', bytes))
1134
 
        real_branch = StubRealBranch()
1135
 
        branch._real_branch = real_branch
1136
 
        branch._set_tags_bytes('tags bytes')
1137
 
        # Call a second time, to exercise the 'remote version already inferred'
1138
 
        # code path.
1139
 
        branch._set_tags_bytes('tags bytes')
1140
 
        self.assertFinished(client)
1141
 
        self.assertEqual(
1142
 
            [('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1143
 
 
1144
 
 
1145
998
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1146
999
 
1147
1000
    def test_empty_branch(self):
1219
1072
        client = FakeClient(self.get_url())
1220
1073
        branch_network_name = self.get_branch_format().network_name()
1221
1074
        client.add_expected_call(
1222
 
            'BzrDir.open_branchV3', ('stacked/',),
 
1075
            'BzrDir.open_branchV2', ('stacked/',),
1223
1076
            'success', ('branch', branch_network_name))
1224
1077
        client.add_expected_call(
1225
1078
            'BzrDir.find_repositoryV3', ('stacked/',),
1247
1100
            len(branch.repository._real_repository._fallback_repositories))
1248
1101
 
1249
1102
    def test_get_stacked_on_real_branch(self):
1250
 
        base_branch = self.make_branch('base')
1251
 
        stacked_branch = self.make_branch('stacked')
 
1103
        base_branch = self.make_branch('base', format='1.6')
 
1104
        stacked_branch = self.make_branch('stacked', format='1.6')
1252
1105
        stacked_branch.set_stacked_on_url('../base')
1253
1106
        reference_format = self.get_repo_format()
1254
1107
        network_name = reference_format.network_name()
1255
1108
        client = FakeClient(self.get_url())
1256
1109
        branch_network_name = self.get_branch_format().network_name()
1257
1110
        client.add_expected_call(
1258
 
            'BzrDir.open_branchV3', ('stacked/',),
 
1111
            'BzrDir.open_branchV2', ('stacked/',),
1259
1112
            'success', ('branch', branch_network_name))
1260
1113
        client.add_expected_call(
1261
1114
            'BzrDir.find_repositoryV3', ('stacked/',),
1262
 
            'success', ('ok', '', 'yes', 'no', 'yes', network_name))
 
1115
            'success', ('ok', '', 'no', 'no', 'yes', network_name))
1263
1116
        # called twice, once from constructor and then again by us
1264
1117
        client.add_expected_call(
1265
1118
            'Branch.get_stacked_on_url', ('stacked/',),
1489
1342
            errors.NoSuchRevision, branch.set_last_revision_info, 123, 'revid')
1490
1343
        branch.unlock()
1491
1344
 
 
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
 
1492
1355
    def test_backwards_compatibility(self):
1493
1356
        """If the server does not support the Branch.set_last_revision_info
1494
1357
        verb (which is new in 1.4), then the client falls back to VFS methods.
1617
1480
    def test_get_multi_line_branch_conf(self):
1618
1481
        # Make sure that multiple-line branch.conf files are supported
1619
1482
        #
1620
 
        # https://bugs.launchpad.net/bzr/+bug/354075
 
1483
        # https://bugs.edge.launchpad.net/bzr/+bug/354075
1621
1484
        client = FakeClient()
1622
1485
        client.add_expected_call(
1623
1486
            'Branch.get_stacked_on_url', ('memory:///',),
1651
1514
        branch.unlock()
1652
1515
        self.assertFinished(client)
1653
1516
 
1654
 
    def test_set_option_with_dict(self):
1655
 
        client = FakeClient()
1656
 
        client.add_expected_call(
1657
 
            'Branch.get_stacked_on_url', ('memory:///',),
1658
 
            'error', ('NotStacked',),)
1659
 
        client.add_expected_call(
1660
 
            'Branch.lock_write', ('memory:///', '', ''),
1661
 
            'success', ('ok', 'branch token', 'repo token'))
1662
 
        encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1663
 
        client.add_expected_call(
1664
 
            'Branch.set_config_option_dict', ('memory:///', 'branch token',
1665
 
            'repo token', encoded_dict_value, 'foo', ''),
1666
 
            'success', ())
1667
 
        client.add_expected_call(
1668
 
            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1669
 
            'success', ('ok',))
1670
 
        transport = MemoryTransport()
1671
 
        branch = self.make_remote_branch(transport, client)
1672
 
        branch.lock_write()
1673
 
        config = branch._get_config()
1674
 
        config.set_option(
1675
 
            {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
1676
 
            'foo')
1677
 
        branch.unlock()
1678
 
        self.assertFinished(client)
1679
 
 
1680
1517
    def test_backwards_compat_set_option(self):
1681
1518
        self.setup_smart_server_with_call_log()
1682
1519
        branch = self.make_branch('.')
1689
1526
        self.assertLength(10, self.hpss_calls)
1690
1527
        self.assertEqual('value', branch._get_config().get_option('name'))
1691
1528
 
1692
 
    def test_backwards_compat_set_option_with_dict(self):
1693
 
        self.setup_smart_server_with_call_log()
1694
 
        branch = self.make_branch('.')
1695
 
        verb = 'Branch.set_config_option_dict'
1696
 
        self.disable_verb(verb)
1697
 
        branch.lock_write()
1698
 
        self.addCleanup(branch.unlock)
1699
 
        self.reset_smart_call_log()
1700
 
        config = branch._get_config()
1701
 
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1702
 
        config.set_option(value_dict, 'name')
1703
 
        self.assertLength(10, self.hpss_calls)
1704
 
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
1705
 
 
1706
1529
 
1707
1530
class TestBranchLockWrite(RemoteBranchTestCase):
1708
1531
 
1850
1673
        return repo, client
1851
1674
 
1852
1675
 
1853
 
def remoted_description(format):
1854
 
    return 'Remote: ' + format.get_format_description()
1855
 
 
1856
 
 
1857
 
class TestBranchFormat(tests.TestCase):
1858
 
 
1859
 
    def test_get_format_description(self):
1860
 
        remote_format = RemoteBranchFormat()
1861
 
        real_format = branch.BranchFormat.get_default_format()
1862
 
        remote_format._network_name = real_format.network_name()
1863
 
        self.assertEqual(remoted_description(real_format),
1864
 
            remote_format.get_format_description())
1865
 
 
1866
 
 
1867
1676
class TestRepositoryFormat(TestRemoteRepository):
1868
1677
 
1869
1678
    def test_fast_delta(self):
1876
1685
        false_format._network_name = false_name
1877
1686
        self.assertEqual(False, false_format.fast_deltas)
1878
1687
 
1879
 
    def test_get_format_description(self):
1880
 
        remote_repo_format = RemoteRepositoryFormat()
1881
 
        real_format = repository.RepositoryFormat.get_default_format()
1882
 
        remote_repo_format._network_name = real_format.network_name()
1883
 
        self.assertEqual(remoted_description(real_format),
1884
 
            remote_repo_format.get_format_description())
1885
 
 
1886
1688
 
1887
1689
class TestRepositoryGatherStats(TestRemoteRepository):
1888
1690
 
2073
1875
        self.assertLength(1, self.hpss_calls)
2074
1876
 
2075
1877
    def disableExtraResults(self):
2076
 
        self.overrideAttr(SmartServerRepositoryGetParentMap,
2077
 
                          'no_extra_results', True)
 
1878
        old_flag = SmartServerRepositoryGetParentMap.no_extra_results
 
1879
        SmartServerRepositoryGetParentMap.no_extra_results = True
 
1880
        def reset_values():
 
1881
            SmartServerRepositoryGetParentMap.no_extra_results = old_flag
 
1882
        self.addCleanup(reset_values)
2078
1883
 
2079
1884
    def test_null_cached_missing_and_stop_key(self):
2080
1885
        self.setup_smart_server_with_call_log()
2139
1944
 
2140
1945
    def test_allows_new_revisions(self):
2141
1946
        """get_parent_map's results can be updated by commit."""
2142
 
        smart_server = test_server.SmartTCPServer_for_testing()
 
1947
        smart_server = server.SmartTCPServer_for_testing()
2143
1948
        self.start_server(smart_server)
2144
1949
        self.make_branch('branch')
2145
1950
        branch = Branch.open(smart_server.get_url() + '/branch')
2255
2060
        """
2256
2061
        # Make a repo with a fallback repo, both using a FakeClient.
2257
2062
        format = remote.response_tuple_to_repo_format(
2258
 
            ('yes', 'no', 'yes', self.get_repo_format().network_name()))
 
2063
            ('yes', 'no', 'yes', 'fake-network-name'))
2259
2064
        repo, client = self.setup_fake_client_and_repository('quack')
2260
2065
        repo._format = format
2261
2066
        fallback_repo, ignored = self.setup_fake_client_and_repository(
2262
2067
            'fallback')
2263
2068
        fallback_repo._client = client
2264
 
        fallback_repo._format = format
2265
2069
        repo.add_fallback_repository(fallback_repo)
2266
2070
        # First the client should ask the primary repo
2267
2071
        client.add_expected_call(
2288
2092
            repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2289
2093
        self.assertFinished(client)
2290
2094
 
2291
 
    def test_branch_fallback_locking(self):
2292
 
        """RemoteBranch.get_rev_id takes a read lock, and tries to call the
2293
 
        get_rev_id_for_revno verb.  If the verb is unknown the VFS fallback
2294
 
        will be invoked, which will fail if the repo is unlocked.
2295
 
        """
2296
 
        self.setup_smart_server_with_call_log()
2297
 
        tree = self.make_branch_and_memory_tree('.')
2298
 
        tree.lock_write()
2299
 
        tree.add('')
2300
 
        rev1 = tree.commit('First')
2301
 
        rev2 = tree.commit('Second')
2302
 
        tree.unlock()
2303
 
        branch = tree.branch
2304
 
        self.assertFalse(branch.is_locked())
2305
 
        self.reset_smart_call_log()
2306
 
        verb = 'Repository.get_rev_id_for_revno'
2307
 
        self.disable_verb(verb)
2308
 
        self.assertEqual(rev1, branch.get_rev_id(1))
2309
 
        self.assertLength(1, [call for call in self.hpss_calls if
2310
 
                              call.call.method == verb])
2311
 
 
2312
2095
 
2313
2096
class TestRepositoryIsShared(TestRemoteRepository):
2314
2097
 
2341
2124
        transport_path = 'quack'
2342
2125
        repo, client = self.setup_fake_client_and_repository(transport_path)
2343
2126
        client.add_success_response('ok', 'a token')
2344
 
        token = repo.lock_write().repository_token
 
2127
        result = repo.lock_write()
2345
2128
        self.assertEqual(
2346
2129
            [('call', 'Repository.lock_write', ('quack/', ''))],
2347
2130
            client._calls)
2348
 
        self.assertEqual('a token', token)
 
2131
        self.assertEqual('a token', result)
2349
2132
 
2350
2133
    def test_lock_write_already_locked(self):
2351
2134
        transport_path = 'quack'
2542
2325
        class FakeRealRepository:
2543
2326
            def _get_sink(self):
2544
2327
                return fake_real_sink
2545
 
            def is_in_write_group(self):
2546
 
                return False
2547
 
            def refresh_data(self):
2548
 
                return True
2549
2328
        repo._real_repository = FakeRealRepository()
2550
2329
        sink = repo._get_sink()
2551
2330
        fmt = repository.RepositoryFormat.get_default_format()
2689
2468
    """RemoteRepository.copy_content_into optimizations"""
2690
2469
 
2691
2470
    def test_copy_content_remote_to_local(self):
2692
 
        self.transport_server = test_server.SmartTCPServer_for_testing
 
2471
        self.transport_server = server.SmartTCPServer_for_testing
2693
2472
        src_repo = self.make_repository('repo1')
2694
2473
        src_repo = repository.Repository.open(self.get_url('repo1'))
2695
2474
        # At the moment the tarball-based copy_content_into can't write back
2843
2622
        expected_error = errors.NotBranchError(path=bzrdir.root_transport.base)
2844
2623
        self.assertEqual(expected_error, translated_error)
2845
2624
 
2846
 
    def test_nobranch_one_arg(self):
2847
 
        bzrdir = self.make_bzrdir('')
2848
 
        translated_error = self.translateTuple(
2849
 
            ('nobranch', 'extra detail'), bzrdir=bzrdir)
2850
 
        expected_error = errors.NotBranchError(
2851
 
            path=bzrdir.root_transport.base,
2852
 
            detail='extra detail')
2853
 
        self.assertEqual(expected_error, translated_error)
2854
 
 
2855
2625
    def test_LockContention(self):
2856
2626
        translated_error = self.translateTuple(('LockContention',))
2857
2627
        expected_error = errors.LockContention('(remote lock)')
2970
2740
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2971
2741
        # been muttered to the log file for developer to look at.
2972
2742
        self.assertContainsRe(
2973
 
            self.get_log(),
 
2743
            self._get_log(keep_log_file=True),
2974
2744
            "Missing key 'branch' in context")
2975
2745
 
2976
2746
    def test_path_missing(self):
2984
2754
        self.assertEqual(server_error, translated_error)
2985
2755
        # In addition to re-raising ErrorFromSmartServer, some debug info has
2986
2756
        # been muttered to the log file for developer to look at.
2987
 
        self.assertContainsRe(self.get_log(), "Missing key 'path' in context")
 
2757
        self.assertContainsRe(
 
2758
            self._get_log(keep_log_file=True), "Missing key 'path' in context")
2988
2759
 
2989
2760
 
2990
2761
class TestStacking(tests.TestCaseWithTransport):
3008
2779
        stacked_branch = self.make_branch('stacked', format='1.9')
3009
2780
        stacked_branch.set_stacked_on_url('../base')
3010
2781
        # start a server looking at this
3011
 
        smart_server = test_server.SmartTCPServer_for_testing()
 
2782
        smart_server = server.SmartTCPServer_for_testing()
3012
2783
        self.start_server(smart_server)
3013
2784
        remote_bzrdir = BzrDir.open(smart_server.get_url() + '/stacked')
3014
2785
        # can get its branch and repository
3118
2889
            local_tree.commit('more local changes are better')
3119
2890
            branch = Branch.open(self.get_url('tree3'))
3120
2891
            branch.lock_read()
3121
 
            self.addCleanup(branch.unlock)
3122
2892
            return None, branch
3123
2893
        rev_ord, expected_revs = self.get_ordered_revs('1.9', 'unordered',
3124
2894
            branch_factory=make_stacked_stacked)
3170
2940
        super(TestRemoteBranchEffort, self).setUp()
3171
2941
        # Create a smart server that publishes whatever the backing VFS server
3172
2942
        # does.
3173
 
        self.smart_server = test_server.SmartTCPServer_for_testing()
 
2943
        self.smart_server = server.SmartTCPServer_for_testing()
3174
2944
        self.start_server(self.smart_server, self.get_server())
3175
2945
        # Log all HPSS calls into self.hpss_calls.
3176
2946
        _SmartClient.hooks.install_named_hook(