~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_remote.py

(gz) Never raise KnownFailure in tests,
 use knownFailure method instead (Martin [gz])

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import bz2
27
27
from cStringIO import StringIO
28
 
import zlib
29
28
 
30
29
from bzrlib import (
31
30
    branch,
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
66
    )
73
 
from bzrlib.symbol_versioning import deprecated_in
74
67
from bzrlib.tests import (
75
68
    test_server,
76
69
    )
122
115
 
123
116
    def test_remote_branch_revision_history(self):
124
117
        b = BzrDir.open_from_transport(self.transport).open_branch()
125
 
        self.assertEqual([],
126
 
            self.applyDeprecated(deprecated_in((2, 5, 0)), b.revision_history))
 
118
        self.assertEqual([], b.revision_history())
127
119
        r1 = self.local_wt.commit('1st commit')
128
120
        r2 = self.local_wt.commit('1st commit', rev_id=u'\xc8'.encode('utf8'))
129
 
        self.assertEqual([r1, r2],
130
 
            self.applyDeprecated(deprecated_in((2, 5, 0)), b.revision_history))
 
121
        self.assertEqual([r1, r2], b.revision_history())
131
122
 
132
123
    def test_find_correct_format(self):
133
124
        """Should open a RemoteBzrDir over a RemoteTransport"""
490
481
        self.assertEqual(None, result._branch_format)
491
482
        self.assertFinished(client)
492
483
 
493
 
    def test_unknown(self):
494
 
        transport = self.get_transport('quack')
495
 
        referenced = self.make_branch('referenced')
496
 
        expected = referenced.bzrdir.cloning_metadir()
497
 
        client = FakeClient(transport.base)
498
 
        client.add_expected_call(
499
 
            'BzrDir.cloning_metadir', ('quack/', 'False'),
500
 
            'success', ('unknown', 'unknown', ('branch', ''))),
501
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
502
 
            _client=client)
503
 
        self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
504
 
 
505
 
 
506
 
class TestBzrDirDestroyBranch(TestRemote):
507
 
 
508
 
    def test_destroy_default(self):
509
 
        transport = self.get_transport('quack')
510
 
        referenced = self.make_branch('referenced')
511
 
        client = FakeClient(transport.base)
512
 
        client.add_expected_call(
513
 
            'BzrDir.destroy_branch', ('quack/', ),
514
 
            'success', ('ok',)),
515
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
516
 
            _client=client)
517
 
        a_bzrdir.destroy_branch()
518
 
        self.assertFinished(client)
519
 
 
520
 
    def test_destroy_named(self):
521
 
        transport = self.get_transport('quack')
522
 
        referenced = self.make_branch('referenced')
523
 
        client = FakeClient(transport.base)
524
 
        client.add_expected_call(
525
 
            'BzrDir.destroy_branch', ('quack/', "foo"),
526
 
            'success', ('ok',)),
527
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
528
 
            _client=client)
529
 
        a_bzrdir.destroy_branch("foo")
530
 
        self.assertFinished(client)
531
 
 
532
 
 
533
 
class TestBzrDirHasWorkingTree(TestRemote):
534
 
 
535
 
    def test_has_workingtree(self):
536
 
        transport = self.get_transport('quack')
537
 
        client = FakeClient(transport.base)
538
 
        client.add_expected_call(
539
 
            'BzrDir.has_workingtree', ('quack/',),
540
 
            'success', ('yes',)),
541
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
542
 
            _client=client)
543
 
        self.assertTrue(a_bzrdir.has_workingtree())
544
 
        self.assertFinished(client)
545
 
 
546
 
    def test_no_workingtree(self):
547
 
        transport = self.get_transport('quack')
548
 
        client = FakeClient(transport.base)
549
 
        client.add_expected_call(
550
 
            'BzrDir.has_workingtree', ('quack/',),
551
 
            'success', ('no',)),
552
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
553
 
            _client=client)
554
 
        self.assertFalse(a_bzrdir.has_workingtree())
555
 
        self.assertFinished(client)
556
 
 
557
 
 
558
 
class TestBzrDirDestroyRepository(TestRemote):
559
 
 
560
 
    def test_destroy_repository(self):
561
 
        transport = self.get_transport('quack')
562
 
        client = FakeClient(transport.base)
563
 
        client.add_expected_call(
564
 
            'BzrDir.destroy_repository', ('quack/',),
565
 
            'success', ('ok',)),
566
 
        a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
567
 
            _client=client)
568
 
        a_bzrdir.destroy_repository()
569
 
        self.assertFinished(client)
570
 
 
571
484
 
572
485
class TestBzrDirOpen(TestRemote):
573
486
 
697
610
        # _get_tree_branch is a form of open_branch, but it should only ask for
698
611
        # branch opening, not any other network requests.
699
612
        calls = []
700
 
        def open_branch(name=None, possible_transports=None):
 
613
        def open_branch(name=None):
701
614
            calls.append("Called")
702
615
            return "a-branch"
703
616
        transport = MemoryTransport()
1083
996
        return RemoteBranch(bzrdir, repo, _client=client, format=format)
1084
997
 
1085
998
 
1086
 
class TestBranchBreakLock(RemoteBranchTestCase):
1087
 
 
1088
 
    def test_break_lock(self):
1089
 
        transport_path = 'quack'
1090
 
        transport = MemoryTransport()
1091
 
        client = FakeClient(transport.base)
