~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-08-17 18:13:57 UTC
  • mfrom: (5268.7.29 transport-segments)
  • Revision ID: pqm@pqm.ubuntu.com-20110817181357-y5q5eth1hk8bl3om
(jelmer) Allow specifying the colocated branch to use in the branch URL,
 and retrieving the branch name using ControlDir._get_selected_branch.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2013, 2016 Canonical Ltd
 
1
# Copyright (C) 2006-2011 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
25
25
 
26
26
import bz2
27
27
from cStringIO import StringIO
28
 
import zlib
29
28
 
30
29
from bzrlib import (
31
 
    bencode,
32
30
    branch,
33
31
    bzrdir,
34
32
    config,
35
33
    controldir,
36
34
    errors,
 
35
    graph as _mod_graph,
37
36
    inventory,
38
37
    inventory_delta,
39
38
    remote,
42
41
    transport,
43
42
    treebuilder,
44
43
    versionedfile,
45
 
    vf_search,
46
44
    )
47
45
from bzrlib.branch import Branch
48
46
from bzrlib.bzrdir import (
50
48
    BzrDirFormat,
51
49
    RemoteBzrProber,
52
50
    )
53
 
from bzrlib.chk_serializer import chk_bencode_serializer
54
51
from bzrlib.remote import (
55
52
    RemoteBranch,
56
53
    RemoteBranchFormat,
60
57
    RemoteRepositoryFormat,
61
58
    )
62
59
from bzrlib.repofmt import groupcompress_repo, knitpack_repo
63
 
from bzrlib.revision import (
64
 
    NULL_REVISION,
65
 
    Revision,
66
 
    )
 
60
from bzrlib.revision import NULL_REVISION
67
61
from bzrlib.smart import medium, request
68
62
from bzrlib.smart.client import _SmartClient
69
63
from bzrlib.smart.repository import (
70
64
    SmartServerRepositoryGetParentMap,
71
65
    SmartServerRepositoryGetStream_1_19,
72
 
    _stream_to_byte_stream,
73
66
    )
74
 
from bzrlib.symbol_versioning import deprecated_in
75
67
from bzrlib.tests import (
76
68
    test_server,
77
69
    )
121
113
        self.local_wt.commit(message='test commit', rev_id=revid)
122
114
        self.assertTrue(repo.has_revision(revid))
123
115
 
 
116
    def test_remote_branch_revision_history(self):
 
117
        b = BzrDir.open_from_transport(self.transport).open_branch()
 
118
        self.assertEqual([], b.revision_history())
 
119
        r1 = self.local_wt.commit('1st commit')
 
120
        r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8'.encode('utf8'))
 
121
        self.assertEqual([r1, r2], b.revision_history())
 
122
 
124
123
    def test_find_correct_format(self):
125
124
        """Should open a RemoteBzrDir over a RemoteTransport"""
126
125
        fmt = BzrDirFormat.find_format(self.transport)
166
165
    def test_remote_branch_set_append_revisions_only(self):
167
166
        # Make a format 1.9 branch, which supports append_revisions_only
168
167
        branch = self.make_branch('branch', format='1.9')
 
168
        config = branch.get_config()
169
169
        branch.set_append_revisions_only(True)
170
 
        config = branch.get_config_stack()
171
170
        self.assertEqual(
172
 
            True, config.get('append_revisions_only'))
 
171
            'True', config.get_user_option('append_revisions_only'))
173
172
        branch.set_append_revisions_only(False)
174
 
        config = branch.get_config_stack()
175
173
        self.assertEqual(
176
 
            False, config.get('append_revisions_only'))
 
174
            'False', config.get_user_option('append_revisions_only'))
177
175
 
178
176
    def test_remote_branch_set_append_revisions_only_upgrade_reqd(self):
179
177
        branch = self.make_branch('branch', format='knit')
 
178
        config = branch.get_config()
180
179
        self.assertRaises(
181
180
            errors.UpgradeRequired, branch.set_append_revisions_only, True)
182
181
 
340
339
class TestRemote(tests.TestCaseWithMemoryTransport):
341
340
 
342
341
    def get_branch_format(self):
343
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
 
342
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
344
343
        return reference_bzrdir_format.get_branch_format()
345
344
 
346
345
    def get_repo_format(self):
347
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
 
346
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
348
347
        return reference_bzrdir_format.repository_format
349
348
 
350
349
    def assertFinished(self, fake_client):
466
465
        transport = transport.clone('quack')
467
466
        self.make_bzrdir('quack')
468
467
        client = FakeClient(transport.base)
469
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
 
468
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
470
469
        control_name = reference_bzrdir_format.network_name()
471
470
        client.add_expected_call(
472
471
            'BzrDir.cloning_metadir', ('quack/', 'False'),
482
481
        self.assertEqual(None, result._branch_format)
483
482
        self.assertFinished(client)
484
483
 
485
 
    def test_unknown(self):
486
 
        transport = self.get_transport('quack')
487
 
        referenced = self.make_branch('referenced')
488
 
        expected = referenced.bzrdir.cloning_metadir()
489
 
        client = FakeClient(transport.base)
490
 
        client.add_expected_call(
491
 
            'BzrDir.cloning_metadir', ('quack/', 'False'),
492
 
            'success', ('unknown', 'unknown', ('branch', ''))),
493
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
494
 
            _client=client)
495
 
        self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
496
 
 
497
 
 
498
 
class TestBzrDirCheckoutMetaDir(TestRemote):
499
 
 
500
 
    def test__get_checkout_format(self):
501
 
        transport = MemoryTransport()
502
 
        client = FakeClient(transport.base)
503
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
504
 
        control_name = reference_bzrdir_format.network_name()
505
 
        client.add_expected_call(
506
 
            'BzrDir.checkout_metadir', ('quack/', ),
507
 
            'success', (control_name, '', ''))
508
 
        transport.mkdir('quack')
509
 
        transport = transport.clone('quack')
510
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
511
 
            _client=client)
512
 
        result = a_bzrdir.checkout_metadir()
513
 
        # We should have got a reference control dir with default branch and
514
 
        # repository formats.
515
 
        self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
516
 
        self.assertEqual(None, result._repository_format)
517
 
        self.assertEqual(None, result._branch_format)
518
 
        self.assertFinished(client)
519
 
 
520
 
    def test_unknown_format(self):
521
 
        transport = MemoryTransport()
522
 
        client = FakeClient(transport.base)
523
 
        client.add_expected_call(
524
 
            'BzrDir.checkout_metadir', ('quack/',),
525
 
            'success', ('dontknow', '', ''))
526
 
        transport.mkdir('quack')
527
 
        transport = transport.clone('quack')
528
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
529
 
            _client=client)
530
 
        self.assertRaises(errors.UnknownFormatError,
531
 
            a_bzrdir.checkout_metadir)
532
 
        self.assertFinished(client)
533
 
 
534
 
 
535
 
class TestBzrDirGetBranches(TestRemote):
536
 
 
537
 
    def test_get_branches(self):
538
 
        transport = MemoryTransport()
