53
64
RemoteRepositoryFormat,
55
from bzrlib.repofmt import groupcompress_repo, pack_repo
56
from bzrlib.revision import NULL_REVISION
57
from bzrlib.smart import medium
58
from bzrlib.smart.client import _SmartClient
59
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
60
from bzrlib.tests import (
62
split_suite_by_condition,
66
from ..bzr import groupcompress_repo, knitpack_repo
67
from ..revision import (
71
from ..sixish import (
74
from ..bzr.smart import medium, request
75
from ..bzr.smart.client import _SmartClient
76
from ..bzr.smart.repository import (
77
SmartServerRepositoryGetParentMap,
78
SmartServerRepositoryGetStream_1_19,
79
_stream_to_byte_stream,
66
from bzrlib.transport import get_transport
67
from bzrlib.transport.memory import MemoryTransport
68
from bzrlib.transport.remote import (
84
from .scenarios import load_tests_apply_scenarios
85
from ..transport.memory import MemoryTransport
86
from ..transport.remote import (
70
88
RemoteSSHTransport,
71
89
RemoteTCPTransport,
74
def load_tests(standard_tests, module, loader):
75
to_adapt, result = split_suite_by_condition(
76
standard_tests, condition_isinstance(BasicRemoteObjectTests))
77
smart_server_version_scenarios = [
93
load_tests = load_tests_apply_scenarios
96
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
79
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
100
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
81
{'transport_server': test_server.SmartTCPServer_for_testing})]
82
return multiply_tests(to_adapt, smart_server_version_scenarios, result)
85
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
102
{'transport_server': test_server.SmartTCPServer_for_testing})]
88
106
super(BasicRemoteObjectTests, self).setUp()
89
107
self.transport = self.get_transport()
90
108
# make a branch that can be opened over the smart transport
91
109
self.local_wt = BzrDir.create_standalone_workingtree('.')
94
self.transport.disconnect()
95
tests.TestCaseWithTransport.tearDown(self)
110
self.addCleanup(self.transport.disconnect)
97
112
def test_create_remote_bzrdir(self):
98
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
113
b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
99
114
self.assertIsInstance(b, BzrDir)
101
116
def test_open_remote_branch(self):
102
117
# open a standalone branch in the working directory
103
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
118
b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
104
119
branch = b.open_branch()
105
120
self.assertIsInstance(branch, Branch)
480
488
self.assertEqual(None, result._branch_format)
481
489
self.assertFinished(client)
491
def test_unknown(self):
492
transport = self.get_transport('quack')
493
referenced = self.make_branch('referenced')
494
expected = referenced.controldir.cloning_metadir()
495
client = FakeClient(transport.base)
496
client.add_expected_call(
497
'BzrDir.cloning_metadir', ('quack/', 'False'),
498
'success', ('unknown', 'unknown', ('branch', ''))),
499
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
501
self.assertRaises(errors.UnknownFormatError, a_controldir.cloning_metadir)
504
class TestBzrDirCheckoutMetaDir(TestRemote):
506
def test__get_checkout_format(self):
507
transport = MemoryTransport()
508
client = FakeClient(transport.base)
509
reference_bzrdir_format = controldir.format_registry.get('default')()
510
control_name = reference_bzrdir_format.network_name()
511
client.add_expected_call(
512
'BzrDir.checkout_metadir', ('quack/', ),
513
'success', (control_name, '', ''))
514
transport.mkdir('quack')
515
transport = transport.clone('quack')
516
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
518
result = a_controldir.checkout_metadir()
519
# We should have got a reference control dir with default branch and
520
# repository formats.
521
self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
522
self.assertEqual(None, result._repository_format)
523
self.assertEqual(None, result._branch_format)
524
self.assertFinished(client)
526
def test_unknown_format(self):
527
transport = MemoryTransport()
528
client = FakeClient(transport.base)
529
client.add_expected_call(
530
'BzrDir.checkout_metadir', ('quack/',),
531
'success', ('dontknow', '', ''))
532
transport.mkdir('quack')
533
transport = transport.clone('quack')
534
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
536
self.assertRaises(errors.UnknownFormatError,
537
a_controldir.checkout_metadir)
538
self.assertFinished(client)
541
class TestBzrDirGetBranches(TestRemote):
543
def test_get_branches(self):
544
transport = MemoryTransport()
545
client = FakeClient(transport.base)
546
reference_bzrdir_format = controldir.format_registry.get('default')()
547
branch_name = reference_bzrdir_format.get_branch_format().network_name()
548
client.add_success_response_with_body(
550
"foo": ("branch", branch_name),
551
"": ("branch", branch_name)}), "success")
552
client.add_success_response(
553
'ok', '', 'no', 'no', 'no',
554
reference_bzrdir_format.repository_format.network_name())
555
client.add_error_response('NotStacked')
556
client.add_success_response(
557
'ok', '', 'no', 'no', 'no',
558
reference_bzrdir_format.repository_format.network_name())
559
client.add_error_response('NotStacked')
560
transport.mkdir('quack')
561
transport = transport.clone('quack')
562
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
564
result = a_controldir.get_branches()
565
self.assertEqual({"", "foo"}, set(result.keys()))
567
[('call_expecting_body', 'BzrDir.get_branches', ('quack/',)),
568
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
569
('call', 'Branch.get_stacked_on_url', ('quack/', )),
570
('call', 'BzrDir.find_repositoryV3', ('quack/', )),
571
('call', 'Branch.get_stacked_on_url', ('quack/', ))],
575
class TestBzrDirDestroyBranch(TestRemote):
577
def test_destroy_default(self):
578
transport = self.get_transport('quack')
579
referenced = self.make_branch('referenced')
580
client = FakeClient(transport.base)
581
client.add_expected_call(
582
'BzrDir.destroy_branch', ('quack/', ),
584
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
586
a_controldir.destroy_branch()
587
self.assertFinished(client)
590
class TestBzrDirHasWorkingTree(TestRemote):
592
def test_has_workingtree(self):
593
transport = self.get_transport('quack')
594
client = FakeClient(transport.base)
595
client.add_expected_call(
596
'BzrDir.has_workingtree', ('quack/',),
597
'success', ('yes',)),
598
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
600
self.assertTrue(a_controldir.has_workingtree())
601
self.assertFinished(client)
603
def test_no_workingtree(self):
604
transport = self.get_transport('quack')
605
client = FakeClient(transport.base)
606
client.add_expected_call(
607
'BzrDir.has_workingtree', ('quack/',),
609
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
611
self.assertFalse(a_controldir.has_workingtree())
612
self.assertFinished(client)
615
class TestBzrDirDestroyRepository(TestRemote):
617
def test_destroy_repository(self):
618
transport = self.get_transport('quack')
619
client = FakeClient(transport.base)
620
client.add_expected_call(
621
'BzrDir.destroy_repository', ('quack/',),
623
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
625
a_controldir.destroy_repository()
626
self.assertFinished(client)
484
629
class TestBzrDirOpen(TestRemote):
715
860
'BzrDir.create_branch', ('quack/', network_name),
716
861
'success', ('ok', network_name, '', 'no', 'no', 'yes',
717
862
reference_repo_name))
718
a_bzrdir = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
720
branch = a_bzrdir.create_branch()
863
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
865
branch = a_controldir.create_branch()
866
# We should have got a remote branch
867
self.assertIsInstance(branch, remote.RemoteBranch)
868
# its format should have the settings from the response
869
format = branch._format
870
self.assertEqual(network_name, format.network_name())
872
def test_already_open_repo_and_reused_medium(self):
873
"""Bug 726584: create_branch(..., repository=repo) should work
874
regardless of what the smart medium's base URL is.
876
self.transport_server = test_server.SmartTCPServer_for_testing
877
transport = self.get_transport('.')
878
repo = self.make_repository('quack')
879
# Client's medium rooted a transport root (not at the bzrdir)
880
client = FakeClient(transport.base)
881
transport = transport.clone('quack')
882
reference_bzrdir_format = controldir.format_registry.get('default')()
883
reference_format = reference_bzrdir_format.get_branch_format()
884
network_name = reference_format.network_name()
885
reference_repo_fmt = reference_bzrdir_format.repository_format
886
reference_repo_name = reference_repo_fmt.network_name()
887
client.add_expected_call(
888
'BzrDir.create_branch', ('extra/quack/', network_name),
889
'success', ('ok', network_name, '', 'no', 'no', 'yes',
890
reference_repo_name))
891
a_controldir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
893
branch = a_controldir.create_branch(repository=repo)
721
894
# We should have got a remote branch
722
895
self.assertIsInstance(branch, remote.RemoteBranch)
723
896
# its format should have the settings from the response
967
1144
return RemoteBranch(bzrdir, repo, _client=client, format=format)
1147
class TestBranchBreakLock(RemoteBranchTestCase):
1149
def test_break_lock(self):
1150
transport_path = 'quack'
1151
transport = MemoryTransport()
1152
client = FakeClient(transport.base)
1153
client.add_expected_call(
1154
'Branch.get_stacked_on_url', ('quack/',),
1155
'error', ('NotStacked',))
1156
client.add_expected_call(
1157
'Branch.break_lock', ('quack/',),
1159
transport.mkdir('quack')
1160
transport = transport.clone('quack')
1161
branch = self.make_remote_branch(transport, client)
1163
self.assertFinished(client)
1166
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1168
def test_get_physical_lock_status_yes(self):
1169
transport = MemoryTransport()
1170
client = FakeClient(transport.base)
1171
client.add_expected_call(
1172
'Branch.get_stacked_on_url', ('quack/',),
1173
'error', ('NotStacked',))
1174
client.add_expected_call(
1175
'Branch.get_physical_lock_status', ('quack/',),
1176
'success', ('yes',))
1177
transport.mkdir('quack')
1178
transport = transport.clone('quack')
1179
branch = self.make_remote_branch(transport, client)
1180
result = branch.get_physical_lock_status()
1181
self.assertFinished(client)
1182
self.assertEqual(True, result)
1184
def test_get_physical_lock_status_no(self):
1185
transport = MemoryTransport()
1186
client = FakeClient(transport.base)
1187
client.add_expected_call(
1188
'Branch.get_stacked_on_url', ('quack/',),
1189
'error', ('NotStacked',))
1190
client.add_expected_call(
1191
'Branch.get_physical_lock_status', ('quack/',),
1193
transport.mkdir('quack')
1194
transport = transport.clone('quack')
1195
branch = self.make_remote_branch(transport, client)
1196
result = branch.get_physical_lock_status()
1197
self.assertFinished(client)
1198
self.assertEqual(False, result)
970
1201
class TestBranchGetParent(RemoteBranchTestCase):
972
1203
def test_no_parent(self):
1143
1374
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1377
class TestBranchHeadsToFetch(RemoteBranchTestCase):
1379
def test_uses_last_revision_info_and_tags_by_default(self):
1380
transport = MemoryTransport()
1381
client = FakeClient(transport.base)
1382
client.add_expected_call(
1383
'Branch.get_stacked_on_url', ('quack/',),
1384
'error', ('NotStacked',))
1385
client.add_expected_call(
1386
'Branch.last_revision_info', ('quack/',),
1387
'success', ('ok', '1', 'rev-tip'))
1388
client.add_expected_call(
1389
'Branch.get_config_file', ('quack/',),
1390
'success', ('ok',), '')
1391
transport.mkdir('quack')
1392
transport = transport.clone('quack')
1393
branch = self.make_remote_branch(transport, client)
1394
result = branch.heads_to_fetch()
1395
self.assertFinished(client)
1396
self.assertEqual(({'rev-tip'}, set()), result)
1398
def test_uses_last_revision_info_and_tags_when_set(self):
1399
transport = MemoryTransport()
1400
client = FakeClient(transport.base)
1401
client.add_expected_call(
1402
'Branch.get_stacked_on_url', ('quack/',),
1403
'error', ('NotStacked',))
1404
client.add_expected_call(
1405
'Branch.last_revision_info', ('quack/',),
1406
'success', ('ok', '1', 'rev-tip'))
1407
client.add_expected_call(
1408
'Branch.get_config_file', ('quack/',),
1409
'success', ('ok',), 'branch.fetch_tags = True')
1410
# XXX: this will break if the default format's serialization of tags
1411
# changes, or if the RPC for fetching tags changes from get_tags_bytes.
1412
client.add_expected_call(
1413
'Branch.get_tags_bytes', ('quack/',),
1414
'success', ('d5:tag-17:rev-foo5:tag-27:rev-bare',))
1415
transport.mkdir('quack')
1416
transport = transport.clone('quack')
1417
branch = self.make_remote_branch(transport, client)
1418
result = branch.heads_to_fetch()
1419
self.assertFinished(client)
1421
({'rev-tip'}, {'rev-foo', 'rev-bar'}), result)
1423
def test_uses_rpc_for_formats_with_non_default_heads_to_fetch(self):
1424
transport = MemoryTransport()
1425
client = FakeClient(transport.base)
1426
client.add_expected_call(
1427
'Branch.get_stacked_on_url', ('quack/',),
1428
'error', ('NotStacked',))
1429
client.add_expected_call(
1430
'Branch.heads_to_fetch', ('quack/',),
1431
'success', (['tip'], ['tagged-1', 'tagged-2']))
1432
transport.mkdir('quack')
1433
transport = transport.clone('quack')
1434
branch = self.make_remote_branch(transport, client)
1435
branch._format._use_default_local_heads_to_fetch = lambda: False
1436
result = branch.heads_to_fetch()
1437
self.assertFinished(client)
1438
self.assertEqual(({'tip'}, {'tagged-1', 'tagged-2'}), result)
1440
def make_branch_with_tags(self):
1441
self.setup_smart_server_with_call_log()
1442
# Make a branch with a single revision.
1443
builder = self.make_branch_builder('foo')
1444
builder.start_series()
1445
builder.build_snapshot(None, [
1446
('add', ('', 'root-id', 'directory', ''))],
1448
builder.finish_series()
1449
branch = builder.get_branch()
1450
# Add two tags to that branch
1451
branch.tags.set_tag('tag-1', 'rev-1')
1452
branch.tags.set_tag('tag-2', 'rev-2')
1455
def test_backwards_compatible(self):
1456
br = self.make_branch_with_tags()
1457
br.get_config_stack().set('branch.fetch_tags', True)
1458
self.addCleanup(br.lock_read().unlock)
1459
# Disable the heads_to_fetch verb
1460
verb = 'Branch.heads_to_fetch'
1461
self.disable_verb(verb)
1462
self.reset_smart_call_log()
1463
result = br.heads_to_fetch()
1464
self.assertEqual(({'tip'}, {'rev-1', 'rev-2'}), result)
1466
['Branch.last_revision_info', 'Branch.get_tags_bytes'],
1467
[call.call.method for call in self.hpss_calls])
1469
def test_backwards_compatible_no_tags(self):
1470
br = self.make_branch_with_tags()
1471
br.get_config_stack().set('branch.fetch_tags', False)
1472
self.addCleanup(br.lock_read().unlock)
1473
# Disable the heads_to_fetch verb
1474
verb = 'Branch.heads_to_fetch'
1475
self.disable_verb(verb)
1476
self.reset_smart_call_log()
1477
result = br.heads_to_fetch()
1478
self.assertEqual(({'tip'}, set()), result)
1480
['Branch.last_revision_info'],
1481
[call.call.method for call in self.hpss_calls])
1146
1484
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1148
1486
def test_empty_branch(self):
1661
2019
self.addCleanup(branch.unlock)
1662
2020
self.reset_smart_call_log()
1663
2021
branch._get_config().set_option('value', 'name')
1664
self.assertLength(10, self.hpss_calls)
2022
self.assertLength(11, self.hpss_calls)
1665
2023
self.assertEqual('value', branch._get_config().get_option('name'))
2025
def test_backwards_compat_set_option_with_dict(self):
2026
self.setup_smart_server_with_call_log()
2027
branch = self.make_branch('.')
2028
verb = 'Branch.set_config_option_dict'
2029
self.disable_verb(verb)
2031
self.addCleanup(branch.unlock)
2032
self.reset_smart_call_log()
2033
config = branch._get_config()
2034
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
2035
config.set_option(value_dict, 'name')
2036
self.assertLength(11, self.hpss_calls)
2037
self.assertEqual(value_dict, branch._get_config().get_option('name'))
2040
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
2042
def test_get_branch_conf(self):
2043
# in an empty branch we decode the response properly
2044
client = FakeClient()
2045
client.add_expected_call(
2046
'Branch.get_stacked_on_url', ('memory:///',),
2047
'error', ('NotStacked',),)
2048
client.add_success_response_with_body('# config file body', 'ok')
2049
transport = MemoryTransport()
2050
branch = self.make_remote_branch(transport, client)
2051
config = branch.get_config_stack()
2053
config.get("log_format")
2055
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2056
('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
2059
def test_set_branch_conf(self):
2060
client = FakeClient()
2061
client.add_expected_call(
2062
'Branch.get_stacked_on_url', ('memory:///',),
2063
'error', ('NotStacked',),)
2064
client.add_expected_call(
2065
'Branch.lock_write', ('memory:///', '', ''),
2066
'success', ('ok', 'branch token', 'repo token'))
2067
client.add_expected_call(
2068
'Branch.get_config_file', ('memory:///', ),
2069
'success', ('ok', ), "# line 1\n")
2070
client.add_expected_call(
2071
'Branch.get_config_file', ('memory:///', ),
2072
'success', ('ok', ), "# line 1\n")
2073
client.add_expected_call(
2074
'Branch.put_config_file', ('memory:///', 'branch token',
2077
client.add_expected_call(
2078
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
2080
transport = MemoryTransport()
2081
branch = self.make_remote_branch(transport, client)
2083
config = branch.get_config_stack()
2084
config.set('email', 'The Dude <lebowski@example.com>')
2086
self.assertFinished(client)
2088
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2089
('call', 'Branch.lock_write', ('memory:///', '', '')),
2090
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2091
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2092
('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2093
('memory:///', 'branch token', 'repo token'),
2094
'# line 1\nemail = The Dude <lebowski@example.com>\n'),
2095
('call', 'Branch.unlock', ('memory:///', 'branch token', 'repo token'))],
1668
2099
class TestBranchLockWrite(RemoteBranchTestCase):
1683
2114
self.assertFinished(client)
2117
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
2119
def test_simple(self):
2120
transport = MemoryTransport()
2121
client = FakeClient(transport.base)
2122
client.add_expected_call(
2123
'Branch.get_stacked_on_url', ('quack/',),
2124
'error', ('NotStacked',),)
2125
client.add_expected_call(
2126
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2127
'success', ('ok', '0',),)
2128
client.add_expected_call(
2129
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2130
'error', ('NoSuchRevision', 'unknown',),)
2131
transport.mkdir('quack')
2132
transport = transport.clone('quack')
2133
branch = self.make_remote_branch(transport, client)
2134
self.assertEqual(0, branch.revision_id_to_revno('null:'))
2135
self.assertRaises(errors.NoSuchRevision,
2136
branch.revision_id_to_revno, 'unknown')
2137
self.assertFinished(client)
2139
def test_dotted(self):
2140
transport = MemoryTransport()
2141
client = FakeClient(transport.base)
2142
client.add_expected_call(
2143
'Branch.get_stacked_on_url', ('quack/',),
2144
'error', ('NotStacked',),)
2145
client.add_expected_call(
2146
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2147
'success', ('ok', '0',),)
2148
client.add_expected_call(
2149
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2150
'error', ('NoSuchRevision', 'unknown',),)
2151
transport.mkdir('quack')
2152
transport = transport.clone('quack')
2153
branch = self.make_remote_branch(transport, client)
2154
self.assertEqual((0, ), branch.revision_id_to_dotted_revno('null:'))
2155
self.assertRaises(errors.NoSuchRevision,
2156
branch.revision_id_to_dotted_revno, 'unknown')
2157
self.assertFinished(client)
2159
def test_dotted_no_smart_verb(self):
2160
self.setup_smart_server_with_call_log()
2161
branch = self.make_branch('.')
2162
self.disable_verb('Branch.revision_id_to_revno')
2163
self.reset_smart_call_log()
2164
self.assertEqual((0, ),
2165
branch.revision_id_to_dotted_revno('null:'))
2166
self.assertLength(8, self.hpss_calls)
1686
2169
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1688
2171
def test__get_config(self):
2414
class TestRepositoryBreakLock(TestRemoteRepository):
2416
def test_break_lock(self):
2417
transport_path = 'quack'
2418
repo, client = self.setup_fake_client_and_repository(transport_path)
2419
client.add_success_response('ok')
2422
[('call', 'Repository.break_lock', ('quack/',))],
2426
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
2428
def test_get_serializer_format(self):
2429
transport_path = 'hill'
2430
repo, client = self.setup_fake_client_and_repository(transport_path)
2431
client.add_success_response('ok', '7')
2432
self.assertEqual('7', repo.get_serializer_format())
2434
[('call', 'VersionedFileRepository.get_serializer_format',
2439
class TestRepositoryReconcile(TestRemoteRepository):
2441
def test_reconcile(self):
2442
transport_path = 'hill'
2443
repo, client = self.setup_fake_client_and_repository(transport_path)
2444
body = ("garbage_inventories: 2\n"
2445
"inconsistent_parents: 3\n")
2446
client.add_expected_call(
2447
'Repository.lock_write', ('hill/', ''),
2448
'success', ('ok', 'a token'))
2449
client.add_success_response_with_body(body, 'ok')
2450
reconciler = repo.reconcile()
2452
[('call', 'Repository.lock_write', ('hill/', '')),
2453
('call_expecting_body', 'Repository.reconcile',
2454
('hill/', 'a token'))],
2456
self.assertEqual(2, reconciler.garbage_inventories)
2457
self.assertEqual(3, reconciler.inconsistent_parents)
2460
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2462
def test_text(self):
2463
# ('ok',), body with signature text
2464
transport_path = 'quack'
2465
repo, client = self.setup_fake_client_and_repository(transport_path)
2466
client.add_success_response_with_body(
2468
self.assertEqual("THETEXT", repo.get_signature_text("revid"))
2470
[('call_expecting_body', 'Repository.get_revision_signature_text',
2471
('quack/', 'revid'))],
2474
def test_no_signature(self):
2475
transport_path = 'quick'
2476
repo, client = self.setup_fake_client_and_repository(transport_path)
2477
client.add_error_response('nosuchrevision', 'unknown')
2478
self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
2481
[('call_expecting_body', 'Repository.get_revision_signature_text',
2482
('quick/', 'unknown'))],
1906
2486
class TestRepositoryGetGraph(TestRemoteRepository):
1908
2488
def test_get_graph(self):
2110
2744
graph = tree.branch.repository.get_graph()
2111
2745
# This provides an opportunity for the missing rev-id to be cached.
2112
2746
self.assertEqual({}, graph.get_parent_map(['rev1']))
2113
tree.commit('message', rev_id='rev1')
2747
tree.commit('message', rev_id=b'rev1')
2114
2748
graph = tree.branch.repository.get_graph()
2115
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.assertEqual(revs, [somerev1])
2784
[('call_with_body_bytes_expecting_body', 'Repository.iter_revisions',
2785
('quack/', ), "somerev1")],
2118
2789
class TestRepositoryGetRevisionGraph(TestRemoteRepository):
2120
2791
def test_null_revision(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.assertEqual(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.assertEqual([], 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'])
2329
3163
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
2331
3165
def test_backwards_compat(self):
2895
3783
expected_error = errors.PermissionDenied(path, extra)
2896
3784
self.assertEqual(expected_error, translated_error)
3786
# GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
3788
def test_NoSuchFile_context_path(self):
3789
local_path = "local path"
3790
translated_error = self.translateTuple(('ReadError', "remote path"),
3792
expected_error = errors.ReadError(local_path)
3793
self.assertEqual(expected_error, translated_error)
3795
def test_NoSuchFile_without_context(self):
3796
remote_path = "remote path"
3797
translated_error = self.translateTuple(('ReadError', remote_path))
3798
expected_error = errors.ReadError(remote_path)
3799
self.assertEqual(expected_error, translated_error)
3801
def test_ReadOnlyError(self):
3802
translated_error = self.translateTuple(('ReadOnlyError',))
3803
expected_error = errors.TransportNotPossible("readonly transport")
3804
self.assertEqual(expected_error, translated_error)
3806
def test_MemoryError(self):
3807
translated_error = self.translateTuple(('MemoryError',))
3808
self.assertStartsWith(str(translated_error),
3809
"remote server out of memory")
3811
def test_generic_IndexError_no_classname(self):
3812
err = errors.ErrorFromSmartServer(('error', "list index out of range"))
3813
translated_error = self.translateErrorFromSmartServer(err)
3814
expected_error = errors.UnknownErrorFromSmartServer(err)
3815
self.assertEqual(expected_error, translated_error)
3817
# GZ 2011-03-02: TODO test generic non-ascii error string
3819
def test_generic_KeyError(self):
3820
err = errors.ErrorFromSmartServer(('error', 'KeyError', "1"))
3821
translated_error = self.translateErrorFromSmartServer(err)
3822
expected_error = errors.UnknownErrorFromSmartServer(err)
3823
self.assertEqual(expected_error, translated_error)
2899
3826
class TestErrorTranslationRobustness(TestErrorTranslationBase):
2900
"""Unit tests for bzrlib.remote._translate_error's robustness.
3827
"""Unit tests for breezy.bzr.remote._translate_error's robustness.
2902
3829
TestErrorTranslationSuccess is for cases where _translate_error can
2903
3830
translate successfully. This class about how _translate_err behaves when
3143
4072
def test_copy_content_into_avoids_revision_history(self):
3144
4073
local = self.make_branch('local')
3145
remote_backing_tree = self.make_branch_and_tree('remote')
3146
remote_backing_tree.commit("Commit.")
4074
builder = self.make_branch_builder('remote')
4075
builder.build_commit(message="Commit.")
3147
4076
remote_branch_url = self.smart_server.get_url() + 'remote'
3148
4077
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3149
4078
local.repository.fetch(remote_branch.repository)
3150
4079
self.hpss_calls = []
3151
4080
remote_branch.copy_content_into(local)
3152
4081
self.assertFalse('Branch.revision_history' in self.hpss_calls)
4083
def test_fetch_everything_needs_just_one_call(self):
4084
local = self.make_branch('local')
4085
builder = self.make_branch_builder('remote')
4086
builder.build_commit(message="Commit.")
4087
remote_branch_url = self.smart_server.get_url() + 'remote'
4088
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4089
self.hpss_calls = []
4090
local.repository.fetch(
4091
remote_branch.repository,
4092
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4093
self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
4095
def override_verb(self, verb_name, verb):
4096
request_handlers = request.request_handlers
4097
orig_verb = request_handlers.get(verb_name)
4098
orig_info = request_handlers.get_info(verb_name)
4099
request_handlers.register(verb_name, verb, override_existing=True)
4100
self.addCleanup(request_handlers.register, verb_name, orig_verb,
4101
override_existing=True, info=orig_info)
4103
def test_fetch_everything_backwards_compat(self):
4104
"""Can fetch with EverythingResult even with pre 2.4 servers.
4106
Pre-2.4 do not support 'everything' searches with the
4107
Repository.get_stream_1.19 verb.
4110
class OldGetStreamVerb(SmartServerRepositoryGetStream_1_19):
4111
"""A version of the Repository.get_stream_1.19 verb patched to
4112
reject 'everything' searches the way 2.3 and earlier do.
4114
def recreate_search(self, repository, search_bytes,
4115
discard_excess=False):
4116
verb_log.append(search_bytes.split('\n', 1)[0])
4117
if search_bytes == 'everything':
4119
request.FailedSmartServerResponse(('BadSearch',)))
4120
return super(OldGetStreamVerb,
4121
self).recreate_search(repository, search_bytes,
4122
discard_excess=discard_excess)
4123
self.override_verb('Repository.get_stream_1.19', OldGetStreamVerb)
4124
local = self.make_branch('local')
4125
builder = self.make_branch_builder('remote')
4126
builder.build_commit(message="Commit.")
4127
remote_branch_url = self.smart_server.get_url() + 'remote'
4128
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4129
self.hpss_calls = []
4130
local.repository.fetch(
4131
remote_branch.repository,
4132
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4133
# make sure the overridden verb was used
4134
self.assertLength(1, verb_log)
4135
# more than one HPSS call is needed, but because it's a VFS callback
4136
# its hard to predict exactly how many.
4137
self.assertTrue(len(self.hpss_calls) > 1)
4140
class TestUpdateBoundBranchWithModifiedBoundLocation(
4141
tests.TestCaseWithTransport):
4142
"""Ensure correct handling of bound_location modifications.
4144
This is tested against a smart server as http://pad.lv/786980 was about a
4145
ReadOnlyError (write attempt during a read-only transaction) which can only
4146
happen in this context.
4150
super(TestUpdateBoundBranchWithModifiedBoundLocation, self).setUp()
4151
self.transport_server = test_server.SmartTCPServer_for_testing
4153
def make_master_and_checkout(self, master_name, checkout_name):
4154
# Create the master branch and its associated checkout
4155
self.master = self.make_branch_and_tree(master_name)
4156
self.checkout = self.master.branch.create_checkout(checkout_name)
4157
# Modify the master branch so there is something to update
4158
self.master.commit('add stuff')
4159
self.last_revid = self.master.commit('even more stuff')
4160
self.bound_location = self.checkout.branch.get_bound_location()
4162
def assertUpdateSucceeds(self, new_location):
4163
self.checkout.branch.set_bound_location(new_location)
4164
self.checkout.update()
4165
self.assertEqual(self.last_revid, self.checkout.last_revision())
4167
def test_without_final_slash(self):
4168
self.make_master_and_checkout('master', 'checkout')
4169
# For unclear reasons some users have a bound_location without a final
4170
# '/', simulate that by forcing such a value
4171
self.assertEndsWith(self.bound_location, '/')
4172
self.assertUpdateSucceeds(self.bound_location.rstrip('/'))
4174
def test_plus_sign(self):
4175
self.make_master_and_checkout('+master', 'checkout')
4176
self.assertUpdateSucceeds(self.bound_location.replace('%2B', '+', 1))
4178
def test_tilda(self):
4179
# Embed ~ in the middle of the path just to avoid any $HOME
4181
self.make_master_and_checkout('mas~ter', 'checkout')
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 = controldir.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.assertEqual("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.assertEqual(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(