1092
 
        client.add_expected_call(
1093
 
            'Branch.get_stacked_on_url', ('quack/',),
1094
 
            'error', ('NotStacked',))
1095
 
        client.add_expected_call(
1096
 
            'Branch.break_lock', ('quack/',),
1097
 
            'success', ('ok',))
1098
 
        transport.mkdir('quack')
1099
 
        transport = transport.clone('quack')
1100
 
        branch = self.make_remote_branch(transport, client)
1101
 
        branch.break_lock()
1102
 
        self.assertFinished(client)
1103
 
 
1104
 
 
1105
 
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1106
 
 
1107
 
    def test_get_physical_lock_status_yes(self):
1108
 
        transport = MemoryTransport()
1109
 
        client = FakeClient(transport.base)
1110
 
        client.add_expected_call(
1111
 
            'Branch.get_stacked_on_url', ('quack/',),
1112
 
            'error', ('NotStacked',))
1113
 
        client.add_expected_call(
1114
 
            'Branch.get_physical_lock_status', ('quack/',),
1115
 
            'success', ('yes',))
1116
 
        transport.mkdir('quack')
1117
 
        transport = transport.clone('quack')
1118
 
        branch = self.make_remote_branch(transport, client)
1119
 
        result = branch.get_physical_lock_status()
1120
 
        self.assertFinished(client)
1121
 
        self.assertEqual(True, result)
1122
 
 
1123
 
    def test_get_physical_lock_status_no(self):
1124
 
        transport = MemoryTransport()
1125
 
        client = FakeClient(transport.base)
1126
 
        client.add_expected_call(
1127
 
            'Branch.get_stacked_on_url', ('quack/',),
1128
 
            'error', ('NotStacked',))
1129
 
        client.add_expected_call(
1130
 
            'Branch.get_physical_lock_status', ('quack/',),
1131
 
            'success', ('no',))
1132
 
        transport.mkdir('quack')
1133
 
        transport = transport.clone('quack')
1134
 
        branch = self.make_remote_branch(transport, client)
1135
 
        result = branch.get_physical_lock_status()
1136
 
        self.assertFinished(client)
1137
 
        self.assertEqual(False, result)
1138
 
 
1139
 
 
1140
999
class TestBranchGetParent(RemoteBranchTestCase):
1141
1000
 
1142
1001
    def test_no_parent(self):
1324
1183
        client.add_expected_call(
1325
1184
            'Branch.last_revision_info', ('quack/',),
1326
1185
            'success', ('ok', '1', 'rev-tip'))
1327
 
        client.add_expected_call(
1328
 
            'Branch.get_config_file', ('quack/',),
1329
 
            'success', ('ok',), '')
1330
 
        transport.mkdir('quack')
1331
 
        transport = transport.clone('quack')
1332
 
        branch = self.make_remote_branch(transport, client)
1333
 
        result = branch.heads_to_fetch()
1334
 
        self.assertFinished(client)
1335
 
        self.assertEqual((set(['rev-tip']), set()), result)
1336
 
 
1337
 
    def test_uses_last_revision_info_and_tags_when_set(self):
1338
 
        transport = MemoryTransport()
1339
 
        client = FakeClient(transport.base)
1340
 
        client.add_expected_call(
1341
 
            'Branch.get_stacked_on_url', ('quack/',),
1342
 
            'error', ('NotStacked',))
1343
 
        client.add_expected_call(
1344
 
            'Branch.last_revision_info', ('quack/',),
1345
 
            'success', ('ok', '1', 'rev-tip'))
1346
 
        client.add_expected_call(
1347
 
            'Branch.get_config_file', ('quack/',),
1348
 
            'success', ('ok',), 'branch.fetch_tags = True')
1349
1186
        # XXX: this will break if the default format's serialization of tags
1350
1187
        # changes, or if the RPC for fetching tags changes from get_tags_bytes.
1351
1188
        client.add_expected_call(
1376
1213
        self.assertFinished(client)
1377
1214
        self.assertEqual((set(['tip']), set(['tagged-1', 'tagged-2'])), result)
1378
1215
 
1379
 
    def make_branch_with_tags(self):
 
1216
    def test_backwards_compatible(self):
1380
1217
        self.setup_smart_server_with_call_log()
1381
1218
        # Make a branch with a single revision.
1382
1219
        builder = self.make_branch_builder('foo')
1388
1225
        # Add two tags to that branch
1389
1226
        branch.tags.set_tag('tag-1', 'rev-1')
1390
1227
        branch.tags.set_tag('tag-2', 'rev-2')
1391
 
        return branch
1392
 
 
1393
 
    def test_backwards_compatible(self):
1394
 
        branch = self.make_branch_with_tags()
1395
 
        c = branch.get_config()
1396
 
        c.set_user_option('branch.fetch_tags', 'True')
1397
1228
        self.addCleanup(branch.lock_read().unlock)
1398
1229
        # Disable the heads_to_fetch verb
1399
1230
        verb = 'Branch.heads_to_fetch'
1402
1233
        result = branch.heads_to_fetch()
1403
1234
        self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1404
1235
        self.assertEqual(
1405
 
            ['Branch.last_revision_info', 'Branch.get_config_file',
1406
 
             'Branch.get_tags_bytes'],
1407
 
            [call.call.method for call in self.hpss_calls])
1408
 
 
1409
 
    def test_backwards_compatible_no_tags(self):
1410
 
        branch = self.make_branch_with_tags()
1411
 
        c = branch.get_config()
1412
 
        c.set_user_option('branch.fetch_tags', 'False')
1413
 
        self.addCleanup(branch.lock_read().unlock)
1414
 
        # Disable the heads_to_fetch verb
1415
 
        verb = 'Branch.heads_to_fetch'
1416
 
        self.disable_verb(verb)
1417
 
        self.reset_smart_call_log()
1418
 
        result = branch.heads_to_fetch()
1419
 
        self.assertEqual((set(['tip']), set()), result)
1420
 
        self.assertEqual(
1421
 
            ['Branch.last_revision_info', 'Branch.get_config_file'],
 
1236
            ['Branch.last_revision_info', 'Branch.get_tags_bytes'],
1422
1237
            [call.call.method for call in self.hpss_calls])
1423
1238
 
1424
1239
 
1586
1401
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1587
1402
            'success', ('ok',))