539
 
        client = FakeClient(transport.base)
540
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
541
 
        branch_name = reference_bzrdir_format.get_branch_format().network_name()
542
 
        client.add_success_response_with_body(
543
 
            bencode.bencode({
544
 
                "foo": ("branch", branch_name),
545
 
                "": ("branch", branch_name)}), "success")
546
 
        client.add_success_response(
547
 
            'ok', '', 'no', 'no', 'no',
548
 
                reference_bzrdir_format.repository_format.network_name())
549
 
        client.add_error_response('NotStacked')
550
 
        client.add_success_response(
551
 
            'ok', '', 'no', 'no', 'no',
552
 
                reference_bzrdir_format.repository_format.network_name())
553
 
        client.add_error_response('NotStacked')
554
 
        transport.mkdir('quack')
555
 
        transport = transport.clone('quack')
556
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
557
 
            _client=client)
558
 
        result = a_bzrdir.get_branches()
559
 
        self.assertEqual(set(["", "foo"]), set(result.keys()))
560
 
        self.assertEqual(
561
 
            [('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
562
 
             ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
563
 
             ('call', 'Branch.get_stacked_on_url', ('quack/', )),
564
 
             ('call', 'BzrDir.find_repositoryV3', ('quack/', )),
565
 
             ('call', 'Branch.get_stacked_on_url', ('quack/', ))],
566
 
            client._calls)
567
 
 
568
 
 
569
 
class TestBzrDirDestroyBranch(TestRemote):
570
 
 
571
 
    def test_destroy_default(self):
572
 
        transport = self.get_transport('quack')
573
 
        referenced = self.make_branch('referenced')
574
 
        client = FakeClient(transport.base)
575
 
        client.add_expected_call(
576
 
            'BzrDir.destroy_branch', ('quack/', ),
577
 
            'success', ('ok',)),
578
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
579
 
            _client=client)
580
 
        a_bzrdir.destroy_branch()
581
 
        self.assertFinished(client)
582
 
 
583
 
 
584
 
class TestBzrDirHasWorkingTree(TestRemote):
585
 
 
586
 
    def test_has_workingtree(self):
587
 
        transport = self.get_transport('quack')
588
 
        client = FakeClient(transport.base)
589
 
        client.add_expected_call(
590
 
            'BzrDir.has_workingtree', ('quack/',),
591
 
            'success', ('yes',)),
592
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
593
 
            _client=client)
594
 
        self.assertTrue(a_bzrdir.has_workingtree())
595
 
        self.assertFinished(client)
596
 
 
597
 
    def test_no_workingtree(self):
598
 
        transport = self.get_transport('quack')
599
 
        client = FakeClient(transport.base)
600
 
        client.add_expected_call(
601
 
            'BzrDir.has_workingtree', ('quack/',),
602
 
            'success', ('no',)),
603
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
604
 
            _client=client)
605
 
        self.assertFalse(a_bzrdir.has_workingtree())
606
 
        self.assertFinished(client)
607
 
 
608
 
 
609
 
class TestBzrDirDestroyRepository(TestRemote):
610
 
 
611
 
    def test_destroy_repository(self):
612
 
        transport = self.get_transport('quack')
613
 
        client = FakeClient(transport.base)
614
 
        client.add_expected_call(
615
 
            'BzrDir.destroy_repository', ('quack/',),
616
 
            'success', ('ok',)),
617
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
618
 
            _client=client)
619
 
        a_bzrdir.destroy_repository()
620
 
        self.assertFinished(client)
621
 
 
622
484
 
623
485
class TestBzrDirOpen(TestRemote):
624
486
 
748
610
        # _get_tree_branch is a form of open_branch, but it should only ask for
749
611
        # branch opening, not any other network requests.
750
612
        calls = []
751
 
        def open_branch(name=None, possible_transports=None):
 
613
        def open_branch(name=None):
752
614
            calls.append("Called")
753
615
            return "a-branch"
754
616
        transport = MemoryTransport()
845
707
        transport = transport.clone('quack')
846
708
        self.make_repository('quack')
847
709
        client = FakeClient(transport.base)
848
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
 
710
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
849
711
        reference_format = reference_bzrdir_format.get_branch_format()
850
712
        network_name = reference_format.network_name()
851
713
        reference_repo_fmt = reference_bzrdir_format.repository_format
873
735
        # Client's medium rooted a transport root (not at the bzrdir)
874
736
        client = FakeClient(transport.base)
875
737
        transport = transport.clone('quack')
876
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
 
738
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
877
739
        reference_format = reference_bzrdir_format.get_branch_format()
878
740
        network_name = reference_format.network_name()
879
741
        reference_repo_fmt = reference_bzrdir_format.repository_format
909
771
        transport = transport.clone('quack')
910
772
        self.make_bzrdir('quack')
911
773
        client = FakeClient(transport.base)
912
 
        reference_bzrdir_format = controldir.format_registry.get('default')()
 
774
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
913
775
        reference_format = reference_bzrdir_format.repository_format
914
776
        network_name = reference_format.network_name()
915
777
        client.add_expected_call(
946
808
        # name.
947
809
        client.add_success_response_with_body(
948
810
            "Bazaar-NG meta directory, format 1\n", 'ok')
949
 
        client.add_success_response('stat', '0', '65535')
950
811
        client.add_success_response_with_body(
951
812
            reference_format.get_format_string(), 'ok')
952
813
        # PackRepository wants to do a stat
961
822
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
962
823
             ('call', 'BzrDir.find_repository', ('quack/',)),
963
824
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
964
 
             ('call', 'stat', ('/quack/.bzr',)),
965
825
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
966
826
             ('call', 'stat', ('/quack/.bzr/repository',)),
967
827
             ],
981
841
        # name.
982
842
        client.add_success_response_with_body(
983
843
            "Bazaar-NG meta directory, format 1\n", 'ok')
984
 
        client.add_success_response('stat', '0', '65535')
985
844
        client.add_success_response_with_body(
986
845
            reference_format.get_format_string(), 'ok')
987
846
        # PackRepository wants to do a stat
995
854
            [('call', 'BzrDir.find_repositoryV3', ('quack/',)),
996
855
             ('call', 'BzrDir.find_repositoryV2', ('quack/',)),
997
856
             ('call_expecting_body', 'get', ('/quack/.bzr/branch-format',)),
998
 
             ('call', 'stat', ('/quack/.bzr',)),
999
857
             ('call_expecting_body', 'get', ('/quack/.bzr/repository/format',)),
1000
858
             ('call', 'stat', ('/quack/.bzr/repository',)),
1001
859
             ],
1138
996
        return RemoteBranch(bzrdir, repo, _client=client, format=format)
1139
997
 
1140
998
 
1141
 
class TestBranchBreakLock(RemoteBranchTestCase):
1142
 
 
1143
 
    def test_break_lock(self):
1144
 
        transport_path = 'quack'
1145
 
        transport = MemoryTransport()
1146
 
        client = FakeClient(transport.base)
1147
 
        client.add_expected_call(
1148
 
            'Branch.get_stacked_on_url', ('quack/',),
1149
 
            'error', ('NotStacked',))
