481
491
self.assertEqual(None, result._branch_format)
482
492
self.assertFinished(client)
494
def test_unknown(self):
495
transport = self.get_transport('quack')
496
referenced = self.make_branch('referenced')
497
expected = referenced.bzrdir.cloning_metadir()
498
client = FakeClient(transport.base)
499
client.add_expected_call(
500
'BzrDir.cloning_metadir', ('quack/', 'False'),
501
'success', ('unknown', 'unknown', ('branch', ''))),
502
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
504
self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
507
class TestBzrDirCheckoutMetaDir(TestRemote):
509
def test__get_checkout_format(self):
510
transport = MemoryTransport()
511
client = FakeClient(transport.base)
512
reference_bzrdir_format = bzrdir.format_registry.get('default')()
513
control_name = reference_bzrdir_format.network_name()
514
client.add_expected_call(
515
'BzrDir.checkout_metadir', ('quack/', ),
516
'success', (control_name, '', ''))
517
transport.mkdir('quack')
518
transport = transport.clone('quack')
519
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
521
result = a_bzrdir.checkout_metadir()
522
# We should have got a reference control dir with default branch and
523
# repository formats.
524
self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
525
self.assertEqual(None, result._repository_format)
526
self.assertEqual(None, result._branch_format)
527
self.assertFinished(client)
529
def test_unknown_format(self):
530
transport = MemoryTransport()
531
client = FakeClient(transport.base)
532
client.add_expected_call(
533
'BzrDir.checkout_metadir', ('quack/',),
534
'success', ('dontknow', '', ''))
535
transport.mkdir('quack')
536
transport = transport.clone('quack')
537
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
539
self.assertRaises(errors.UnknownFormatError,
540
a_bzrdir.checkout_metadir)
541
self.assertFinished(client)
544
class TestBzrDirGetBranches(TestRemote):
546
def test_get_branches(self):
547
transport = MemoryTransport()
548
client = FakeClient(transport.base)
549
reference_bzrdir_format = bzrdir.format_registry.get('default')()
550
branch_name = reference_bzrdir_format.get_branch_format().network_name()
551
client.add_success_response_with_body(
553
"foo": ("branch", branch_name),
554
"": ("branch", branch_name)}), "success")
555
client.add_success_response(
556
'ok', '', 'no', 'no', 'no',
557
reference_bzrdir_format.repository_format.network_name())
558
client.add_error_response('NotStacked')
559
client.add_success_response(
560
'ok', '', 'no', 'no', 'no',
561
reference_bzrdir_format.repository_format.network_name())
562
client.add_error_response('NotStacked')
563
transport.mkdir('quack')
564
transport = transport.clone('quack')
565
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
567
result = a_bzrdir.get_branches()
568
self.assertEquals(set(["", "foo"]), set(result.keys()))
570
[('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
571
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
572
('call', 'Branch.get_stacked_on_url', ('quack/', )),
573
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
574
('call', 'Branch.get_stacked_on_url', ('quack/', ))],
578
class TestBzrDirDestroyBranch(TestRemote):
580
def test_destroy_default(self):
581
transport = self.get_transport('quack')
582
referenced = self.make_branch('referenced')
583
client = FakeClient(transport.base)
584
client.add_expected_call(
585
'BzrDir.destroy_branch', ('quack/', ),
587
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
589
a_bzrdir.destroy_branch()
590
self.assertFinished(client)
593
class TestBzrDirHasWorkingTree(TestRemote):
595
def test_has_workingtree(self):
596
transport = self.get_transport('quack')
597
client = FakeClient(transport.base)
598
client.add_expected_call(
599
'BzrDir.has_workingtree', ('quack/',),
600
'success', ('yes',)),
601
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
603
self.assertTrue(a_bzrdir.has_workingtree())
604
self.assertFinished(client)
606
def test_no_workingtree(self):
607
transport = self.get_transport('quack')
608
client = FakeClient(transport.base)
609
client.add_expected_call(
610
'BzrDir.has_workingtree', ('quack/',),
612
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
614
self.assertFalse(a_bzrdir.has_workingtree())
615
self.assertFinished(client)
618
class TestBzrDirDestroyRepository(TestRemote):
620
def test_destroy_repository(self):
621
transport = self.get_transport('quack')
622
client = FakeClient(transport.base)
623
client.add_expected_call(
624
'BzrDir.destroy_repository', ('quack/',),
626
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
628
a_bzrdir.destroy_repository()
629
self.assertFinished(client)
485
632
class TestBzrDirOpen(TestRemote):
996
1147
return RemoteBranch(bzrdir, repo, _client=client, format=format)
1150
class TestBranchBreakLock(RemoteBranchTestCase):
1152
def test_break_lock(self):
1153
transport_path = 'quack'
1154
transport = MemoryTransport()
1155
client = FakeClient(transport.base)
1156
client.add_expected_call(
1157
'Branch.get_stacked_on_url', ('quack/',),
1158
'error', ('NotStacked',))
1159
client.add_expected_call(
1160
'Branch.break_lock', ('quack/',),
1162
transport.mkdir('quack')
1163
transport = transport.clone('quack')
1164
branch = self.make_remote_branch(transport, client)
1166
self.assertFinished(client)
1169
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1171
def test_get_physical_lock_status_yes(self):
1172
transport = MemoryTransport()
1173
client = FakeClient(transport.base)
1174
client.add_expected_call(
1175
'Branch.get_stacked_on_url', ('quack/',),
1176
'error', ('NotStacked',))
1177
client.add_expected_call(
1178
'Branch.get_physical_lock_status', ('quack/',),
1179
'success', ('yes',))
1180
transport.mkdir('quack')
1181
transport = transport.clone('quack')
1182
branch = self.make_remote_branch(transport, client)
1183
result = branch.get_physical_lock_status()
1184
self.assertFinished(client)
1185
self.assertEqual(True, result)
1187
def test_get_physical_lock_status_no(self):
1188
transport = MemoryTransport()
1189
client = FakeClient(transport.base)
1190
client.add_expected_call(
1191
'Branch.get_stacked_on_url', ('quack/',),
1192
'error', ('NotStacked',))
1193
client.add_expected_call(
1194
'Branch.get_physical_lock_status', ('quack/',),
1196
transport.mkdir('quack')
1197
transport = transport.clone('quack')
1198
branch = self.make_remote_branch(transport, client)
1199
result = branch.get_physical_lock_status()
1200
self.assertFinished(client)
1201
self.assertEqual(False, result)
999
1204
class TestBranchGetParent(RemoteBranchTestCase):
1001
1206
def test_no_parent(self):
1840
2038
config = branch._get_config()
1841
2039
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1842
2040
config.set_option(value_dict, 'name')
1843
self.assertLength(10, self.hpss_calls)
2041
self.assertLength(11, self.hpss_calls)
1844
2042
self.assertEqual(value_dict, branch._get_config().get_option('name'))
2045
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
2047
def test_get_branch_conf(self):
2048
# in an empty branch we decode the response properly
2049
client = FakeClient()
2050
client.add_expected_call(
2051
'Branch.get_stacked_on_url', ('memory:///',),
2052
'error', ('NotStacked',),)
2053
client.add_success_response_with_body('# config file body', 'ok')
2054
transport = MemoryTransport()
2055
branch = self.make_remote_branch(transport, client)
2056
config = branch.get_config_stack()
2058
config.get("log_format")
2060
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2061
('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
2064
def test_set_branch_conf(self):
2065
client = FakeClient()
2066
client.add_expected_call(
2067
'Branch.get_stacked_on_url', ('memory:///',),
2068
'error', ('NotStacked',),)
2069
client.add_expected_call(
2070
'Branch.lock_write', ('memory:///', '', ''),
2071
'success', ('ok', 'branch token', 'repo token'))
2072
client.add_expected_call(
2073
'Branch.get_config_file', ('memory:///', ),
2074
'success', ('ok', ), "# line 1\n")
2075
client.add_expected_call(
2076
'Branch.put_config_file', ('memory:///', 'branch token',
2079
client.add_expected_call(
2080
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
2082
transport = MemoryTransport()
2083
branch = self.make_remote_branch(transport, client)
2085
config = branch.get_config_stack()
2086
config.set('email', 'The Dude <lebowski@example.com>')
2088
self.assertFinished(client)
2090
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2091
('call', 'Branch.lock_write', ('memory:///', '', '')),
2092
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2093
('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2094
('memory:///', 'branch token', 'repo token'),
2095
'# line 1\nemail = The Dude <lebowski@example.com>\n'),
2096
('call', 'Branch.unlock', ('memory:///', 'branch token', 'repo token'))],
1847
2100
class TestBranchLockWrite(RemoteBranchTestCase):
1849
2102
def test_lock_write_unlockable(self):
1862
2115
self.assertFinished(client)
2118
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
2120
def test_simple(self):
2121
transport = MemoryTransport()
2122
client = FakeClient(transport.base)
2123
client.add_expected_call(
2124
'Branch.get_stacked_on_url', ('quack/',),
2125
'error', ('NotStacked',),)
2126
client.add_expected_call(
2127
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2128
'success', ('ok', '0',),)
2129
client.add_expected_call(
2130
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2131
'error', ('NoSuchRevision', 'unknown',),)
2132
transport.mkdir('quack')
2133
transport = transport.clone('quack')
2134
branch = self.make_remote_branch(transport, client)
2135
self.assertEquals(0, branch.revision_id_to_revno('null:'))
2136
self.assertRaises(errors.NoSuchRevision,
2137
branch.revision_id_to_revno, 'unknown')
2138
self.assertFinished(client)
2140
def test_dotted(self):
2141
transport = MemoryTransport()
2142
client = FakeClient(transport.base)
2143
client.add_expected_call(
2144
'Branch.get_stacked_on_url', ('quack/',),
2145
'error', ('NotStacked',),)
2146
client.add_expected_call(
2147
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2148
'success', ('ok', '0',),)
2149
client.add_expected_call(
2150
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2151
'error', ('NoSuchRevision', 'unknown',),)
2152
transport.mkdir('quack')
2153
transport = transport.clone('quack')
2154
branch = self.make_remote_branch(transport, client)
2155
self.assertEquals((0, ), branch.revision_id_to_dotted_revno('null:'))
2156
self.assertRaises(errors.NoSuchRevision,
2157
branch.revision_id_to_dotted_revno, 'unknown')
2158
self.assertFinished(client)
2160
def test_dotted_no_smart_verb(self):
2161
self.setup_smart_server_with_call_log()
2162
branch = self.make_branch('.')
2163
self.disable_verb('Branch.revision_id_to_revno')
2164
self.reset_smart_call_log()
2165
self.assertEquals((0, ),
2166
branch.revision_id_to_dotted_revno('null:'))
2167
self.assertLength(8, self.hpss_calls)
1865
2170
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1867
2172
def test__get_config(self):
2415
class TestRepositoryBreakLock(TestRemoteRepository):
2417
def test_break_lock(self):
2418
transport_path = 'quack'
2419
repo, client = self.setup_fake_client_and_repository(transport_path)
2420
client.add_success_response('ok')
2423
[('call', 'Repository.break_lock', ('quack/',))],
2427
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
2429
def test_get_serializer_format(self):
2430
transport_path = 'hill'
2431
repo, client = self.setup_fake_client_and_repository(transport_path)
2432
client.add_success_response('ok', '7')
2433
self.assertEquals('7', repo.get_serializer_format())
2435
[('call', 'VersionedFileRepository.get_serializer_format',
2440
class TestRepositoryReconcile(TestRemoteRepository):
2442
def test_reconcile(self):
2443
transport_path = 'hill'
2444
repo, client = self.setup_fake_client_and_repository(transport_path)
2445
body = ("garbage_inventories: 2\n"
2446
"inconsistent_parents: 3\n")
2447
client.add_expected_call(
2448
'Repository.lock_write', ('hill/', ''),
2449
'success', ('ok', 'a token'))
2450
client.add_success_response_with_body(body, 'ok')
2451
reconciler = repo.reconcile()
2453
[('call', 'Repository.lock_write', ('hill/', '')),
2454
('call_expecting_body', 'Repository.reconcile',
2455
('hill/', 'a token'))],
2457
self.assertEquals(2, reconciler.garbage_inventories)
2458
self.assertEquals(3, reconciler.inconsistent_parents)
2461
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2463
def test_text(self):
2464
# ('ok',), body with signature text
2465
transport_path = 'quack'
2466
repo, client = self.setup_fake_client_and_repository(transport_path)
2467
client.add_success_response_with_body(
2469
self.assertEquals("THETEXT", repo.get_signature_text("revid"))
2471
[('call_expecting_body', 'Repository.get_revision_signature_text',
2472
('quack/', 'revid'))],
2475
def test_no_signature(self):
2476
transport_path = 'quick'
2477
repo, client = self.setup_fake_client_and_repository(transport_path)
2478
client.add_error_response('nosuchrevision', 'unknown')
2479
self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
2482
[('call_expecting_body', 'Repository.get_revision_signature_text',
2483
('quick/', 'unknown'))],
2085
2487
class TestRepositoryGetGraph(TestRemoteRepository):
2087
2489
def test_get_graph(self):
2092
2494
self.assertNotEqual(graph._parents_provider, repo)
2497
class TestRepositoryAddSignatureText(TestRemoteRepository):
2499
def test_add_signature_text(self):
2500
transport_path = 'quack'
2501
repo, client = self.setup_fake_client_and_repository(transport_path)
2502
client.add_expected_call(
2503
'Repository.lock_write', ('quack/', ''),
2504
'success', ('ok', 'a token'))
2505
client.add_expected_call(
2506
'Repository.start_write_group', ('quack/', 'a token'),
2507
'success', ('ok', ('token1', )))
2508
client.add_expected_call(
2509
'Repository.add_signature_text', ('quack/', 'a token', 'rev1',
2511
'success', ('ok', ), None)
2513
repo.start_write_group()
2515
repo.add_signature_text("rev1", "every bloody emperor"))
2517
('call_with_body_bytes_expecting_body',
2518
'Repository.add_signature_text',
2519
('quack/', 'a token', 'rev1', 'token1'),
2520
'every bloody emperor'),
2095
2524
class TestRepositoryGetParentMap(TestRemoteRepository):
2097
2526
def test_get_parent_map_caching(self):
2274
2703
self.assertEqual({}, repo.get_parent_map(['non-existant']))
2275
2704
self.assertLength(0, self.hpss_calls)
2706
def test_exposes_get_cached_parent_map(self):
2707
"""RemoteRepository exposes get_cached_parent_map from
2710
r1 = u'\u0e33'.encode('utf8')
2711
r2 = u'\u0dab'.encode('utf8')
2712
lines = [' '.join([r2, r1]), r1]
2713
encoded_body = bz2.compress('\n'.join(lines))
2715
transport_path = 'quack'
2716
repo, client = self.setup_fake_client_and_repository(transport_path)
2717
client.add_success_response_with_body(encoded_body, 'ok')
2719
# get_cached_parent_map should *not* trigger an RPC
2720
self.assertEqual({}, repo.get_cached_parent_map([r1]))
2721
self.assertEqual([], client._calls)
2722
self.assertEqual({r2: (r1,)}, repo.get_parent_map([r2]))
2723
self.assertEqual({r1: (NULL_REVISION,)},
2724
repo.get_cached_parent_map([r1]))
2726
[('call_with_body_bytes_expecting_body',
2727
'Repository.get_parent_map', ('quack/', 'include-missing:', r2),
2278
2733
class TestGetParentMapAllowsNew(tests.TestCaseWithTransport):
2294
2749
self.assertEqual({'rev1': ('null:',)}, graph.get_parent_map(['rev1']))
2752
class TestRepositoryGetRevisions(TestRemoteRepository):
2754
def test_hpss_missing_revision(self):
2755
transport_path = 'quack'
2756
repo, client = self.setup_fake_client_and_repository(transport_path)
2757
client.add_success_response_with_body(
2759
self.assertRaises(errors.NoSuchRevision, repo.get_revisions,
2760
['somerev1', 'anotherrev2'])
2762
[('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2763
('quack/', ), "somerev1\nanotherrev2")],
2766
def test_hpss_get_single_revision(self):
2767
transport_path = 'quack'
2768
repo, client = self.setup_fake_client_and_repository(transport_path)
2769
somerev1 = Revision("somerev1")
2770
somerev1.committer = "Joe Committer <joe@example.com>"
2771
somerev1.timestamp = 1321828927
2772
somerev1.timezone = -60
2773
somerev1.inventory_sha1 = "691b39be74c67b1212a75fcb19c433aaed903c2b"
2774
somerev1.message = "Message"
2775
body = zlib.compress(chk_bencode_serializer.write_revision_to_string(
2777
# Split up body into two bits to make sure the zlib compression object
2778
# gets data fed twice.
2779
client.add_success_response_with_body(
2780
[body[:10], body[10:]], 'ok', '10')
2781
revs = repo.get_revisions(['somerev1'])
2782
self.assertEquals(revs, [somerev1])
2784
[('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2785
('quack/', ), "somerev1")],
2297
2789
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
2299
2791
def test_null_revision(self):
2450
2942
call.call.method == verb])
2945
class TestRepositoryHasSignatureForRevisionId(TestRemoteRepository):
2947
def test_has_signature_for_revision_id(self):
2948
# ('yes', ) for Repository.has_signature_for_revision_id -> 'True'.
2949
transport_path = 'quack'
2950
repo, client = self.setup_fake_client_and_repository(transport_path)
2951
client.add_success_response('yes')
2952
result = repo.has_signature_for_revision_id('A')
2954
[('call', 'Repository.has_signature_for_revision_id',
2957
self.assertEqual(True, result)
2959
def test_is_not_shared(self):
2960
# ('no', ) for Repository.has_signature_for_revision_id -> 'False'.
2961
transport_path = 'qwack'
2962
repo, client = self.setup_fake_client_and_repository(transport_path)
2963
client.add_success_response('no')
2964
result = repo.has_signature_for_revision_id('A')
2966
[('call', 'Repository.has_signature_for_revision_id',
2969
self.assertEqual(False, result)
2972
class TestRepositoryPhysicalLockStatus(TestRemoteRepository):
2974
def test_get_physical_lock_status_yes(self):
2975
transport_path = 'qwack'
2976
repo, client = self.setup_fake_client_and_repository(transport_path)
2977
client.add_success_response('yes')
2978
result = repo.get_physical_lock_status()
2980
[('call', 'Repository.get_physical_lock_status',
2983
self.assertEqual(True, result)
2985
def test_get_physical_lock_status_no(self):
2986
transport_path = 'qwack'
2987
repo, client = self.setup_fake_client_and_repository(transport_path)
2988
client.add_success_response('no')
2989
result = repo.get_physical_lock_status()
2991
[('call', 'Repository.get_physical_lock_status',
2994
self.assertEqual(False, result)
2453
2997
class TestRepositoryIsShared(TestRemoteRepository):
2455
2999
def test_is_shared(self):
3078
class TestRepositoryWriteGroups(TestRemoteRepository):
3080
def test_start_write_group(self):
3081
transport_path = 'quack'
3082
repo, client = self.setup_fake_client_and_repository(transport_path)
3083
client.add_expected_call(
3084
'Repository.lock_write', ('quack/', ''),
3085
'success', ('ok', 'a token'))
3086
client.add_expected_call(
3087
'Repository.start_write_group', ('quack/', 'a token'),
3088
'success', ('ok', ('token1', )))
3090
repo.start_write_group()
3092
def test_start_write_group_unsuspendable(self):
3093
# Some repositories do not support suspending write
3094
# groups. For those, fall back to the "real" repository.
3095
transport_path = 'quack'
3096
repo, client = self.setup_fake_client_and_repository(transport_path)
3097
def stub_ensure_real():
3098
client._calls.append(('_ensure_real',))
3099
repo._real_repository = _StubRealPackRepository(client._calls)
3100
repo._ensure_real = stub_ensure_real
3101
client.add_expected_call(
3102
'Repository.lock_write', ('quack/', ''),
3103
'success', ('ok', 'a token'))
3104
client.add_expected_call(
3105
'Repository.start_write_group', ('quack/', 'a token'),
3106
'error', ('UnsuspendableWriteGroup',))
3108
repo.start_write_group()
3109
self.assertEquals(client._calls[-2:], [
3111
('start_write_group',)])
3113
def test_commit_write_group(self):
3114
transport_path = 'quack'
3115
repo, client = self.setup_fake_client_and_repository(transport_path)
3116
client.add_expected_call(
3117
'Repository.lock_write', ('quack/', ''),
3118
'success', ('ok', 'a token'))
3119
client.add_expected_call(
3120
'Repository.start_write_group', ('quack/', 'a token'),
3121
'success', ('ok', ['token1']))
3122
client.add_expected_call(
3123
'Repository.commit_write_group', ('quack/', 'a token', ['token1']),
3126
repo.start_write_group()
3127
repo.commit_write_group()
3129
def test_abort_write_group(self):
3130
transport_path = 'quack'
3131
repo, client = self.setup_fake_client_and_repository(transport_path)
3132
client.add_expected_call(
3133
'Repository.lock_write', ('quack/', ''),
3134
'success', ('ok', 'a token'))
3135
client.add_expected_call(
3136
'Repository.start_write_group', ('quack/', 'a token'),
3137
'success', ('ok', ['token1']))
3138
client.add_expected_call(
3139
'Repository.abort_write_group', ('quack/', 'a token', ['token1']),
3142
repo.start_write_group()
3143
repo.abort_write_group(False)
3145
def test_suspend_write_group(self):
3146
transport_path = 'quack'
3147
repo, client = self.setup_fake_client_and_repository(transport_path)
3148
self.assertEquals([], repo.suspend_write_group())
3150
def test_resume_write_group(self):
3151
transport_path = 'quack'
3152
repo, client = self.setup_fake_client_and_repository(transport_path)
3153
client.add_expected_call(
3154
'Repository.lock_write', ('quack/', ''),
3155
'success', ('ok', 'a token'))
3156
client.add_expected_call(
3157
'Repository.check_write_group', ('quack/', 'a token', ['token1']),
3160
repo.resume_write_group(['token1'])
2509
3163
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
2511
3165
def test_backwards_compat(self):
2570
3224
self.assertEqual([], client._calls)
3227
class TestRepositoryIterFilesBytes(TestRemoteRepository):
3228
"""Test Repository.iter_file_bytes."""
3230
def test_single(self):
3231
transport_path = 'quack'
3232
repo, client = self.setup_fake_client_and_repository(transport_path)
3233
client.add_expected_call(
3234
'Repository.iter_files_bytes', ('quack/', ),
3235
'success', ('ok',), iter(["ok\x000", "\n", zlib.compress("mydata" * 10)]))
3236
for (identifier, byte_stream) in repo.iter_files_bytes([("somefile",
3237
"somerev", "myid")]):
3238
self.assertEquals("myid", identifier)
3239
self.assertEquals("".join(byte_stream), "mydata" * 10)
3241
def test_missing(self):
3242
transport_path = 'quack'
3243
repo, client = self.setup_fake_client_and_repository(transport_path)
3244
client.add_expected_call(
3245
'Repository.iter_files_bytes',
3247
'error', ('RevisionNotPresent', 'somefile', 'somerev'),
3248
iter(["absent\0somefile\0somerev\n"]))
3249
self.assertRaises(errors.RevisionNotPresent, list,
3250
repo.iter_files_bytes(
3251
[("somefile", "somerev", "myid")]))
2573
3254
class TestRepositoryInsertStreamBase(TestRemoteRepository):
2574
3255
"""Base class for Repository.insert_stream and .insert_stream_1.19
3495
4180
# interpretation
3496
4181
self.make_master_and_checkout('mas~ter', 'checkout')
3497
4182
self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
4185
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4187
def test_no_context(self):
4188
class OutOfCoffee(errors.BzrError):
4189
"""A dummy exception for testing."""
4191
def __init__(self, urgency):
4192
self.urgency = urgency
4193
remote.no_context_error_translators.register("OutOfCoffee",
4194
lambda err: OutOfCoffee(err.error_args[0]))
4195
transport = MemoryTransport()
4196
client = FakeClient(transport.base)
4197
client.add_expected_call(
4198
'Branch.get_stacked_on_url', ('quack/',),
4199
'error', ('NotStacked',))
4200
client.add_expected_call(
4201
'Branch.last_revision_info',
4203
'error', ('OutOfCoffee', 'low'))
4204
transport.mkdir('quack')
4205
transport = transport.clone('quack')
4206
branch = self.make_remote_branch(transport, client)
4207
self.assertRaises(OutOfCoffee, branch.last_revision_info)
4208
self.assertFinished(client)
4210
def test_with_context(self):
4211
class OutOfTea(errors.BzrError):
4212
def __init__(self, branch, urgency):
4213
self.branch = branch
4214
self.urgency = urgency
4215
remote.error_translators.register("OutOfTea",
4216
lambda err, find, path: OutOfTea(err.error_args[0],
4218
transport = MemoryTransport()
4219
client = FakeClient(transport.base)
4220
client.add_expected_call(
4221
'Branch.get_stacked_on_url', ('quack/',),
4222
'error', ('NotStacked',))
4223
client.add_expected_call(
4224
'Branch.last_revision_info',
4226
'error', ('OutOfTea', 'low'))
4227
transport.mkdir('quack')
4228
transport = transport.clone('quack')
4229
branch = self.make_remote_branch(transport, client)
4230
self.assertRaises(OutOfTea, branch.last_revision_info)
4231
self.assertFinished(client)
4234
class TestRepositoryPack(TestRemoteRepository):
4236
def test_pack(self):
4237
transport_path = 'quack'
4238
repo, client = self.setup_fake_client_and_repository(transport_path)
4239
client.add_expected_call(
4240
'Repository.lock_write', ('quack/', ''),
4241
'success', ('ok', 'token'))
4242
client.add_expected_call(
4243
'Repository.pack', ('quack/', 'token', 'False'),
4244
'success', ('ok',), )
4245
client.add_expected_call(
4246
'Repository.unlock', ('quack/', 'token'),
4247
'success', ('ok', ))
4250
def test_pack_with_hint(self):
4251
transport_path = 'quack'
4252
repo, client = self.setup_fake_client_and_repository(transport_path)
4253
client.add_expected_call(
4254
'Repository.lock_write', ('quack/', ''),
4255
'success', ('ok', 'token'))
4256
client.add_expected_call(
4257
'Repository.pack', ('quack/', 'token', 'False'),
4258
'success', ('ok',), )
4259
client.add_expected_call(
4260
'Repository.unlock', ('quack/', 'token', 'False'),
4261
'success', ('ok', ))
4262
repo.pack(['hinta', 'hintb'])
4265
class TestRepositoryIterInventories(TestRemoteRepository):
4266
"""Test Repository.iter_inventories."""
4268
def _serialize_inv_delta(self, old_name, new_name, delta):
4269
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4270
return "".join(serializer.delta_to_lines(old_name, new_name, delta))
4272
def test_single_empty(self):
4273
transport_path = 'quack'
4274
repo, client = self.setup_fake_client_and_repository(transport_path)
4275
fmt = bzrdir.format_registry.get('2a')().repository_format
4277
stream = [('inventory-deltas', [
4278
versionedfile.FulltextContentFactory('somerevid', None, None,
4279
self._serialize_inv_delta('null:', 'somerevid', []))])]
4280
client.add_expected_call(
4281
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4282
'success', ('ok', ),
4283
_stream_to_byte_stream(stream, fmt))
4284
ret = list(repo.iter_inventories(["somerevid"]))
4285
self.assertLength(1, ret)
4287
self.assertEquals("somerevid", inv.revision_id)
4289
def test_empty(self):
4290
transport_path = 'quack'
4291
repo, client = self.setup_fake_client_and_repository(transport_path)
4292
ret = list(repo.iter_inventories([]))
4293
self.assertEquals(ret, [])
4295
def test_missing(self):
4296
transport_path = 'quack'
4297
repo, client = self.setup_fake_client_and_repository(transport_path)
4298
client.add_expected_call(
4299
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4300
'success', ('ok', ), iter([]))
4301
self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(