1588
1403
        branch = self.make_remote_branch(transport, client)
 
1404
        # This is a hack to work around the problem that RemoteBranch currently
 
1405
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 
1406
        branch._ensure_real = lambda: None
1589
1407
        branch.lock_write()
1590
1408
        result = branch._set_last_revision(NULL_REVISION)
1591
1409
        branch.unlock()
1620
1438
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1621
1439
            'success', ('ok',))
1622
1440
        branch = self.make_remote_branch(transport, client)
 
1441
        # This is a hack to work around the problem that RemoteBranch currently
 
1442
        # unnecessarily invokes _ensure_real upon a call to lock_write.
 
1443
        branch._ensure_real = lambda: None
1623
1444
        # Lock the branch, reset the record of remote calls.
1624
1445
        branch.lock_write()
1625
1446
        result = branch._set_last_revision('rev-id2')
1692
1513
            'Branch.unlock', ('branch/', 'branch token', 'repo token'),
1693
1514
            'success', ('ok',))
1694
1515
        branch = self.make_remote_branch(transport, client)
 
1516
        branch._ensure_real = lambda: None
1695
1517
        branch.lock_write()
1696
1518
        # The 'TipChangeRejected' error response triggered by calling
1697
1519
        # set_last_revision_info causes a TipChangeRejected exception.
1978
1800
        self.assertEqual(value_dict, branch._get_config().get_option('name'))
1979
1801
 
1980
1802
 
1981
 
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
1982
 
 
1983
 
    def test_get_branch_conf(self):
1984
 
        # in an empty branch we decode the response properly
1985
 
        client = FakeClient()
1986
 
        client.add_expected_call(
1987
 
            'Branch.get_stacked_on_url', ('memory:///',),
1988
 
            'error', ('NotStacked',),)
1989
 
        client.add_success_response_with_body('# config file body', 'ok')
1990
 
        transport = MemoryTransport()
1991
 
        branch = self.make_remote_branch(transport, client)
1992
 
        config = branch.get_config_stack()
1993
 
        config.get("email")
1994
 
        config.get("log_format")