1150
 
        client.add_expected_call(
1151
 
            'Branch.break_lock', ('quack/',),
1152
 
            'success', ('ok',))
1153
 
        transport.mkdir('quack')
1154
 
        transport = transport.clone('quack')
1155
 
        branch = self.make_remote_branch(transport, client)
1156
 
        branch.break_lock()
1157
 
        self.assertFinished(client)
1158
 
 
1159
 
 
1160
 
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1161
 
 
1162
 
    def test_get_physical_lock_status_yes(self):
1163
 
        transport = MemoryTransport()
1164
 
        client = FakeClient(transport.base)
1165
 
        client.add_expected_call(
1166
 
            'Branch.get_stacked_on_url', ('quack/',),
1167
 
            'error', ('NotStacked',))
1168
 
        client.add_expected_call(
1169
 
            'Branch.get_physical_lock_status', ('quack/',),
1170
 
            'success', ('yes',))
1171
 
        transport.mkdir('quack')
1172
 
        transport = transport.clone('quack')
1173
 
        branch = self.make_remote_branch(transport, client)
1174
 
        result = branch.get_physical_lock_status()
1175
 
        self.assertFinished(client)
1176
 
        self.assertEqual(True, result)
1177
 
 
1178
 
    def test_get_physical_lock_status_no(self):
1179
 
        transport = MemoryTransport()
1180
 
        client = FakeClient(transport.base)
1181
 
        client.add_expected_call(
1182
 
            'Branch.get_stacked_on_url', ('quack/',),
1183
 
            'error', ('NotStacked',))
1184
 
        client.add_expected_call(
1185
 
            'Branch.get_physical_lock_status', ('quack/',),
1186
 
            'success', ('no',))
1187
 
        transport.mkdir('quack')
1188
 
        transport = transport.clone('quack')
1189
 
        branch = self.make_remote_branch(transport, client)
1190
 
        result = branch.get_physical_lock_status()
1191
 
        self.assertFinished(client)
1192
 
        self.assertEqual(False, result)
1193
 
 
1194
 
 
1195
999
class TestBranchGetParent(RemoteBranchTestCase):
1196
1000
 
1197
1001
    def test_no_parent(self):
1287
1091
        verb = 'Branch.set_parent_location'
1288
1092
        self.disable_verb(verb)
1289
1093
        branch.set_parent('http://foo/')
1290
 
        self.assertLength(14, self.hpss_calls)
 
1094
        self.assertLength(12, self.hpss_calls)
1291
1095
 
1292
1096
 
1293
1097
class TestBranchGetTagsBytes(RemoteBranchTestCase):
1446
1250
        return branch
1447
1251
 
1448
1252
    def test_backwards_compatible(self):
1449
 
        br = self.make_branch_with_tags()
1450
 
        br.get_config_stack().set('branch.fetch_tags', True)
1451
 
        self.addCleanup(br.lock_read().unlock)
 
1253
        branch = self.make_branch_with_tags()
 
1254
        c = branch.get_config()
 
1255
        c.set_user_option('branch.fetch_tags', 'True')
 
1256
        self.addCleanup(branch.lock_read().unlock)
1452
1257
        # Disable the heads_to_fetch verb
1453
1258
        verb = 'Branch.heads_to_fetch'
1454
1259
        self.disable_verb(verb)
1455
1260
        self.reset_smart_call_log()
1456
 
        result = br.heads_to_fetch()
 
1261
        result = branch.heads_to_fetch()
1457
1262
        self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1458
1263
        self.assertEqual(
1459
 
            ['Branch.last_revision_info', 'Branch.get_tags_bytes'],
 
1264
            ['Branch.last_revision_info', 'Branch.get_config_file',
 
1265
             'Branch.get_tags_bytes'],
1460
1266
            [call.call.method for call in self.hpss_calls])
1461
1267
 
1462
1268
    def test_backwards_compatible_no_tags(self):
1463
 
        br = self.make_branch_with_tags()
1464
 
        br.get_config_stack().set('branch.fetch_tags', False)
1465
 
        self.addCleanup(br.lock_read().unlock)
 
1269
        branch = self.make_branch_with_tags()
 
1270
        c = branch.get_config()
 
1271
        c.set_user_option('branch.fetch_tags', 'False')
 
1272
        self.addCleanup(branch.lock_read().unlock)
1466
1273
        # Disable the heads_to_fetch verb
1467
1274
        verb = 'Branch.heads_to_fetch'
1468
1275
        self.disable_verb(verb)
1469
1276
        self.reset_smart_call_log()
1470
 
        result = br.heads_to_fetch()
 
1277
        result = branch.heads_to_fetch()
1471
1278
        self.assertEqual((set(['tip']), set()), result)
1472
1279
        self.assertEqual(
1473
 
            ['Branch.last_revision_info'],
 
1280
            ['Branch.last_revision_info', 'Branch.get_config_file'],
1474
1281
            [call.call.method for call in self.hpss_calls])
1475
1282
 
1476
1283
 
1638
1445
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1639
1446
            'success', ('ok',))
1640
1447
        branch = self.make_remote_branch(transport, client)
 
1448
        # This is a hack to work around the problem that RemoteBranch currently
 
1449
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 
1450
        branch._ensure_real = lambda: None
1641
1451
        branch.lock_write()
1642
1452
        result = branch._set_last_revision(NULL_REVISION)
1643
1453
        branch.unlock()
1672
1482
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1673
1483
            'success', ('ok',))
1674
1484
        branch = self.make_remote_branch(transport, client)
 
1485
        # This is a hack to work around the problem that RemoteBranch currently
 
1486
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 
1487
        branch._ensure_real = lambda: None
1675
1488
        # Lock the branch, reset the record of remote calls.
1676
1489
        branch.lock_write()
1677
1490
        result = branch._set_last_revision('rev-id2')
1744
1557
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1745
1558
            'success', ('ok',))
1746
1559
        branch = self.make_remote_branch(transport, client)
 
1560
        branch._ensure_real = lambda: None
1747
1561
        branch.lock_write()
1748
1562
        # The 'TipChangeRejected' error response triggered by calling
1749
1563
        # set_last_revision_info causes a TipChangeRejected exception.
2012
1826
        self.addCleanup(branch.unlock)
2013
1827
        self.reset_smart_call_log()
2014
1828
        branch._get_config().set_option('value', 'name')
2015
 
        self.assertLength(11, self.hpss_calls)
 
1829
        self.assertLength(10, self.hpss_calls)
2016
1830
        self.assertEqual('value', branch._get_config().get_option('name'))
2017
1831
 
2018
1832
    def test_backwards_compat_set_option_with_dict(self):
2026
1840
        config = branch._get_config()
2027
1841
        value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
2028
1842
        config.set_option(value_dict, 'name')
2029
 
        self.assertLength(11, self.hpss_calls)
 
1843
        self.assertLength(10, self.hpss_calls)
2030
1844
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
2031
1845
 
2032
1846
 
2033
 
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
2034
 
 
2035
 
    def test_get_branch_conf(self):
