53
from bzrlib.chk_serializer import chk_bencode_serializer
51
54
from bzrlib.remote import (
53
56
RemoteBranchFormat,
56
60
RemoteRepositoryFormat,
58
from bzrlib.repofmt import groupcompress_repo, pack_repo
59
from bzrlib.revision import NULL_REVISION
60
from bzrlib.smart import medium
62
from bzrlib.repofmt import groupcompress_repo, knitpack_repo
63
from bzrlib.revision import (
67
from bzrlib.smart import medium, request
61
68
from bzrlib.smart.client import _SmartClient
62
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
69
from bzrlib.smart.repository import (
70
SmartServerRepositoryGetParentMap,
71
SmartServerRepositoryGetStream_1_19,
73
from bzrlib.symbol_versioning import deprecated_in
63
74
from bzrlib.tests import (
65
split_suite_by_condition,
77
from bzrlib.tests.scenarios import load_tests_apply_scenarios
69
78
from bzrlib.transport.memory import MemoryTransport
70
79
from bzrlib.transport.remote import (
72
81
RemoteSSHTransport,
73
82
RemoteTCPTransport,
76
def load_tests(standard_tests, module, loader):
77
to_adapt, result = split_suite_by_condition(
78
standard_tests, condition_isinstance(BasicRemoteObjectTests))
79
smart_server_version_scenarios = [
86
load_tests = load_tests_apply_scenarios
89
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
81
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
93
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
83
{'transport_server': test_server.SmartTCPServer_for_testing})]
84
return multiply_tests(to_adapt, smart_server_version_scenarios, result)
87
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
95
{'transport_server': test_server.SmartTCPServer_for_testing})]
90
99
super(BasicRemoteObjectTests, self).setUp()
479
490
self.assertEqual(None, result._branch_format)
480
491
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)
483
572
class TestBzrDirOpen(TestRemote):
966
1083
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)
969
1140
class TestBranchGetParent(RemoteBranchTestCase):
971
1142
def test_no_parent(self):
1142
1313
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1316
class TestBranchHeadsToFetch(RemoteBranchTestCase):
1318
def test_uses_last_revision_info_and_tags_by_default(self):
1319
transport = MemoryTransport()
1320
client = FakeClient(transport.base)
1321
client.add_expected_call(
1322
'Branch.get_stacked_on_url', ('quack/',),
1323
'error', ('NotStacked',))
1324
client.add_expected_call(
1325
'Branch.last_revision_info', ('quack/',),
1326
'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
# XXX: this will break if the default format's serialization of tags
1350
# changes, or if the RPC for fetching tags changes from get_tags_bytes.
1351
client.add_expected_call(
1352
'Branch.get_tags_bytes', ('quack/',),
1353
'success', ('d5:tag-17:rev-foo5:tag-27:rev-bare',))
1354
transport.mkdir('quack')
1355
transport = transport.clone('quack')
1356
branch = self.make_remote_branch(transport, client)
1357
result = branch.heads_to_fetch()
1358
self.assertFinished(client)
1360
(set(['rev-tip']), set(['rev-foo', 'rev-bar'])), result)
1362
def test_uses_rpc_for_formats_with_non_default_heads_to_fetch(self):
1363
transport = MemoryTransport()
1364
client = FakeClient(transport.base)
1365
client.add_expected_call(
1366
'Branch.get_stacked_on_url', ('quack/',),
1367
'error', ('NotStacked',))
1368
client.add_expected_call(
1369
'Branch.heads_to_fetch', ('quack/',),
1370
'success', (['tip'], ['tagged-1', 'tagged-2']))
1371
transport.mkdir('quack')
1372
transport = transport.clone('quack')
1373
branch = self.make_remote_branch(transport, client)
1374
branch._format._use_default_local_heads_to_fetch = lambda: False
1375
result = branch.heads_to_fetch()
1376
self.assertFinished(client)
1377
self.assertEqual((set(['tip']), set(['tagged-1', 'tagged-2'])), result)
1379
def make_branch_with_tags(self):
1380
self.setup_smart_server_with_call_log()
1381
# Make a branch with a single revision.
1382
builder = self.make_branch_builder('foo')
1383
builder.start_series()
1384
builder.build_snapshot('tip', None, [
1385
('add', ('', 'root-id', 'directory', ''))])
1386
builder.finish_series()
1387
branch = builder.get_branch()
1388
# Add two tags to that branch
1389
branch.tags.set_tag('tag-1', 'rev-1')
1390
branch.tags.set_tag('tag-2', 'rev-2')
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
self.addCleanup(branch.lock_read().unlock)
1398
# Disable the heads_to_fetch verb
1399
verb = 'Branch.heads_to_fetch'
1400
self.disable_verb(verb)
1401
self.reset_smart_call_log()
1402
result = branch.heads_to_fetch()
1403
self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
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'],
1422
[call.call.method for call in self.hpss_calls])
1145
1425
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1147
1427
def test_empty_branch(self):
1704
1978
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'))],
1707
2036
class TestBranchLockWrite(RemoteBranchTestCase):
1709
2038
def test_lock_write_unlockable(self):
1722
2051
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)
1725
2106
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1727
2108
def test__get_config(self):
1867
2248
class TestRepositoryFormat(TestRemoteRepository):
1869
2250
def test_fast_delta(self):
1870
true_name = groupcompress_repo.RepositoryFormatCHK1().network_name()
2251
true_name = groupcompress_repo.RepositoryFormat2a().network_name()
1871
2252
true_format = RemoteRepositoryFormat()
1872
2253
true_format._network_name = true_name
1873
2254
self.assertEqual(True, true_format.fast_deltas)
1874
false_name = pack_repo.RepositoryFormatKnitPack1().network_name()
2255
false_name = knitpack_repo.RepositoryFormatKnitPack1().network_name()
1875
2256
false_format = RemoteRepositoryFormat()
1876
2257
false_format._network_name = false_name
1877
2258
self.assertEqual(False, false_format.fast_deltas)
1879
2260
def test_get_format_description(self):
1880
2261
remote_repo_format = RemoteRepositoryFormat()
1881
real_format = repository.RepositoryFormat.get_default_format()
2262
real_format = repository.format_registry.get_default()
1882
2263
remote_repo_format._network_name = real_format.network_name()
1883
2264
self.assertEqual(remoted_description(real_format),
1884
2265
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',
1887
2293
class TestRepositoryGatherStats(TestRemoteRepository):
1889
2295
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 TestRepositoryReconcile(TestRemoteRepository):
2378
def test_reconcile(self):
2379
transport_path = 'hill'
2380
repo, client = self.setup_fake_client_and_repository(transport_path)
2381
body = ("garbage_inventories: 2\n"
2382
"inconsistent_parents: 3\n")
2383
client.add_expected_call(
2384
'Repository.lock_write', ('hill/', ''),
2385
'success', ('ok', 'a token'))
2386
client.add_success_response_with_body(body, 'ok')
2387
reconciler = repo.reconcile()
2389
[('call', 'Repository.lock_write', ('hill/', '')),
2390
('call_expecting_body', 'Repository.reconcile',
2391
('hill/', 'a token'))],
2393
self.assertEquals(2, reconciler.garbage_inventories)
2394
self.assertEquals(3, reconciler.inconsistent_parents)
2397
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2399
def test_text(self):
2400
# ('ok',), body with signature text
2401
transport_path = 'quack'
2402
repo, client = self.setup_fake_client_and_repository(transport_path)
2403
client.add_success_response_with_body(
2405
self.assertEquals("THETEXT", repo.get_signature_text("revid"))
2407
[('call_expecting_body', 'Repository.get_revision_signature_text',
2408
('quack/', 'revid'))],
2411
def test_no_signature(self):
2412
transport_path = 'quick'
2413
repo, client = self.setup_fake_client_and_repository(transport_path)
2414
client.add_error_response('nosuchrevision', 'unknown')
2415
self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
2418
[('call_expecting_body', 'Repository.get_revision_signature_text',
2419
('quick/', 'unknown'))],
1945
2423
class TestRepositoryGetGraph(TestRemoteRepository):
1947
2425
def test_get_graph(self):
2154
2685
self.assertEqual({'rev1': ('null:',)}, graph.get_parent_map(['rev1']))
2688
class TestRepositoryGetRevisions(TestRemoteRepository):
2690
def test_hpss_missing_revision(self):
2691
transport_path = 'quack'
2692
repo, client = self.setup_fake_client_and_repository(transport_path)
2693
client.add_success_response_with_body(
2695
self.assertRaises(errors.NoSuchRevision, repo.get_revisions,
2696
['somerev1', 'anotherrev2'])
2698
[('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2699
('quack/', ), "somerev1\nanotherrev2")],
2702
def test_hpss_get_single_revision(self):
2703
transport_path = 'quack'
2704
repo, client = self.setup_fake_client_and_repository(transport_path)
2705
somerev1 = Revision("somerev1")
2706
somerev1.committer = "Joe Committer <joe@example.com>"
2707
somerev1.timestamp = 1321828927
2708
somerev1.timezone = -60
2709
somerev1.inventory_sha1 = "691b39be74c67b1212a75fcb19c433aaed903c2b"
2710
somerev1.message = "Message"
2711
body = zlib.compress(chk_bencode_serializer.write_revision_to_string(
2713
# Split up body into two bits to make sure the zlib compression object
2714
# gets data fed twice.
2715
client.add_success_response_with_body(
2716
[body[:10], body[10:]], 'ok', '10')
2717
revs = repo.get_revisions(['somerev1'])
2718
self.assertEquals(revs, [somerev1])
2720
[('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2721
('quack/', ), "somerev1")],
2157
2725
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
2159
2727
def test_null_revision(self):
2310
2878
call.call.method == verb])
2881
class TestRepositoryHasSignatureForRevisionId(TestRemoteRepository):
2883
def test_has_signature_for_revision_id(self):
2884
# ('yes', ) for Repository.has_signature_for_revision_id -> 'True'.
2885
transport_path = 'quack'
2886
repo, client = self.setup_fake_client_and_repository(transport_path)
2887
client.add_success_response('yes')
2888
result = repo.has_signature_for_revision_id('A')
2890
[('call', 'Repository.has_signature_for_revision_id',
2893
self.assertEqual(True, result)
2895
def test_is_not_shared(self):
2896
# ('no', ) for Repository.has_signature_for_revision_id -> 'False'.
2897
transport_path = 'qwack'
2898
repo, client = self.setup_fake_client_and_repository(transport_path)
2899
client.add_success_response('no')
2900
result = repo.has_signature_for_revision_id('A')
2902
[('call', 'Repository.has_signature_for_revision_id',
2905
self.assertEqual(False, result)
2908
class TestRepositoryPhysicalLockStatus(TestRemoteRepository):
2910
def test_get_physical_lock_status_yes(self):
2911
transport_path = 'qwack'
2912
repo, client = self.setup_fake_client_and_repository(transport_path)
2913
client.add_success_response('yes')
2914
result = repo.get_physical_lock_status()
2916
[('call', 'Repository.get_physical_lock_status',
2919
self.assertEqual(True, result)
2921
def test_get_physical_lock_status_no(self):
2922
transport_path = 'qwack'
2923
repo, client = self.setup_fake_client_and_repository(transport_path)
2924
client.add_success_response('no')
2925
result = repo.get_physical_lock_status()
2927
[('call', 'Repository.get_physical_lock_status',
2930
self.assertEqual(False, result)
2313
2933
class TestRepositoryIsShared(TestRemoteRepository):
2315
2935
def test_is_shared(self):
3014
class TestRepositoryWriteGroups(TestRemoteRepository):
3016
def test_start_write_group(self):
3017
transport_path = 'quack'
3018
repo, client = self.setup_fake_client_and_repository(transport_path)
3019
client.add_expected_call(
3020
'Repository.lock_write', ('quack/', ''),
3021
'success', ('ok', 'a token'))
3022
client.add_expected_call(
3023
'Repository.start_write_group', ('quack/', 'a token'),
3024
'success', ('ok', ('token1', )))
3026
repo.start_write_group()
3028
def test_start_write_group_unsuspendable(self):
3029
# Some repositories do not support suspending write
3030
# groups. For those, fall back to the "real" repository.
3031
transport_path = 'quack'
3032
repo, client = self.setup_fake_client_and_repository(transport_path)
3033
def stub_ensure_real():
3034
client._calls.append(('_ensure_real',))
3035
repo._real_repository = _StubRealPackRepository(client._calls)
3036
repo._ensure_real = stub_ensure_real
3037
client.add_expected_call(
3038
'Repository.lock_write', ('quack/', ''),
3039
'success', ('ok', 'a token'))
3040
client.add_expected_call(
3041
'Repository.start_write_group', ('quack/', 'a token'),
3042
'error', ('UnsuspendableWriteGroup',))
3044
repo.start_write_group()
3045
self.assertEquals(client._calls[-2:], [
3047
('start_write_group',)])
3049
def test_commit_write_group(self):
3050
transport_path = 'quack'
3051
repo, client = self.setup_fake_client_and_repository(transport_path)
3052
client.add_expected_call(
3053
'Repository.lock_write', ('quack/', ''),
3054
'success', ('ok', 'a token'))
3055
client.add_expected_call(
3056
'Repository.start_write_group', ('quack/', 'a token'),
3057
'success', ('ok', ['token1']))
3058
client.add_expected_call(
3059
'Repository.commit_write_group', ('quack/', 'a token', ['token1']),
3062
repo.start_write_group()
3063
repo.commit_write_group()
3065
def test_abort_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.start_write_group', ('quack/', 'a token'),
3073
'success', ('ok', ['token1']))
3074
client.add_expected_call(
3075
'Repository.abort_write_group', ('quack/', 'a token', ['token1']),
3078
repo.start_write_group()
3079
repo.abort_write_group(False)
3081
def test_suspend_write_group(self):
3082
transport_path = 'quack'
3083
repo, client = self.setup_fake_client_and_repository(transport_path)
3084
self.assertEquals([], repo.suspend_write_group())
3086
def test_resume_write_group(self):
3087
transport_path = 'quack'
3088
repo, client = self.setup_fake_client_and_repository(transport_path)
3089
client.add_expected_call(
3090
'Repository.lock_write', ('quack/', ''),
3091
'success', ('ok', 'a token'))
3092
client.add_expected_call(
3093
'Repository.check_write_group', ('quack/', 'a token', ['token1']),
3096
repo.resume_write_group(['token1'])
2369
3099
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
2371
3101
def test_backwards_compat(self):
2935
3719
expected_error = errors.PermissionDenied(path, extra)
2936
3720
self.assertEqual(expected_error, translated_error)
3722
# GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
3724
def test_NoSuchFile_context_path(self):
3725
local_path = "local path"
3726
translated_error = self.translateTuple(('ReadError', "remote path"),
3728
expected_error = errors.ReadError(local_path)
3729
self.assertEqual(expected_error, translated_error)
3731
def test_NoSuchFile_without_context(self):
3732
remote_path = "remote path"
3733
translated_error = self.translateTuple(('ReadError', remote_path))
3734
expected_error = errors.ReadError(remote_path)
3735
self.assertEqual(expected_error, translated_error)
3737
def test_ReadOnlyError(self):
3738
translated_error = self.translateTuple(('ReadOnlyError',))
3739
expected_error = errors.TransportNotPossible("readonly transport")
3740
self.assertEqual(expected_error, translated_error)
3742
def test_MemoryError(self):
3743
translated_error = self.translateTuple(('MemoryError',))
3744
self.assertStartsWith(str(translated_error),
3745
"remote server out of memory")
3747
def test_generic_IndexError_no_classname(self):
3748
err = errors.ErrorFromSmartServer(('error', "list index out of range"))
3749
translated_error = self.translateErrorFromSmartServer(err)
3750
expected_error = errors.UnknownErrorFromSmartServer(err)
3751
self.assertEqual(expected_error, translated_error)
3753
# GZ 2011-03-02: TODO test generic non-ascii error string
3755
def test_generic_KeyError(self):
3756
err = errors.ErrorFromSmartServer(('error', 'KeyError', "1"))
3757
translated_error = self.translateErrorFromSmartServer(err)
3758
expected_error = errors.UnknownErrorFromSmartServer(err)
3759
self.assertEqual(expected_error, translated_error)
2939
3762
class TestErrorTranslationRobustness(TestErrorTranslationBase):
2940
3763
"""Unit tests for bzrlib.remote._translate_error's robustness.
3183
4008
def test_copy_content_into_avoids_revision_history(self):
3184
4009
local = self.make_branch('local')
3185
remote_backing_tree = self.make_branch_and_tree('remote')
3186
remote_backing_tree.commit("Commit.")
4010
builder = self.make_branch_builder('remote')
4011
builder.build_commit(message="Commit.")
3187
4012
remote_branch_url = self.smart_server.get_url() + 'remote'
3188
4013
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3189
4014
local.repository.fetch(remote_branch.repository)
3190
4015
self.hpss_calls = []
3191
4016
remote_branch.copy_content_into(local)
3192
4017
self.assertFalse('Branch.revision_history' in self.hpss_calls)
4019
def test_fetch_everything_needs_just_one_call(self):
4020
local = self.make_branch('local')
4021
builder = self.make_branch_builder('remote')
4022
builder.build_commit(message="Commit.")
4023
remote_branch_url = self.smart_server.get_url() + 'remote'
4024
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4025
self.hpss_calls = []
4026
local.repository.fetch(
4027
remote_branch.repository,
4028
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4029
self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
4031
def override_verb(self, verb_name, verb):
4032
request_handlers = request.request_handlers
4033
orig_verb = request_handlers.get(verb_name)
4034
orig_info = request_handlers.get_info(verb_name)
4035
request_handlers.register(verb_name, verb, override_existing=True)
4036
self.addCleanup(request_handlers.register, verb_name, orig_verb,
4037
override_existing=True, info=orig_info)
4039
def test_fetch_everything_backwards_compat(self):
4040
"""Can fetch with EverythingResult even with pre 2.4 servers.
4042
Pre-2.4 do not support 'everything' searches with the
4043
Repository.get_stream_1.19 verb.
4046
class OldGetStreamVerb(SmartServerRepositoryGetStream_1_19):
4047
"""A version of the Repository.get_stream_1.19 verb patched to
4048
reject 'everything' searches the way 2.3 and earlier do.
4050
def recreate_search(self, repository, search_bytes,
4051
discard_excess=False):
4052
verb_log.append(search_bytes.split('\n', 1)[0])
4053
if search_bytes == 'everything':
4055
request.FailedSmartServerResponse(('BadSearch',)))
4056
return super(OldGetStreamVerb,
4057
self).recreate_search(repository, search_bytes,
4058
discard_excess=discard_excess)
4059
self.override_verb('Repository.get_stream_1.19', OldGetStreamVerb)
4060
local = self.make_branch('local')
4061
builder = self.make_branch_builder('remote')
4062
builder.build_commit(message="Commit.")
4063
remote_branch_url = self.smart_server.get_url() + 'remote'
4064
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4065
self.hpss_calls = []
4066
local.repository.fetch(
4067
remote_branch.repository,
4068
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4069
# make sure the overridden verb was used
4070
self.assertLength(1, verb_log)
4071
# more than one HPSS call is needed, but because it's a VFS callback
4072
# its hard to predict exactly how many.
4073
self.assertTrue(len(self.hpss_calls) > 1)
4076
class TestUpdateBoundBranchWithModifiedBoundLocation(
4077
tests.TestCaseWithTransport):
4078
"""Ensure correct handling of bound_location modifications.
4080
This is tested against a smart server as http://pad.lv/786980 was about a
4081
ReadOnlyError (write attempt during a read-only transaction) which can only
4082
happen in this context.
4086
super(TestUpdateBoundBranchWithModifiedBoundLocation, self).setUp()
4087
self.transport_server = test_server.SmartTCPServer_for_testing
4089
def make_master_and_checkout(self, master_name, checkout_name):
4090
# Create the master branch and its associated checkout
4091
self.master = self.make_branch_and_tree(master_name)
4092
self.checkout = self.master.branch.create_checkout(checkout_name)
4093
# Modify the master branch so there is something to update
4094
self.master.commit('add stuff')
4095
self.last_revid = self.master.commit('even more stuff')
4096
self.bound_location = self.checkout.branch.get_bound_location()
4098
def assertUpdateSucceeds(self, new_location):
4099
self.checkout.branch.set_bound_location(new_location)
4100
self.checkout.update()
4101
self.assertEquals(self.last_revid, self.checkout.last_revision())
4103
def test_without_final_slash(self):
4104
self.make_master_and_checkout('master', 'checkout')
4105
# For unclear reasons some users have a bound_location without a final
4106
# '/', simulate that by forcing such a value
4107
self.assertEndsWith(self.bound_location, '/')
4108
self.assertUpdateSucceeds(self.bound_location.rstrip('/'))
4110
def test_plus_sign(self):
4111
self.make_master_and_checkout('+master', 'checkout')
4112
self.assertUpdateSucceeds(self.bound_location.replace('%2B', '+', 1))
4114
def test_tilda(self):
4115
# Embed ~ in the middle of the path just to avoid any $HOME
4117
self.make_master_and_checkout('mas~ter', 'checkout')
4118
self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
4121
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4123
def test_no_context(self):
4124
class OutOfCoffee(errors.BzrError):
4125
"""A dummy exception for testing."""
4127
def __init__(self, urgency):
4128
self.urgency = urgency
4129
remote.no_context_error_translators.register("OutOfCoffee",
4130
lambda err: OutOfCoffee(err.error_args[0]))
4131
transport = MemoryTransport()
4132
client = FakeClient(transport.base)
4133
client.add_expected_call(
4134
'Branch.get_stacked_on_url', ('quack/',),
4135
'error', ('NotStacked',))
4136
client.add_expected_call(
4137
'Branch.last_revision_info',
4139
'error', ('OutOfCoffee', 'low'))
4140
transport.mkdir('quack')
4141
transport = transport.clone('quack')
4142
branch = self.make_remote_branch(transport, client)
4143
self.assertRaises(OutOfCoffee, branch.last_revision_info)
4144
self.assertFinished(client)
4146
def test_with_context(self):
4147
class OutOfTea(errors.BzrError):
4148
def __init__(self, branch, urgency):
4149
self.branch = branch
4150
self.urgency = urgency
4151
remote.error_translators.register("OutOfTea",
4152
lambda err, find, path: OutOfTea(err.error_args[0],
4154
transport = MemoryTransport()
4155
client = FakeClient(transport.base)
4156
client.add_expected_call(
4157
'Branch.get_stacked_on_url', ('quack/',),
4158
'error', ('NotStacked',))
4159
client.add_expected_call(
4160
'Branch.last_revision_info',
4162
'error', ('OutOfTea', 'low'))
4163
transport.mkdir('quack')
4164
transport = transport.clone('quack')
4165
branch = self.make_remote_branch(transport, client)
4166
self.assertRaises(OutOfTea, branch.last_revision_info)
4167
self.assertFinished(client)
4170
class TestRepositoryPack(TestRemoteRepository):
4172
def test_pack(self):
4173
transport_path = 'quack'
4174
repo, client = self.setup_fake_client_and_repository(transport_path)
4175
client.add_expected_call(
4176
'Repository.lock_write', ('quack/', ''),
4177
'success', ('ok', 'token'))
4178
client.add_expected_call(
4179
'Repository.pack', ('quack/', 'token', 'False'),
4180
'success', ('ok',), )
4181
client.add_expected_call(
4182
'Repository.unlock', ('quack/', 'token'),
4183
'success', ('ok', ))
4186
def test_pack_with_hint(self):
4187
transport_path = 'quack'
4188
repo, client = self.setup_fake_client_and_repository(transport_path)
4189
client.add_expected_call(
4190
'Repository.lock_write', ('quack/', ''),
4191
'success', ('ok', 'token'))
4192
client.add_expected_call(
4193
'Repository.pack', ('quack/', 'token', 'False'),
4194
'success', ('ok',), )
4195
client.add_expected_call(
4196
'Repository.unlock', ('quack/', 'token', 'False'),
4197
'success', ('ok', ))
4198
repo.pack(['hinta', 'hintb'])