1995
 
        self.assertEqual(
1996
 
            [('call', 'Branch.get_stacked_on_url', ('memory:///',)),
1997
 
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
1998
 
            client._calls)
1999
 
 
2000
 
    def test_set_branch_conf(self):
2001
 
        client = FakeClient()
2002
 
        client.add_expected_call(
2003
 
            'Branch.get_stacked_on_url', ('memory:///',),
2004
 
            'error', ('NotStacked',),)
2005
 
        client.add_expected_call(
2006
 
            'Branch.lock_write', ('memory:///', '', ''),
2007
 
            'success', ('ok', 'branch token', 'repo token'))
2008
 
        client.add_expected_call(
2009
 
            'Branch.get_config_file', ('memory:///', ),
2010
 
            'success', ('ok', ), "# line 1\n")
2011
 
        client.add_expected_call(
2012
 
            'Branch.put_config_file', ('memory:///', 'branch token',
2013
 
            'repo token'),
2014
 
            'success', ('ok',))
2015
 
        client.add_expected_call(
2016
 
            'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
2017
 
            'success', ('ok',))
2018
 
        transport = MemoryTransport()
2019
 
        branch = self.make_remote_branch(transport, client)
2020
 
        branch.lock_write()
2021
 
        config = branch.get_config_stack()
2022
 
        config.set('email', 'The Dude <lebowski@example.com>')
2023
 
        branch.unlock()
2024
 
        self.assertFinished(client)
2025
 
        self.assertEqual(
2026
 
            [('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2027
 
             ('call', 'Branch.lock_write', ('memory:///', '', '')),
2028
 
             ('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2029
 
             ('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2030
 
                 ('memory:///', 'branch token', 'repo token'),
2031
 
                 '# line 1\nemail = The Dude <lebowski@example.com>\n'),
2032
 
             ('call', 'Branch.unlock', ('memory:///', 'branch token', 'repo token'))],
2033
 
            client._calls)
2034
 
 
2035
 
 
2036
1803
class TestBranchLockWrite(RemoteBranchTestCase):
2037
1804
 
2038
1805
    def test_lock_write_unlockable(self):
2051
1818
        self.assertFinished(client)
2052
1819
 
2053
1820
 
2054
 
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
2055
 
 
2056
 
    def test_simple(self):
2057
 
        transport = MemoryTransport()
2058
 
        client = FakeClient(transport.base)
2059
 
        client.add_expected_call(
2060
 
            'Branch.get_stacked_on_url', ('quack/',),
2061
 
            'error', ('NotStacked',),)
2062
 
        client.add_expected_call(
2063
 
            'Branch.revision_id_to_revno', ('quack/', 'null:'),
2064
 
            'success', ('ok', '0',),)
2065
 
        client.add_expected_call(
2066
 
            'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2067
 
            'error', ('NoSuchRevision', 'unknown',),)
2068
 
        transport.mkdir('quack')
2069
 
        transport = transport.clone('quack')
2070
 
        branch = self.make_remote_branch(transport, client)
2071
 
        self.assertEquals(0, branch.revision_id_to_revno('null:'))
2072
 
        self.assertRaises(errors.NoSuchRevision,
2073
 
            branch.revision_id_to_revno, 'unknown')
2074
 
        self.assertFinished(client)
2075
 
 
2076
 
    def test_dotted(self):
2077
 
        transport = MemoryTransport()
2078
 
        client = FakeClient(transport.base)
2079
 
        client.add_expected_call(
2080
 
            'Branch.get_stacked_on_url', ('quack/',),
2081
 
            'error', ('NotStacked',),)
2082
 
        client.add_expected_call(
2083
 
            'Branch.revision_id_to_revno', ('quack/', 'null:'),
2084
 
            'success', ('ok', '0',),)
2085
 
        client.add_expected_call(
2086
 
            'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2087
 
            'error', ('NoSuchRevision', 'unknown',),)
2088
 
        transport.mkdir('quack')
2089
 
        transport = transport.clone('quack')
2090
 
        branch = self.make_remote_branch(transport, client)
2091
 
        self.assertEquals((0, ), branch.revision_id_to_dotted_revno('null:'))
2092
 
        self.assertRaises(errors.NoSuchRevision,
2093
 
            branch.revision_id_to_dotted_revno, 'unknown')
2094
 
        self.assertFinished(client)
2095
 
 
2096
 
    def test_dotted_no_smart_verb(self):
2097
 
        self.setup_smart_server_with_call_log()
2098
 
        branch = self.make_branch('.')
2099
 
        self.disable_verb('Branch.revision_id_to_revno')
2100
 
        self.reset_smart_call_log()
2101
 
        self.assertEquals((0, ),
2102
 
            branch.revision_id_to_dotted_revno('null:'))
2103
 
        self.assertLength(7, self.hpss_calls)
2104
 
 
2105
 
 
2106
1821
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
2107
1822
 
2108
1823
    def test__get_config(self):
2265
1980
            remote_repo_format.get_format_description())
2266
1981
 
2267
1982
 
2268
 
class TestRepositoryAllRevisionIds(TestRemoteRepository):
2269
 
 
2270
 
    def test_empty(self):
2271
 
        transport_path = 'quack'
2272
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2273
 
        client.add_success_response_with_body('', 'ok')
2274
 
        self.assertEquals([], repo.all_revision_ids())
2275
 
        self.assertEqual(
2276
 
            [('call_expecting_body', 'Repository.all_revision_ids',
2277
 
             ('quack/',))],
2278
 
            client._calls)
2279
 
 
2280
 
    def test_with_some_content(self):
2281
 
        transport_path = 'quack'
2282
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2283
 
        client.add_success_response_with_body(
2284
 
            'rev1\nrev2\nanotherrev\n', 'ok')
2285
 
        self.assertEquals(["rev1", "rev2", "anotherrev"],
2286
 
            repo.all_revision_ids())
2287
 
        self.assertEqual(
2288
 
            [('call_expecting_body', 'Repository.all_revision_ids',
2289
 
             ('quack/',))],
2290
 
            client._calls)
2291
 
 
2292
 
 
2293
1983
class TestRepositoryGatherStats(TestRemoteRepository):
2294
1984
 
2295
1985
    def test_revid_none(self):
2348
2038
                         result)
2349
2039
 
2350
2040
 
2351
 
class TestRepositoryBreakLock(TestRemoteRepository):
2352
 
 
2353
 
    def test_break_lock(self):
2354
 
        transport_path = 'quack'
2355
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2356
 
        client.add_success_response('ok')
2357
 
        repo.break_lock()
2358
 
        self.assertEqual(
2359
 
            [('call', 'Repository.break_lock', ('quack/',))],
2360
 
            client._calls)
2361
 
 
2362
 
 
2363
 
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
2364
 
 
2365
 
    def test_get_serializer_format(self):
2366
 
        transport_path = 'hill'
2367
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2368
 
        client.add_success_response('ok', '7')
2369
 
        self.assertEquals('7', repo.get_serializer_format())
2370
 
        self.assertEqual(
2371
 
            [('call', 'VersionedFileRepository.get_serializer_format',
2372
 
              ('hill/', ))],
2373
 
            client._calls)
2374
 
 
2375
 
 
2376
 
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2377
 
 
2378
 
    def test_text(self):
2379
 
        # ('ok',), body with signature text
2380
 
        transport_path = 'quack'
2381
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2382
 
        client.add_success_response_with_body(
2383
 
            'THETEXT', 'ok')
2384
 
        self.assertEquals("THETEXT", repo.get_signature_text("revid"))
2385
 
        self.assertEqual(
2386
 
            [('call_expecting_body', 'Repository.get_revision_signature_text',
2387
 
             ('quack/', 'revid'))],
2388
 
            client._calls)
2389
 
 
2390
 
    def test_no_signature(self):
2391
 
        transport_path = 'quick'
2392
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2393
 
        client.add_error_response('nosuchrevision', 'unknown')
2394
 
        self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
2395
 
                "unknown")