2036
 
        # in an empty branch we decode the response properly
2037
 
        client = FakeClient()
2038
 
        client.add_expected_call(
2039
 
            'Branch.get_stacked_on_url', ('memory:///',),
2040
 
            'error', ('NotStacked',),)
2041
 
        client.add_success_response_with_body('# config file body', 'ok')
2042
 
        transport = MemoryTransport()
2043
 
        branch = self.make_remote_branch(transport, client)
2044
 
        config = branch.get_config_stack()
2045
 
        config.get("email")
2046
 
        config.get("log_format")
2047
 
        self.assertEqual(
2048
 
            [('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2049
 
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
2050
 
            client._calls)
2051
 
 
2052
 
    def test_set_branch_conf(self):
2053
 
        client = FakeClient()
2054
 
        client.add_expected_call(
2055
 
            'Branch.get_stacked_on_url', ('memory:///',),
2056
 
            'error', ('NotStacked',),)
2057
 
        client.add_expected_call(
2058
 
            'Branch.lock_write', ('memory:///', '', ''),
2059
 
            'success', ('ok', 'branch token', 'repo token'))
2060
 
        client.add_expected_call(
2061
 
            'Branch.get_config_file', ('memory:///', ),
2062
 
            'success', ('ok', ), "# line 1\n")
2063
 
        client.add_expected_call(
2064
 
            'Branch.get_config_file', ('memory:///', ),
2065
 
            'success', ('ok', ), "# line 1\n")
2066
 
        client.add_expected_call(
2067
 
            'Branch.put_config_file', ('memory:///', 'branch token',
2068
 
            'repo token'),
2069
 
            'success', ('ok',))
2070
 
        client.add_expected_call(
2071
 
            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
2072
 
            'success', ('ok',))
2073
 
        transport = MemoryTransport()
2074
 
        branch = self.make_remote_branch(transport, client)
2075
 
        branch.lock_write()
2076
 
        config = branch.get_config_stack()
2077
 
        config.set('email', 'The Dude <lebowski@example.com>')
2078
 
        branch.unlock()
2079
 
        self.assertFinished(client)
2080
 
        self.assertEqual(
2081
 
            [('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2082
 
             ('call', 'Branch.lock_write', ('memory:///', '', '')),
2083
 
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2084
 
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2085
 
             ('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2086
 
                 ('memory:///', 'branch token', 'repo token'),
2087
 
                 '# line 1\nemail = The Dude <lebowski@example.com>\n'),
2088
 
             ('call', 'Branch.unlock', ('memory:///', 'branch token', 'repo token'))],
2089
 
            client._calls)
2090
 
 
2091
 
 
2092
1847
class TestBranchLockWrite(RemoteBranchTestCase):
2093
1848
 
2094
1849
    def test_lock_write_unlockable(self):
2107
1862
        self.assertFinished(client)
2108
1863
 
2109
1864
 
2110
 
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
2111
 
 
2112
 
    def test_simple(self):
2113
 
        transport = MemoryTransport()
2114
 
        client = FakeClient(transport.base)
2115
 
        client.add_expected_call(
2116
 
            'Branch.get_stacked_on_url', ('quack/',),
2117
 
            'error', ('NotStacked',),)
2118
 
        client.add_expected_call(
2119
 
            'Branch.revision_id_to_revno', ('quack/', 'null:'),
2120
 
            'success', ('ok', '0',),)
2121
 
        client.add_expected_call(
2122
 
            'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2123
 
            'error', ('NoSuchRevision', 'unknown',),)
2124
 
        transport.mkdir('quack')
2125
 
        transport = transport.clone('quack')
2126
 
        branch = self.make_remote_branch(transport, client)
2127
 
        self.assertEqual(0, branch.revision_id_to_revno('null:'))
2128
 
        self.assertRaises(errors.NoSuchRevision,
2129
 
            branch.revision_id_to_revno, 'unknown')
2130
 
        self.assertFinished(client)
2131
 
 
2132
 
    def test_dotted(self):
2133
 
        transport = MemoryTransport()
2134
 
        client = FakeClient(transport.base)
2135
 
        client.add_expected_call(
2136
 
            'Branch.get_stacked_on_url', ('quack/',),
2137
 
            'error', ('NotStacked',),)
2138
 
        client.add_expected_call(
2139
 
            'Branch.revision_id_to_revno', ('quack/', 'null:'),
2140
 
            'success', ('ok', '0',),)
2141
 
        client.add_expected_call(
2142
 
            'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2143
 
            'error', ('NoSuchRevision', 'unknown',),)
2144
 
        transport.mkdir('quack')
2145
 
        transport = transport.clone('quack')
2146
 
        branch = self.make_remote_branch(transport, client)
2147
 
        self.assertEqual((0, ), branch.revision_id_to_dotted_revno('null:'))
2148
 
        self.assertRaises(errors.NoSuchRevision,
2149
 
            branch.revision_id_to_dotted_revno, 'unknown')
2150
 
        self.assertFinished(client)
2151
 
 
2152
 
    def test_dotted_no_smart_verb(self):
2153
 
        self.setup_smart_server_with_call_log()
2154
 
        branch = self.make_branch('.')
2155
 
        self.disable_verb('Branch.revision_id_to_revno')
2156
 
        self.reset_smart_call_log()
2157
 
        self.assertEqual((0, ),
2158
 
            branch.revision_id_to_dotted_revno('null:'))
2159
 
        self.assertLength(8, self.hpss_calls)
2160
 
 
2161
 
 
2162
1865
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
2163
1866
 
2164
1867
    def test__get_config(self):
2178
1881
        self.reset_smart_call_log()
2179
1882
        config = bzrdir.get_config()
2180
1883
        config.set_default_stack_on('/')
2181
 
        self.assertLength(4, self.hpss_calls)
 
1884
        self.assertLength(3, self.hpss_calls)
2182
1885
 
2183
1886
    def test_backwards_compat_get_option(self):
2184
1887
        self.setup_smart_server_with_call_log()
2188
1891
        self.reset_smart_call_log()
2189
1892
        self.assertEqual(None,
2190
1893
            bzrdir._get_config().get_option('default_stack_on'))
2191
 
        self.assertLength(4, self.hpss_calls)
 
1894
        self.assertLength(3, self.hpss_calls)
2192
1895
 
2193
1896
 
2194
1897
class TestTransportIsReadonly(tests.TestCase):
2321
2024
            remote_repo_format.get_format_description())
2322
2025
 
2323
2026
 
2324
 
class TestRepositoryAllRevisionIds(TestRemoteRepository):
2325
 
 
2326
 
    def test_empty(self):
2327
 
        transport_path = 'quack'
2328
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2329
 
        client.add_success_response_with_body('', 'ok')
2330
 
        self.assertEqual([], repo.all_revision_ids())
2331
 
        self.assertEqual(
2332
 
            [('call_expecting_body', 'Repository.all_revision_ids',
2333
 
             ('quack/',))],
2334
 
            client._calls)
2335
 
 
2336
 
    def test_with_some_content(self):
2337
 
        transport_path = 'quack'
2338
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2339
 
        client.add_success_response_with_body(
2340
 
            'rev1\nrev2\nanotherrev\n', 'ok')
2341
 
        self.assertEqual(["rev1", "rev2", "anotherrev"],
2342
 
            repo.all_revision_ids())
2343
 
        self.assertEqual(
2344
 
            [('call_expecting_body', 'Repository.all_revision_ids',
2345
 
             ('quack/',))],
2346
 
            client._calls)
2347
 
 
2348
 
 
2349
2027
class TestRepositoryGatherStats(TestRemoteRepository):
2350
2028
 
2351
2029
    def test_revid_none(self):
2404
2082
                         result)
2405
2083
 
2406
2084
 
2407
 
class TestRepositoryBreakLock(TestRemoteRepository):
2408
 
 
2409
 
    def test_break_lock(self):
2410
 
        transport_path = 'quack'
2411
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2412
 
        client.add_success_response('ok')
2413
 
        repo.break_lock()
2414
 
        self.assertEqual(
2415
 
            [('call', 'Repository.break_lock', ('quack/',))],
2416
 
            client._calls)
2417
 
 
2418
 
 
2419
 
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
2420
 
 
2421
 
    def test_get_serializer_format(self):
2422
 
        transport_path = 'hill'
2423
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2424
 
        client.add_success_response('ok', '7')
2425
 
        self.assertEqual('7', repo.get_serializer_format())
2426
 
        self.assertEqual(
2427
 
            [('call', 'VersionedFileRepository.get_serializer_format',
2428
 
              ('hill/', ))],
2429
 
            client._calls)
2430
 
 
2431
 
 
2432
 
class TestRepositoryReconcile(TestRemoteRepository):
2433
 
 
2434
 
    def test_reconcile(self):
2435
 
        transport_path = 'hill'
2436
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2437
 
        body = ("garbage_inventories: 2\n"
2438
 
                "inconsistent_parents: 3\n")
2439
 
        client.add_expected_call(
2440
 
            'Repository.lock_write', ('hill/', ''),
2441
 
            'success', ('ok', 'a token'))
2442
 
        client.add_success_response_with_body(body, 'ok')
2443
 
        reconciler = repo.reconcile()
2444
 
        self.assertEqual(
2445
 
            [('call', 'Repository.lock_write', ('hill/', '')),
2446
 
             ('call_expecting_body', 'Repository.reconcile',
2447
 
                ('hill/', 'a token'))],
2448
 
            client._calls)
2449
 
        self.assertEqual(2, reconciler.garbage_inventories)
2450
 
        self.assertEqual(3, reconciler.inconsistent_parents)
2451
 
 
2452
 
 
2453
 
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2454
 
 
2455
 
    def test_text(self):
2456
 
        # ('ok',), body with signature text
2457
 
        transport_path = 'quack'
2458
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2459
 
        client.add_success_response_with_body(
2460
 
            'THETEXT', 'ok')
2461
 
        self.assertEqual("THETEXT", repo.get_signature_text("revid"))
2462
 
        self.assertEqual(
2463
 
            [('call_expecting_body', 'Repository.get_revision_signature_text',
2464
 
             ('quack/', 'revid'))],
2465
 
            client._calls)
2466
 
 
2467
 
    def test_no_signature(self):
2468
 
        transport_path = 'quick'
2469
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2470
 
        client.add_error_response('nosuchrevision', 'unknown')
2471
 
        self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
2472
 
                "unknown")
