123
116
def test_remote_branch_revision_history(self):
124
117
b = BzrDir.open_from_transport(self.transport).open_branch()
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())
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)
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(),
503
self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
506
class TestBzrDirDestroyBranch(TestRemote):
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/', ),
515
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
517
a_bzrdir.destroy_branch()
518
self.assertFinished(client)
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"),
527
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
529
a_bzrdir.destroy_branch("foo")
530
self.assertFinished(client)
533
class TestBzrDirHasWorkingTree(TestRemote):
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(),
543
self.assertTrue(a_bzrdir.has_workingtree())
544
self.assertFinished(client)
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/',),
552
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
554
self.assertFalse(a_bzrdir.has_workingtree())
555
self.assertFinished(client)
558
class TestBzrDirDestroyRepository(TestRemote):
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/',),
566
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
568
a_bzrdir.destroy_repository()
569
self.assertFinished(client)
572
485
class TestBzrDirOpen(TestRemote):
1083
996
return RemoteBranch(bzrdir, repo, _client=client, format=format)
1086
class TestBranchBreakLock(RemoteBranchTestCase):
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/',),
1098
transport.mkdir('quack')
1099
transport = transport.clone('quack')
1100
branch = self.make_remote_branch(transport, client)
1102
self.assertFinished(client)
1105
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
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)
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/',),
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)
1140
999
class TestBranchGetParent(RemoteBranchTestCase):
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)
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(
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])
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)
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])
1978
1800
self.assertEqual(value_dict, branch._get_config().get_option('name'))
1981
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
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()
1994
config.get("log_format")
1996
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
1997
('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
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',
2015
client.add_expected_call(
2016
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
2018
transport = MemoryTransport()
2019
branch = self.make_remote_branch(transport, client)
2021
config = branch.get_config_stack()
2022
config.set('email', 'The Dude <lebowski@example.com>')
2024
self.assertFinished(client)
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'))],
2036
1803
class TestBranchLockWrite(RemoteBranchTestCase):
2038
1805
def test_lock_write_unlockable(self):
2051
1818
self.assertFinished(client)
2054
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
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)
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)
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)
2106
1821
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
2108
1823
def test__get_config(self):
2265
1980
remote_repo_format.get_format_description())
2268
class TestRepositoryAllRevisionIds(TestRemoteRepository):
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())
2276
[('call_expecting_body', 'Repository.all_revision_ids',
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())
2288
[('call_expecting_body', 'Repository.all_revision_ids',
2293
1983
class TestRepositoryGatherStats(TestRemoteRepository):
2295
1985
def test_revid_none(self):
2351
class TestRepositoryBreakLock(TestRemoteRepository):
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')
2359
[('call', 'Repository.break_lock', ('quack/',))],
2363
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
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())
2371
[('call', 'VersionedFileRepository.get_serializer_format',
2376
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
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(
2384
self.assertEquals("THETEXT", repo.get_signature_text("revid"))
2386
[('call_expecting_body', 'Repository.get_revision_signature_text',
2387
('quack/', 'revid'))],
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,
2397
[('call_expecting_body', 'Repository.get_revision_signature_text',
2398
('quick/', 'unknown'))],
2402
2041
class TestRepositoryGetGraph(TestRemoteRepository):
2404
2043
def test_get_graph(self):
2409
2048
self.assertNotEqual(graph._parents_provider, repo)
2412
class TestRepositoryAddSignatureText(TestRemoteRepository):
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',
2426
'success', ('ok', ), None)
2428
repo.start_write_group()
2430
repo.add_signature_text("rev1", "every bloody emperor"))
2432
('call_with_body_bytes_expecting_body',
2433
'Repository.add_signature_text',
2434
('quack/', 'a token', 'rev1', 'token1'),
2435
'every bloody emperor'),
2439
2051
class TestRepositoryGetParentMap(TestRemoteRepository):
2441
2053
def test_get_parent_map_caching(self):
2618
2230
self.assertEqual({}, repo.get_parent_map(['non-existant']))
2619
2231
self.assertLength(0, self.hpss_calls)
2621
def test_exposes_get_cached_parent_map(self):
2622
"""RemoteRepository exposes get_cached_parent_map from
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))
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')
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]))
2641
[('call_with_body_bytes_expecting_body',
2642
'Repository.get_parent_map', ('quack/', 'include-missing:', r2),
2648
2234
class TestGetParentMapAllowsNew(tests.TestCaseWithTransport):
2664
2250
self.assertEqual({'rev1': ('null:',)}, graph.get_parent_map(['rev1']))
2667
class TestRepositoryGetRevisions(TestRemoteRepository):
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(
2674
self.assertRaises(errors.NoSuchRevision, repo.get_revisions,
2675
['somerev1', 'anotherrev2'])
2677
[('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2678
('quack/', ), "somerev1\nanotherrev2")],
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(
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])
2699
[('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2700
('quack/', ), "somerev1")],
2704
2253
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
2706
2255
def test_null_revision(self):
2857
2406
call.call.method == verb])
2860
class TestRepositoryHasSignatureForRevisionId(TestRemoteRepository):
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')
2869
[('call', 'Repository.has_signature_for_revision_id',
2872
self.assertEqual(True, result)
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')
2881
[('call', 'Repository.has_signature_for_revision_id',
2884
self.assertEqual(False, result)
2887
class TestRepositoryPhysicalLockStatus(TestRemoteRepository):
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()
2895
[('call', 'Repository.get_physical_lock_status',
2898
self.assertEqual(True, result)
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()
2906
[('call', 'Repository.get_physical_lock_status',
2909
self.assertEqual(False, result)
2912
2409
class TestRepositoryIsShared(TestRemoteRepository):
2914
2411
def test_is_shared(self):
2934
2431
self.assertEqual(False, result)
2937
class TestRepositoryMakeWorkingTrees(TestRemoteRepository):
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()
2946
[('call', 'Repository.make_working_trees', ('quack/',))],
2948
self.assertEqual(True, result)
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()
2957
[('call', 'Repository.make_working_trees', ('qwack/',))],
2959
self.assertEqual(False, result)
2962
2434
class TestRepositoryLockWrite(TestRemoteRepository):
2964
2436
def test_lock_write(self):
2993
class TestRepositoryWriteGroups(TestRemoteRepository):
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', )))
3005
repo.start_write_group()
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',))
3023
repo.start_write_group()
3024
self.assertEquals(client._calls[-2:], [
3026
('start_write_group',)])
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']),
3041
repo.start_write_group()
3042
repo.commit_write_group()
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']),
3057
repo.start_write_group()
3058
repo.abort_write_group(False)
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())
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']),
3075
repo.resume_write_group(['token1'])
3078
2465
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
3080
2467
def test_backwards_compat(self):
3139
2526
self.assertEqual([], client._calls)
3142
class TestRepositoryIterFilesBytes(TestRemoteRepository):
3143
"""Test Repository.iter_file_bytes."""
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)
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',
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")]))
3169
2529
class TestRepositoryInsertStreamBase(TestRemoteRepository):
3170
2530
"""Base class for Repository.insert_stream and .insert_stream_1.19
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)
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)
4018
3374
def test_fetch_everything_backwards_compat(self):
4019
3375
"""Can fetch with EverythingResult even with pre 2.4 servers.
4095
3451
# interpretation
4096
3452
self.make_master_and_checkout('mas~ter', 'checkout')
4097
3453
self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
4100
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4102
def test_no_context(self):
4103
class OutOfCoffee(errors.BzrError):
4104
"""A dummy exception for testing."""
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',
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)
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],
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',
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)
4149
class TestRepositoryPack(TestRemoteRepository):
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', ))
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'])