2396
 
        self.assertEqual(
2397
 
            [('call_expecting_body', 'Repository.get_revision_signature_text',
2398
 
              ('quick/', 'unknown'))],
2399
 
            client._calls)
2400
 
 
2401
 
 
2402
2041
class TestRepositoryGetGraph(TestRemoteRepository):
2403
2042
 
2404
2043
    def test_get_graph(self):
2409
2048
        self.assertNotEqual(graph._parents_provider, repo)
2410
2049
 
2411
2050
 
2412
 
class TestRepositoryAddSignatureText(TestRemoteRepository):
2413
 
 
2414
 
    def test_add_signature_text(self):
2415
 
        transport_path = 'quack'
2416
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2417
 
        client.add_expected_call(
2418
 
            'Repository.lock_write', ('quack/', ''),
2419
 
            'success', ('ok', 'a token'))
2420
 
        client.add_expected_call(
2421
 
            'Repository.start_write_group', ('quack/', 'a token'),
2422
 
            'success', ('ok', ('token1', )))
2423
 
        client.add_expected_call(
2424
 
            'Repository.add_signature_text', ('quack/', 'a token', 'rev1',
2425
 
                'token1'),
2426
 
            'success', ('ok', ), None)
2427
 
        repo.lock_write()
2428
 
        repo.start_write_group()
2429
 
        self.assertIs(None,
2430
 
            repo.add_signature_text("rev1", "every bloody emperor"))
2431
 
        self.assertEqual(
2432
 
            ('call_with_body_bytes_expecting_body',
2433
 
              'Repository.add_signature_text',
2434
 
                ('quack/', 'a token', 'rev1', 'token1'),
2435
 
              'every bloody emperor'),
2436
 
            client._calls[-1])
2437
 
 
2438
 
 
2439
2051
class TestRepositoryGetParentMap(TestRemoteRepository):
2440
2052
 
2441
2053
    def test_get_parent_map_caching(self):
2491
2103
        parents = repo.get_parent_map([rev_id])
2492
2104
        self.assertEqual(
2493
2105
            [('call_with_body_bytes_expecting_body',
2494
 
              'Repository.get_parent_map',
2495
 
              ('quack/', 'include-missing:', rev_id), '\n\n0'),
 
2106
              'Repository.get_parent_map', ('quack/', 'include-missing:',
 
2107
              rev_id), '\n\n0'),
2496
2108
             ('disconnect medium',),
2497
2109
             ('call_expecting_body', 'Repository.get_revision_graph',
2498
2110
              ('quack/', ''))],
2618
2230
        self.assertEqual({}, repo.get_parent_map(['non-existant']))
2619
2231
        self.assertLength(0, self.hpss_calls)
2620
2232
 
2621
 
    def test_exposes_get_cached_parent_map(self):
2622
 
        """RemoteRepository exposes get_cached_parent_map from
2623
 
        _unstacked_provider
2624
 
        """
2625
 
        r1 = u'\u0e33'.encode('utf8')
2626
 
        r2 = u'\u0dab'.encode('utf8')
2627
 
        lines = [' '.join([r2, r1]), r1]
2628
 
        encoded_body = bz2.compress('\n'.join(lines))
2629
 
 
2630
 
        transport_path = 'quack'
2631
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2632
 
        client.add_success_response_with_body(encoded_body, 'ok')
2633
 
        repo.lock_read()
2634
 
        # get_cached_parent_map should *not* trigger an RPC
2635
 
        self.assertEqual({}, repo.get_cached_parent_map([r1]))
2636
 
        self.assertEqual([], client._calls)
2637
 
        self.assertEqual({r2: (r1,)}, repo.get_parent_map([r2]))
2638
 
        self.assertEqual({r1: (NULL_REVISION,)},
2639
 
            repo.get_cached_parent_map([r1]))
2640
 
        self.assertEqual(
2641
 
            [('call_with_body_bytes_expecting_body',
2642
 
              'Repository.get_parent_map', ('quack/', 'include-missing:', r2),
2643
 
              '\n\n0')],
2644
 
            client._calls)
2645
 
        repo.unlock()
2646
 
 
2647
2233
 
2648
2234
class TestGetParentMapAllowsNew(tests.TestCaseWithTransport):
2649
2235
 
2664
2250
        self.assertEqual({'rev1': ('null:',)}, graph.get_parent_map(['rev1']))
2665
2251
 
2666
2252
 
2667
 
class TestRepositoryGetRevisions(TestRemoteRepository):
2668
 
 
2669
 
    def test_hpss_missing_revision(self):
2670
 
        transport_path = 'quack'
2671
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2672
 
        client.add_success_response_with_body(
2673
 
            '', 'ok', '10')
2674
 
        self.assertRaises(errors.NoSuchRevision, repo.get_revisions,
2675
 
            ['somerev1', 'anotherrev2'])
2676
 
        self.assertEqual(
2677
 
            [('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2678
 
             ('quack/', ), "somerev1\nanotherrev2")],
2679
 
            client._calls)
2680
 
 
2681
 
    def test_hpss_get_single_revision(self):
2682
 
        transport_path = 'quack'
2683
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2684
 
        somerev1 = Revision("somerev1")
2685
 
        somerev1.committer = "Joe Committer <joe@example.com>"
2686
 
        somerev1.timestamp = 1321828927
2687
 
        somerev1.timezone = -60
2688
 
        somerev1.inventory_sha1 = "691b39be74c67b1212a75fcb19c433aaed903c2b"
2689
 
        somerev1.message = "Message"