2473
 
        self.assertEqual(
2474
 
            [('call_expecting_body', 'Repository.get_revision_signature_text',
2475
 
              ('quick/', 'unknown'))],
2476
 
            client._calls)
2477
 
 
2478
 
 
2479
2085
class TestRepositoryGetGraph(TestRemoteRepository):
2480
2086
 
2481
2087
    def test_get_graph(self):
2486
2092
        self.assertNotEqual(graph._parents_provider, repo)
2487
2093
 
2488
2094
 
2489
 
class TestRepositoryAddSignatureText(TestRemoteRepository):
2490
 
 
2491
 
    def test_add_signature_text(self):
2492
 
        transport_path = 'quack'
2493
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2494
 
        client.add_expected_call(
2495
 
            'Repository.lock_write', ('quack/', ''),
2496
 
            'success', ('ok', 'a token'))
2497
 
        client.add_expected_call(
2498
 
            'Repository.start_write_group', ('quack/', 'a token'),
2499
 
            'success', ('ok', ('token1', )))
2500
 
        client.add_expected_call(
2501
 
            'Repository.add_signature_text', ('quack/', 'a token', 'rev1',
2502
 
                'token1'),
2503
 
            'success', ('ok', ), None)
2504
 
        repo.lock_write()
2505
 
        repo.start_write_group()
2506
 
        self.assertIs(None,
2507
 
            repo.add_signature_text("rev1", "every bloody emperor"))
2508
 
        self.assertEqual(
2509
 
            ('call_with_body_bytes_expecting_body',
2510
 
              'Repository.add_signature_text',
2511
 
                ('quack/', 'a token', 'rev1', 'token1'),
2512
 
              'every bloody emperor'),
2513
 
            client._calls[-1])
2514
 
 
2515
 
 
2516
2095
class TestRepositoryGetParentMap(TestRemoteRepository):
2517
2096
 
2518
2097
    def test_get_parent_map_caching(self):
2568
2147
        parents = repo.get_parent_map([rev_id])
2569
2148
        self.assertEqual(
2570
2149
            [('call_with_body_bytes_expecting_body',
2571
 
              'Repository.get_parent_map',
2572
 
              ('quack/', 'include-missing:', rev_id), '\n\n0'),
 
2150
              'Repository.get_parent_map', ('quack/', 'include-missing:',
 
2151
              rev_id), '\n\n0'),
2573
2152
             ('disconnect medium',),
2574
2153
             ('call_expecting_body', 'Repository.get_revision_graph',
2575
2154
              ('quack/', ''))],
2695
2274
        self.assertEqual({}, repo.get_parent_map(['non-existant']))
2696
2275
        self.assertLength(0, self.hpss_calls)
2697
2276
 
2698
 
    def test_exposes_get_cached_parent_map(self):
2699
 
        """RemoteRepository exposes get_cached_parent_map from
2700
 
        _unstacked_provider
2701
 
        """
2702
 
        r1 = u'\u0e33'.encode('utf8')
2703
 
        r2 = u'\u0dab'.encode('utf8')
2704
 
        lines = [' '.join([r2, r1]), r1]
2705
 
        encoded_body = bz2.compress('\n'.join(lines))
2706
 
 
2707
 
        transport_path = 'quack'
2708
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2709
 
        client.add_success_response_with_body(encoded_body, 'ok')
2710
 
        repo.lock_read()
2711
 
        # get_cached_parent_map should *not* trigger an RPC
2712
 
        self.assertEqual({}, repo.get_cached_parent_map([r1]))
2713
 
        self.assertEqual([], client._calls)
2714
 
        self.assertEqual({r2: (r1,)}, repo.get_parent_map([r2]))