2690
 
        body = zlib.compress(chk_bencode_serializer.write_revision_to_string(
2691
 
            somerev1))
2692
 
        # Split up body into two bits to make sure the zlib compression object
2693
 
        # gets data fed twice.
2694
 
        client.add_success_response_with_body(
2695
 
                [body[:10], body[10:]], 'ok', '10')
2696
 
        revs = repo.get_revisions(['somerev1'])
2697
 
        self.assertEquals(revs, [somerev1])
2698
 
        self.assertEqual(
2699
 
            [('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2700
 
             ('quack/', ), "somerev1")],
2701
 
            client._calls)
2702
 
 
2703
 
 
2704
2253
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
2705
2254
 
2706
2255
    def test_null_revision(self):
2857
2406
                              call.call.method == verb])
2858
2407
 
2859
2408
 
2860
 
class TestRepositoryHasSignatureForRevisionId(TestRemoteRepository):
2861
 
 
2862
 
    def test_has_signature_for_revision_id(self):
2863
 
        # ('yes', ) for Repository.has_signature_for_revision_id -> 'True'.
2864
 
        transport_path = 'quack'
2865
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2866
 
        client.add_success_response('yes')
2867
 
        result = repo.has_signature_for_revision_id('A')
2868
 
        self.assertEqual(
2869
 
            [('call', 'Repository.has_signature_for_revision_id',
2870
 
              ('quack/', 'A'))],
2871
 
            client._calls)
2872
 
        self.assertEqual(True, result)
2873
 
 
2874
 
    def test_is_not_shared(self):
2875
 
        # ('no', ) for Repository.has_signature_for_revision_id -> 'False'.
2876
 
        transport_path = 'qwack'
2877
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2878
 
        client.add_success_response('no')
2879
 
        result = repo.has_signature_for_revision_id('A')
2880
 
        self.assertEqual(
2881
 
            [('call', 'Repository.has_signature_for_revision_id',
2882
 
              ('qwack/', 'A'))],
2883
 
            client._calls)
2884
 
        self.assertEqual(False, result)
2885
 
 
2886
 
 
2887
 
class TestRepositoryPhysicalLockStatus(TestRemoteRepository):
2888
 
 
2889
 
    def test_get_physical_lock_status_yes(self):
2890
 
        transport_path = 'qwack'
2891
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2892
 
        client.add_success_response('yes')
2893
 
        result = repo.get_physical_lock_status()
2894
 
        self.assertEqual(
2895
 
            [('call', 'Repository.get_physical_lock_status',
2896
 
              ('qwack/', ))],
2897
 
            client._calls)
2898
 
        self.assertEqual(True, result)
2899
 
 
2900
 
    def test_get_physical_lock_status_no(self):
2901
 
        transport_path = 'qwack'
2902
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2903
 
        client.add_success_response('no')
2904
 
        result = repo.get_physical_lock_status()
2905
 
        self.assertEqual(
2906
 
            [('call', 'Repository.get_physical_lock_status',
2907
 
              ('qwack/', ))],
2908
 
            client._calls)
2909
 
        self.assertEqual(False, result)
2910
 
 
2911
 
 
2912
2409
class TestRepositoryIsShared(TestRemoteRepository):
2913
2410
 
2914
2411
    def test_is_shared(self):
2934
2431
        self.assertEqual(False, result)
2935
2432
 
2936
2433
 
2937
 
class TestRepositoryMakeWorkingTrees(TestRemoteRepository):
2938
 
 
2939
 
    def test_make_working_trees(self):
2940
 
        # ('yes', ) for Repository.make_working_trees -> '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.make_working_trees()
2945
 
        self.assertEqual(
2946
 
            [('call', 'Repository.make_working_trees', ('quack/',))],
2947
 
            client._calls)
2948
 
        self.assertEqual(True, result)
2949
 
 
2950
 
    def test_no_working_trees(self):
2951
 
        # ('no', ) for Repository.make_working_trees -> 'False'.
2952
 
        transport_path = 'qwack'
2953
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2954
 
        client.add_success_response('no')
2955
 
        result = repo.make_working_trees()
2956
 
        self.assertEqual(
2957
 
            [('call', 'Repository.make_working_trees', ('qwack/',))],
2958
 
            client._calls)
2959
 
        self.assertEqual(False, result)
2960
 
 
2961
 
 
2962
2434
class TestRepositoryLockWrite(TestRemoteRepository):
2963
2435
 
2964
2436
    def test_lock_write(self):
2990
2462
            client._calls)
2991
2463
 
2992
2464
 
2993
 
class TestRepositoryWriteGroups(TestRemoteRepository):
2994
 
 
2995
 
    def test_start_write_group(self):
2996
 
        transport_path = 'quack'
2997
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
2998
 
        client.add_expected_call(
2999
 
            'Repository.lock_write', ('quack/', ''),
3000
 
            'success', ('ok', 'a token'))
3001
 
        client.add_expected_call(
3002
 
            'Repository.start_write_group', ('quack/', 'a token'),
3003
 
            'success', ('ok', ('token1', )))
3004
 
        repo.lock_write()
3005
 
        repo.start_write_group()
3006
 
 
3007
 
    def test_start_write_group_unsuspendable(self):
3008
 
        # Some repositories do not support suspending write
3009
 
        # groups. For those, fall back to the "real" repository.
3010
 
        transport_path = 'quack'
3011
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3012
 
        def stub_ensure_real():