2715
 
        self.assertEqual({r1: (NULL_REVISION,)},
2716
 
            repo.get_cached_parent_map([r1]))
2717
 
        self.assertEqual(
2718
 
            [('call_with_body_bytes_expecting_body',
2719
 
              'Repository.get_parent_map', ('quack/', 'include-missing:', r2),
2720
 
              '\n\n0')],
2721
 
            client._calls)
2722
 
        repo.unlock()
2723
 
 
2724
2277
 
2725
2278
class TestGetParentMapAllowsNew(tests.TestCaseWithTransport):
2726
2279
 
2741
2294
        self.assertEqual({'rev1': ('null:',)}, graph.get_parent_map(['rev1']))
2742
2295
 
2743
2296
 
2744
 
class TestRepositoryGetRevisions(TestRemoteRepository):
2745
 
 
2746
 
    def test_hpss_missing_revision(self):
2747
 
        transport_path = 'quack'
2748
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2749
 
        client.add_success_response_with_body(
2750
 
            '', 'ok', '10')
2751
 
        self.assertRaises(errors.NoSuchRevision, repo.get_revisions,
2752
 
            ['somerev1', 'anotherrev2'])
2753
 
        self.assertEqual(
2754
 
            [('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2755
 
             ('quack/', ), "somerev1\nanotherrev2")],
2756
 
            client._calls)
2757
 
 
2758
 
    def test_hpss_get_single_revision(self):
2759
 
        transport_path = 'quack'
2760
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2761
 
        somerev1 = Revision("somerev1")
2762
 
        somerev1.committer = "Joe Committer <joe@example.com>"
2763
 
        somerev1.timestamp = 1321828927
2764
 
        somerev1.timezone = -60
2765
 
        somerev1.inventory_sha1 = "691b39be74c67b1212a75fcb19c433aaed903c2b"
2766
 
        somerev1.message = "Message"
2767
 
        body = zlib.compress(chk_bencode_serializer.write_revision_to_string(
2768
 
            somerev1))
2769
 
        # Split up body into two bits to make sure the zlib compression object
2770
 
        # gets data fed twice.
2771
 
        client.add_success_response_with_body(
2772
 
                [body[:10], body[10:]], 'ok', '10')
2773
 
        revs = repo.get_revisions(['somerev1'])
2774
 
        self.assertEqual(revs, [somerev1])
2775
 
        self.assertEqual(
2776
 
            [('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2777
 
             ('quack/', ), "somerev1")],
2778
 
            client._calls)
2779
 
 
2780
 
 
2781
2297
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
2782
2298
 
2783
2299
    def test_null_revision(self):
2934
2450
                              call.call.method == verb])
2935
2451
 
2936
2452
 
2937
 
class TestRepositoryHasSignatureForRevisionId(TestRemoteRepository):
2938
 
 
2939
 
    def test_has_signature_for_revision_id(self):
2940
 
        # ('yes', ) for Repository.has_signature_for_revision_id -> 'True'.
2941
 
        transport_path = 'quack'
2942
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2943
 
        client.add_success_response('yes')
2944
 
        result = repo.has_signature_for_revision_id('A')
2945
 
        self.assertEqual(
2946
 
            [('call', 'Repository.has_signature_for_revision_id',
2947
 
              ('quack/', 'A'))],
2948
 
            client._calls)
2949
 
        self.assertEqual(True, result)
2950
 
 
2951
 
    def test_is_not_shared(self):
2952
 
        # ('no', ) for Repository.has_signature_for_revision_id -> 'False'.
2953
 
        transport_path = 'qwack'
2954
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2955
 
        client.add_success_response('no')
2956
 
        result = repo.has_signature_for_revision_id('A')
2957
 
        self.assertEqual(
2958
 
            [('call', 'Repository.has_signature_for_revision_id',
2959
 
              ('qwack/', 'A'))],
2960
 
            client._calls)
2961
 
        self.assertEqual(False, result)
2962
 
 
2963
 
 
2964
 
class TestRepositoryPhysicalLockStatus(TestRemoteRepository):
2965
 
 
2966
 
    def test_get_physical_lock_status_yes(self):
2967
 
        transport_path = 'qwack'
2968
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2969
 
        client.add_success_response('yes')
2970
 
        result = repo.get_physical_lock_status()
2971
 
        self.assertEqual(
2972
 
            [('call', 'Repository.get_physical_lock_status',
2973
 
              ('qwack/', ))],
2974
 
            client._calls)
2975
 
        self.assertEqual(True, result)
2976
 
 
2977
 
    def test_get_physical_lock_status_no(self):
2978
 
        transport_path = 'qwack'
2979
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2980
 
        client.add_success_response('no')
2981
 
        result = repo.get_physical_lock_status()
2982
 
        self.assertEqual(
2983
 
            [('call', 'Repository.get_physical_lock_status',
2984
 
              ('qwack/', ))],
2985
 
            client._calls)
2986
 
        self.assertEqual(False, result)
2987
 
 
2988
 
 
2989
2453
class TestRepositoryIsShared(TestRemoteRepository):
2990
2454
 
2991
2455
    def test_is_shared(self):
3011
2475
        self.assertEqual(False, result)
3012
2476
 
3013
2477
 
3014
 
class TestRepositoryMakeWorkingTrees(TestRemoteRepository):
3015
 
 
3016
 
    def test_make_working_trees(self):
3017
 
        # ('yes', ) for Repository.make_working_trees -> 'True'.
3018
 
        transport_path = 'quack'
3019
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3020
 
        client.add_success_response('yes')
3021
 
        result = repo.make_working_trees()
3022
 
        self.assertEqual(
3023
 
            [('call', 'Repository.make_working_trees', ('quack/',))],
3024
 
            client._calls)
3025
 
        self.assertEqual(True, result)
3026
 
 
3027
 
    def test_no_working_trees(self):
3028
 
        # ('no', ) for Repository.make_working_trees -> 'False'.
3029
 
        transport_path = 'qwack'
3030
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3031
 
        client.add_success_response('no')
3032
 
        result = repo.make_working_trees()
3033
 
        self.assertEqual(
3034
 
            [('call', 'Repository.make_working_trees', ('qwack/',))],
3035
 
            client._calls)
3036
 
        self.assertEqual(False, result)
3037
 
 
3038
 
 
3039
2478
class TestRepositoryLockWrite(TestRemoteRepository):
3040
2479
 
3041
2480
    def test_lock_write(self):
3067
2506
            client._calls)
3068
2507
 
3069
2508
 
3070
 
class TestRepositoryWriteGroups(TestRemoteRepository):
3071
 
 
3072
 
    def test_start_write_group(self):
3073
 
        transport_path = 'quack'
3074
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3075
 
        client.add_expected_call(
3076
 
            'Repository.lock_write', ('quack/', ''),
3077
 
            'success', ('ok', 'a token'))
3078
 
        client.add_expected_call(
3079
 
            'Repository.start_write_group', ('quack/', 'a token'),
3080
 
            'success', ('ok', ('token1', )))
3081
 
        repo.lock_write()
3082
 
        repo.start_write_group()
3083
 
 
3084
 
    def test_start_write_group_unsuspendable(self):
3085
 
        # Some repositories do not support suspending write
3086
 
        # groups. For those, fall back to the "real" repository.
3087
 
        transport_path = 'quack'
3088
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3089
 
        def stub_ensure_real():
3090
 
            client._calls.append(('_ensure_real',))
3091
 
            repo._real_repository = _StubRealPackRepository(client._calls)
3092
 
        repo._ensure_real = stub_ensure_real
3093
 
        client.add_expected_call(
3094
 
            'Repository.lock_write', ('quack/', ''),
3095
 
            'success', ('ok', 'a token'))
3096
 
        client.add_expected_call(
3097
 
            'Repository.start_write_group', ('quack/', 'a token'),
3098
 
            'error', ('UnsuspendableWriteGroup',))
3099
 
        repo.lock_write()
3100
 
        repo.start_write_group()
3101
 
        self.assertEqual(client._calls[-2:], [ 
3102
 
            ('_ensure_real',),
3103
 
            ('start_write_group',)])
3104
 
 
3105
 
    def test_commit_write_group(self):
3106
 
        transport_path = 'quack'
3107
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3108
 
        client.add_expected_call(
3109
 
            'Repository.lock_write', ('quack/', ''),
3110
 
            'success', ('ok', 'a token'))
3111
 
        client.add_expected_call(
3112
 
            'Repository.start_write_group', ('quack/', 'a token'),
3113
 
            'success', ('ok', ['token1']))
3114
 
        client.add_expected_call(
3115
 
            'Repository.commit_write_group', ('quack/', 'a token', ['token1']),
3116
 
            'success', ('ok',))
3117
 
        repo.lock_write()
3118
 
        repo.start_write_group()
3119
 
        repo.commit_write_group()
3120
 
 
3121
 
    def test_abort_write_group(self):
3122
 
        transport_path = 'quack'
3123
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3124
 
        client.add_expected_call(
3125
 
            'Repository.lock_write', ('quack/', ''),
3126
 
            'success', ('ok', 'a token'))
3127
 
        client.add_expected_call(
3128
 
            'Repository.start_write_group', ('quack/', 'a token'),
3129
 
            'success', ('ok', ['token1']))
3130
 
        client.add_expected_call(
3131
 
            'Repository.abort_write_group', ('quack/', 'a token', ['token1']),
3132
 
            'success', ('ok',))
3133
 
        repo.lock_write()
3134
 
        repo.start_write_group()
3135
 
        repo.abort_write_group(False)
3136
 
 
3137
 
    def test_suspend_write_group(self):
3138
 
        transport_path = 'quack'
3139
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3140
 
        self.assertEqual([], repo.suspend_write_group())
3141
 
 
3142
 
    def test_resume_write_group(self):
3143
 
        transport_path = 'quack'
3144
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3145
 
        client.add_expected_call(
3146
 
            'Repository.lock_write', ('quack/', ''),
3147
 
            'success', ('ok', 'a token'))
3148
 
        client.add_expected_call(
3149
 
            'Repository.check_write_group', ('quack/', 'a token', ['token1']),
3150
 
            'success', ('ok',))
3151
 
        repo.lock_write()
3152
 
        repo.resume_write_group(['token1'])
3153
 
 
3154
 
 
3155
2509
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
3156
2510
 
3157
2511
    def test_backwards_compat(self):
3216
2570
        self.assertEqual([], client._calls)
3217
2571
 
3218
2572
 
3219
 
class TestRepositoryIterFilesBytes(TestRemoteRepository):
3220
 
    """Test Repository.iter_file_bytes."""
3221
 
 
3222
 
    def test_single(self):
3223
 
        transport_path = 'quack'
3224
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3225
 
        client.add_expected_call(
3226
 
            'Repository.iter_files_bytes', ('quack/', ),
3227
 
            'success', ('ok',), iter(["ok\x000", "\n", zlib.compress("mydata" * 10)]))
3228
 
        for (identifier, byte_stream) in repo.iter_files_bytes([("somefile",
3229
 
                "somerev", "myid")]):
3230
 
            self.assertEqual("myid", identifier)
3231
 
            self.assertEqual("".join(byte_stream), "mydata" * 10)
3232
 
 
3233
 
    def test_missing(self):
3234
 
        transport_path = 'quack'
3235
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3236
 
        client.add_expected_call(
3237
 
            'Repository.iter_files_bytes',
3238
 
                ('quack/', ),
3239
 
            'error', ('RevisionNotPresent', 'somefile', 'somerev'),
3240
 
            iter(["absent\0somefile\0somerev\n"]))
3241
 
        self.assertRaises(errors.RevisionNotPresent, list,
3242
 
                repo.iter_files_bytes(
3243
 
                [("somefile", "somerev", "myid")]))
3244
 
 
3245
 
 
3246
2573
class TestRepositoryInsertStreamBase(TestRemoteRepository):
3247
2574
    """Base class for Repository.insert_stream and .insert_stream_1.19
3248
2575
    tests.
3270
2597
    """
3271
2598
 
3272
2599
    def setUp(self):
3273
 
        super(TestRepositoryInsertStream, self).setUp()
 
2600
        TestRemoteRepository.setUp(self)
3274
2601
        self.disable_verb('Repository.insert_stream_1.19')
3275
2602
 
3276
2603
    def test_unlocked_repo(self):
3523
2850
        self.calls = calls
3524
2851
        self._pack_collection = _StubPackCollection(calls)
3525
2852
 
3526
 
    def start_write_group(self):
3527
 
        self.calls.append(('start_write_group',))
3528
 
 
3529
2853
    def is_in_write_group(self):
3530
2854
        return False
3531
2855
 
3955
3279
        :result: The revision ids in the stream, in the order seen,
3956
3280
            the topological order of revisions in the source.
3957
3281
        """
3958
 
        unordered_format = controldir.format_registry.get(format)()
 
3282
        unordered_format = bzrdir.format_registry.get(format)()
3959
3283
        target_repository_format = unordered_format.repository_format
3960
3284
        # Cross check
3961
3285
        self.assertEqual(order, target_repository_format._fetch_order)
3969
3293
        revs = [r for (r,ps) in graph.iter_ancestry([tip])
3970
3294
                if r != NULL_REVISION]
3971
3295
        revs.reverse()
3972
 
        search = vf_search.PendingAncestryResult([tip], stacked.repository)
 
3296
        search = _mod_graph.PendingAncestryResult([tip], stacked.repository)
3973
3297
        self.reset_smart_call_log()
3974
3298
        stream = source.get_stream(search)
3975
3299
        # We trust that if a revision is in the stream the rest of the new
4081
3405
        self.hpss_calls = []
4082
3406
        local.repository.fetch(
4083
3407
            remote_branch.repository,
4084
 
            fetch_spec=vf_search.EverythingResult(remote_branch.repository))
 
3408
            fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
4085
3409
        self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
4086
3410
 
4087
3411
    def override_verb(self, verb_name, verb):
4088
3412
        request_handlers = request.request_handlers
4089
3413
        orig_verb = request_handlers.get(verb_name)
4090
 
        orig_info = request_handlers.get_info(verb_name)
4091
3414
        request_handlers.register(verb_name, verb, override_existing=True)
4092
3415
        self.addCleanup(request_handlers.register, verb_name, orig_verb,
4093
 
                override_existing=True, info=orig_info)
 
3416
                override_existing=True)
4094
3417
 
4095
3418
    def test_fetch_everything_backwards_compat(self):
4096
3419
        """Can fetch with EverythingResult even with pre 2.4 servers.