3013
 
            client._calls.append(('_ensure_real',))
3014
 
            repo._real_repository = _StubRealPackRepository(client._calls)
3015
 
        repo._ensure_real = stub_ensure_real
3016
 
        client.add_expected_call(
3017
 
            'Repository.lock_write', ('quack/', ''),
3018
 
            'success', ('ok', 'a token'))
3019
 
        client.add_expected_call(
3020
 
            'Repository.start_write_group', ('quack/', 'a token'),
3021
 
            'error', ('UnsuspendableWriteGroup',))
3022
 
        repo.lock_write()
3023
 
        repo.start_write_group()
3024
 
        self.assertEquals(client._calls[-2:], [ 
3025
 
            ('_ensure_real',),
3026
 
            ('start_write_group',)])
3027
 
 
3028
 
    def test_commit_write_group(self):
3029
 
        transport_path = 'quack'
3030
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3031
 
        client.add_expected_call(
3032
 
            'Repository.lock_write', ('quack/', ''),
3033
 
            'success', ('ok', 'a token'))
3034
 
        client.add_expected_call(
3035
 
            'Repository.start_write_group', ('quack/', 'a token'),
3036
 
            'success', ('ok', ['token1']))
3037
 
        client.add_expected_call(
3038
 
            'Repository.commit_write_group', ('quack/', 'a token', ['token1']),
3039
 
            'success', ('ok',))
3040
 
        repo.lock_write()
3041
 
        repo.start_write_group()
3042
 
        repo.commit_write_group()
3043
 
 
3044
 
    def test_abort_write_group(self):
3045
 
        transport_path = 'quack'
3046
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3047
 
        client.add_expected_call(
3048
 
            'Repository.lock_write', ('quack/', ''),
3049
 
            'success', ('ok', 'a token'))
3050
 
        client.add_expected_call(
3051
 
            'Repository.start_write_group', ('quack/', 'a token'),
3052
 
            'success', ('ok', ['token1']))
3053
 
        client.add_expected_call(
3054
 
            'Repository.abort_write_group', ('quack/', 'a token', ['token1']),
3055
 
            'success', ('ok',))
3056
 
        repo.lock_write()
3057
 
        repo.start_write_group()
3058
 
        repo.abort_write_group(False)
3059
 
 
3060
 
    def test_suspend_write_group(self):
3061
 
        transport_path = 'quack'
3062
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3063
 
        self.assertEquals([], repo.suspend_write_group())
3064
 
 
3065
 
    def test_resume_write_group(self):
3066
 
        transport_path = 'quack'
3067
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3068
 
        client.add_expected_call(
3069
 
            'Repository.lock_write', ('quack/', ''),
3070
 
            'success', ('ok', 'a token'))
3071
 
        client.add_expected_call(
3072
 
            'Repository.check_write_group', ('quack/', 'a token', ['token1']),
3073
 
            'success', ('ok',))
3074
 
        repo.lock_write()
3075
 
        repo.resume_write_group(['token1'])
3076
 
 
3077
 
 
3078
2465
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
3079
2466
 
3080
2467
    def test_backwards_compat(self):
3139
2526
        self.assertEqual([], client._calls)
3140
2527
 
3141
2528
 
3142
 
class TestRepositoryIterFilesBytes(TestRemoteRepository):
3143
 
    """Test Repository.iter_file_bytes."""
3144
 
 
3145
 
    def test_single(self):
3146
 
        transport_path = 'quack'
3147
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3148
 
        client.add_expected_call(
3149
 
            'Repository.iter_files_bytes', ('quack/', ),
3150
 
            'success', ('ok',), iter(["ok\x000", "\n", zlib.compress("mydata" * 10)]))
3151
 
        for (identifier, byte_stream) in repo.iter_files_bytes([("somefile",
3152
 
                "somerev", "myid")]):
3153
 
            self.assertEquals("myid", identifier)
3154
 
            self.assertEquals("".join(byte_stream), "mydata" * 10)
3155
 
 
3156
 
    def test_missing(self):
3157
 
        transport_path = 'quack'
3158
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
3159
 
        client.add_expected_call(
3160
 
            'Repository.iter_files_bytes',
3161
 
                ('quack/', ),
3162
 
            'error', ('RevisionNotPresent', 'somefile', 'somerev'),
3163
 
            iter(["absent\0somefile\0somerev\n"]))
3164
 
        self.assertRaises(errors.RevisionNotPresent, list,
3165
 
                repo.iter_files_bytes(
3166
 
                [("somefile", "somerev", "myid")]))