4121
3444
        self.hpss_calls = []
4122
3445
        local.repository.fetch(
4123
3446
            remote_branch.repository,
4124
 
            fetch_spec=vf_search.EverythingResult(remote_branch.repository))
 
3447
            fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
4125
3448
        # make sure the overridden verb was used
4126
3449
        self.assertLength(1, verb_log)
4127
3450
        # more than one HPSS call is needed, but because it's a VFS callback
4154
3477
    def assertUpdateSucceeds(self, new_location):
4155
3478
        self.checkout.branch.set_bound_location(new_location)
4156
3479
        self.checkout.update()
4157
 
        self.assertEqual(self.last_revid, self.checkout.last_revision())
 
3480
        self.assertEquals(self.last_revid, self.checkout.last_revision())
4158
3481
 
4159
3482
    def test_without_final_slash(self):
4160
3483
        self.make_master_and_checkout('master', 'checkout')
4172
3495
        # interpretation
4173
3496
        self.make_master_and_checkout('mas~ter', 'checkout')
4174
3497
        self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
4175
 
 
4176
 
 
4177
 
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4178
 
 
4179
 
    def test_no_context(self):
4180
 
        class OutOfCoffee(errors.BzrError):
4181
 
            """A dummy exception for testing."""
4182
 
 
4183
 
            def __init__(self, urgency):
4184
 
                self.urgency = urgency
4185
 
        remote.no_context_error_translators.register("OutOfCoffee",
4186
 
            lambda err: OutOfCoffee(err.error_args[0]))
4187
 
        transport = MemoryTransport()
4188
 
        client = FakeClient(transport.base)
4189
 
        client.add_expected_call(
4190
 
            'Branch.get_stacked_on_url', ('quack/',),
4191
 
            'error', ('NotStacked',))
4192
 
        client.add_expected_call(
4193
 
            'Branch.last_revision_info',
4194
 
            ('quack/',),
4195
 
            'error', ('OutOfCoffee', 'low'))
4196
 
        transport.mkdir('quack')
4197
 
        transport = transport.clone('quack')
4198
 
        branch = self.make_remote_branch(transport, client)
4199
 
        self.assertRaises(OutOfCoffee, branch.last_revision_info)
4200
 
        self.assertFinished(client)
4201
 
 
4202
 
    def test_with_context(self):
4203
 
        class OutOfTea(errors.BzrError):
4204
 
            def __init__(self, branch, urgency):
4205
 
                self.branch = branch
4206
 
                self.urgency = urgency
4207
 
        remote.error_translators.register("OutOfTea",
4208
 
            lambda err, find, path: OutOfTea(err.error_args[0],
4209
 
                find("branch")))
4210
 
        transport = MemoryTransport()
4211
 
        client = FakeClient(transport.base)
4212
 
        client.add_expected_call(
4213
 
            'Branch.get_stacked_on_url', ('quack/',),
4214
 
            'error', ('NotStacked',))
4215
 
        client.add_expected_call(
4216
 
            'Branch.last_revision_info',
4217
 
            ('quack/',),
4218
 
            'error', ('OutOfTea', 'low'))
4219
 
        transport.mkdir('quack')
4220
 
        transport = transport.clone('quack')
4221
 
        branch = self.make_remote_branch(transport, client)
4222
 
        self.assertRaises(OutOfTea, branch.last_revision_info)
4223
 
        self.assertFinished(client)
4224
 
 
4225
 
 
4226
 
class TestRepositoryPack(TestRemoteRepository):
4227
 
 
4228
 
    def test_pack(self):
4229
 
        transport_path = 'quack'
4230
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4231
 
        client.add_expected_call(
4232
 
            'Repository.lock_write', ('quack/', ''),
4233
 
            'success', ('ok', 'token'))
4234
 
        client.add_expected_call(
4235
 
            'Repository.pack', ('quack/', 'token', 'False'),
4236
 
            'success', ('ok',), )
4237
 
        client.add_expected_call(
4238
 
            'Repository.unlock', ('quack/', 'token'),
4239
 
            'success', ('ok', ))
4240
 
        repo.pack()
4241
 
 
4242
 
    def test_pack_with_hint(self):
4243
 
        transport_path = 'quack'
4244
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4245
 
        client.add_expected_call(
4246
 
            'Repository.lock_write', ('quack/', ''),
4247
 
            'success', ('ok', 'token'))
4248
 
        client.add_expected_call(
4249
 
            'Repository.pack', ('quack/', 'token', 'False'),
4250
 
            'success', ('ok',), )
4251
 
        client.add_expected_call(
4252
 
            'Repository.unlock', ('quack/', 'token', 'False'),
4253
 
            'success', ('ok', ))
4254
 
        repo.pack(['hinta', 'hintb'])
4255
 
 
4256
 
 
4257
 
class TestRepositoryIterInventories(TestRemoteRepository):
4258
 
    """Test Repository.iter_inventories."""
4259
 
 
4260
 
    def _serialize_inv_delta(self, old_name, new_name, delta):
4261
 
        serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4262
 
        return "".join(serializer.delta_to_lines(old_name, new_name, delta))
4263
 
 
4264
 
    def test_single_empty(self):
4265
 
        transport_path = 'quack'
4266
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4267
 
        fmt = controldir.format_registry.get('2a')().repository_format
4268
 
        repo._format = fmt
4269
 
        stream = [('inventory-deltas', [
4270
 
            versionedfile.FulltextContentFactory('somerevid', None, None,
4271
 
                self._serialize_inv_delta('null:', 'somerevid', []))])]
4272
 
        client.add_expected_call(
4273
 
            'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4274
 
            'success', ('ok', ),
4275
 
            _stream_to_byte_stream(stream, fmt))
4276
 
        ret = list(repo.iter_inventories(["somerevid"]))
4277
 
        self.assertLength(1, ret)
4278
 
        inv = ret[0]
4279
 
        self.assertEqual("somerevid", inv.revision_id)
4280
 
 
4281
 
    def test_empty(self):
4282
 
        transport_path = 'quack'
4283
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4284
 
        ret = list(repo.iter_inventories([]))
4285
 
        self.assertEqual(ret, [])
4286
 
 
4287
 
    def test_missing(self):
4288
 
        transport_path = 'quack'
4289
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4290
 
        client.add_expected_call(
4291
 
            'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4292
 
            'success', ('ok', ), iter([]))
4293
 
        self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(
4294
 
            ["somerevid"]))