3167
 
 
3168
 
 
3169
2529
class TestRepositoryInsertStreamBase(TestRemoteRepository):
3170
2530
    """Base class for Repository.insert_stream and .insert_stream_1.19
3171
2531
    tests.
3446
2806
        self.calls = calls
3447
2807
        self._pack_collection = _StubPackCollection(calls)
3448
2808
 
3449
 
    def start_write_group(self):
3450
 
        self.calls.append(('start_write_group',))
3451
 
 
3452
2809
    def is_in_write_group(self):
3453
2810
        return False
3454
2811
 
3892
3249
        revs = [r for (r,ps) in graph.iter_ancestry([tip])
3893
3250
                if r != NULL_REVISION]
3894
3251
        revs.reverse()
3895
 
        search = vf_search.PendingAncestryResult([tip], stacked.repository)
 
3252
        search = _mod_graph.PendingAncestryResult([tip], stacked.repository)
3896
3253
        self.reset_smart_call_log()
3897
3254
        stream = source.get_stream(search)
3898
3255
        # We trust that if a revision is in the stream the rest of the new
4004
3361
        self.hpss_calls = []
4005
3362
        local.repository.fetch(
4006
3363
            remote_branch.repository,
4007
 
            fetch_spec=vf_search.EverythingResult(remote_branch.repository))
 
3364
            fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
4008
3365
        self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
4009
3366
 
4010
3367
    def override_verb(self, verb_name, verb):
4011
3368
        request_handlers = request.request_handlers
4012
3369
        orig_verb = request_handlers.get(verb_name)
4013
 
        orig_info = request_handlers.get_info(verb_name)
4014
3370
        request_handlers.register(verb_name, verb, override_existing=True)
4015
3371
        self.addCleanup(request_handlers.register, verb_name, orig_verb,
4016
 
                override_existing=True, info=orig_info)
 
3372
                override_existing=True)
4017
3373
 
4018
3374
    def test_fetch_everything_backwards_compat(self):
4019
3375
        """Can fetch with EverythingResult even with pre 2.4 servers.
4044
3400
        self.hpss_calls = []
4045
3401
        local.repository.fetch(
4046
3402
            remote_branch.repository,
4047
 
            fetch_spec=vf_search.EverythingResult(remote_branch.repository))
 
3403
            fetch_spec=_mod_graph.EverythingResult(remote_branch.repository))
4048
3404
        # make sure the overridden verb was used
4049
3405
        self.assertLength(1, verb_log)
4050
3406
        # more than one HPSS call is needed, but because it's a VFS callback
4095
3451
        # interpretation
4096
3452
        self.make_master_and_checkout('mas~ter', 'checkout')
4097
3453
        self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
4098
 
 
4099
 
 
4100
 
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4101
 
 
4102
 
    def test_no_context(self):
4103
 
        class OutOfCoffee(errors.BzrError):
4104
 
            """A dummy exception for testing."""
4105
 
 
4106
 
            def __init__(self, urgency):
4107
 
                self.urgency = urgency
4108
 
        remote.no_context_error_translators.register("OutOfCoffee",
4109
 
            lambda err: OutOfCoffee(err.error_args[0]))
4110
 
        transport = MemoryTransport()
4111
 
        client = FakeClient(transport.base)
4112
 
        client.add_expected_call(
4113
 
            'Branch.get_stacked_on_url', ('quack/',),
4114
 
            'error', ('NotStacked',))
4115
 
        client.add_expected_call(
4116
 
            'Branch.last_revision_info',
4117
 
            ('quack/',),
4118
 
            'error', ('OutOfCoffee', 'low'))
4119
 
        transport.mkdir('quack')
4120
 
        transport = transport.clone('quack')
4121
 
        branch = self.make_remote_branch(transport, client)
4122
 
        self.assertRaises(OutOfCoffee, branch.last_revision_info)
4123
 
        self.assertFinished(client)
4124
 
 
4125
 
    def test_with_context(self):
4126
 
        class OutOfTea(errors.BzrError):
4127
 
            def __init__(self, branch, urgency):
4128
 
                self.branch = branch
4129
 
                self.urgency = urgency
4130
 
        remote.error_translators.register("OutOfTea",
4131
 
            lambda err, find, path: OutOfTea(err.error_args[0],
4132
 
                find("branch")))
4133
 
        transport = MemoryTransport()
4134
 
        client = FakeClient(transport.base)
4135
 
        client.add_expected_call(
4136
 
            'Branch.get_stacked_on_url', ('quack/',),
4137
 
            'error', ('NotStacked',))
4138
 
        client.add_expected_call(
4139
 
            'Branch.last_revision_info',
4140
 
            ('quack/',),
4141
 
            'error', ('OutOfTea', 'low'))
4142
 
        transport.mkdir('quack')
4143
 
        transport = transport.clone('quack')
4144
 
        branch = self.make_remote_branch(transport, client)
4145
 
        self.assertRaises(OutOfTea, branch.last_revision_info)
4146
 
        self.assertFinished(client)
4147
 
 
4148
 
 
4149
 
class TestRepositoryPack(TestRemoteRepository):
4150
 
 
4151
 
    def test_pack(self):
4152
 
        transport_path = 'quack'
4153
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4154
 
        client.add_expected_call(
4155
 
            'Repository.lock_write', ('quack/', ''),
4156
 
            'success', ('ok', 'token'))
4157
 
        client.add_expected_call(
4158
 
            'Repository.pack', ('quack/', 'token', 'False'),
4159
 
            'success', ('ok',), )
4160
 
        client.add_expected_call(
4161
 
            'Repository.unlock', ('quack/', 'token'),
4162
 
            'success', ('ok', ))
4163
 
        repo.pack()
4164
 
 
4165
 
    def test_pack_with_hint(self):
4166
 
        transport_path = 'quack'
4167
 
        repo, client = self.setup_fake_client_and_repository(transport_path)
4168
 
        client.add_expected_call(
4169
 
            'Repository.lock_write', ('quack/', ''),
4170
 
            'success', ('ok', 'token'))
4171
 
        client.add_expected_call(
4172
 
            'Repository.pack', ('quack/', 'token', 'False'),
4173
 
            'success', ('ok',), )
4174
 
        client.add_expected_call(
4175
 
            'Repository.unlock', ('quack/', 'token', 'False'),
4176
 
            'success', ('ok', ))
4177
 
        repo.pack(['hinta', 'hintb'])