53
60
RemoteRepositoryFormat,
55
from bzrlib.repofmt import groupcompress_repo, pack_repo
56
from bzrlib.revision import NULL_REVISION
57
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
58
68
from bzrlib.smart.client import _SmartClient
59
from bzrlib.smart.repository import SmartServerRepositoryGetParentMap
69
from bzrlib.smart.repository import (
70
SmartServerRepositoryGetParentMap,
71
SmartServerRepositoryGetStream_1_19,
72
_stream_to_byte_stream,
74
from bzrlib.symbol_versioning import deprecated_in
60
75
from bzrlib.tests import (
62
split_suite_by_condition,
66
from bzrlib.transport import get_transport
78
from bzrlib.tests.scenarios import load_tests_apply_scenarios
67
79
from bzrlib.transport.memory import MemoryTransport
68
80
from bzrlib.transport.remote import (
70
82
RemoteSSHTransport,
71
83
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 = [
87
load_tests = load_tests_apply_scenarios
90
class BasicRemoteObjectTests(tests.TestCaseWithTransport):
79
{'transport_server': test_server.SmartTCPServer_for_testing_v2_only}),
94
{'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):
96
{'transport_server': test_server.SmartTCPServer_for_testing})]
88
100
super(BasicRemoteObjectTests, self).setUp()
89
101
self.transport = self.get_transport()
90
102
# make a branch that can be opened over the smart transport
91
103
self.local_wt = BzrDir.create_standalone_workingtree('.')
94
self.transport.disconnect()
95
tests.TestCaseWithTransport.tearDown(self)
104
self.addCleanup(self.transport.disconnect)
97
106
def test_create_remote_bzrdir(self):
98
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
107
b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
99
108
self.assertIsInstance(b, BzrDir)
101
110
def test_open_remote_branch(self):
102
111
# open a standalone branch in the working directory
103
b = remote.RemoteBzrDir(self.transport, remote.RemoteBzrDirFormat())
112
b = remote.RemoteBzrDir(self.transport, RemoteBzrDirFormat())
104
113
branch = b.open_branch()
105
114
self.assertIsInstance(branch, Branch)
480
491
self.assertEqual(None, result._branch_format)
481
492
self.assertFinished(client)
494
def test_unknown(self):
495
transport = self.get_transport('quack')
496
referenced = self.make_branch('referenced')
497
expected = referenced.bzrdir.cloning_metadir()
498
client = FakeClient(transport.base)
499
client.add_expected_call(
500
'BzrDir.cloning_metadir', ('quack/', 'False'),
501
'success', ('unknown', 'unknown', ('branch', ''))),
502
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
504
self.assertRaises(errors.UnknownFormatError, a_bzrdir.cloning_metadir)
507
class TestBzrDirCheckoutMetaDir(TestRemote):
509
def test__get_checkout_format(self):
510
transport = MemoryTransport()
511
client = FakeClient(transport.base)
512
reference_bzrdir_format = bzrdir.format_registry.get('default')()
513
control_name = reference_bzrdir_format.network_name()
514
client.add_expected_call(
515
'BzrDir.checkout_metadir', ('quack/', ),
516
'success', (control_name, '', ''))
517
transport.mkdir('quack')
518
transport = transport.clone('quack')
519
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
521
result = a_bzrdir.checkout_metadir()
522
# We should have got a reference control dir with default branch and
523
# repository formats.
524
self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
525
self.assertEqual(None, result._repository_format)
526
self.assertEqual(None, result._branch_format)
527
self.assertFinished(client)
529
def test_unknown_format(self):
530
transport = MemoryTransport()
531
client = FakeClient(transport.base)
532
client.add_expected_call(
533
'BzrDir.checkout_metadir', ('quack/',),
534
'success', ('dontknow', '', ''))
535
transport.mkdir('quack')
536
transport = transport.clone('quack')
537
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
539
self.assertRaises(errors.UnknownFormatError,
540
a_bzrdir.checkout_metadir)
541
self.assertFinished(client)
544
class TestBzrDirDestroyBranch(TestRemote):
546
def test_destroy_default(self):
547
transport = self.get_transport('quack')
548
referenced = self.make_branch('referenced')
549
client = FakeClient(transport.base)
550
client.add_expected_call(
551
'BzrDir.destroy_branch', ('quack/', ),
553
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
555
a_bzrdir.destroy_branch()
556
self.assertFinished(client)
558
def test_destroy_named(self):
559
transport = self.get_transport('quack')
560
referenced = self.make_branch('referenced')
561
client = FakeClient(transport.base)
562
client.add_expected_call(
563
'BzrDir.destroy_branch', ('quack/', "foo"),
565
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
567
a_bzrdir.destroy_branch("foo")
568
self.assertFinished(client)
571
class TestBzrDirHasWorkingTree(TestRemote):
573
def test_has_workingtree(self):
574
transport = self.get_transport('quack')
575
client = FakeClient(transport.base)
576
client.add_expected_call(
577
'BzrDir.has_workingtree', ('quack/',),
578
'success', ('yes',)),
579
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
581
self.assertTrue(a_bzrdir.has_workingtree())
582
self.assertFinished(client)
584
def test_no_workingtree(self):
585
transport = self.get_transport('quack')
586
client = FakeClient(transport.base)
587
client.add_expected_call(
588
'BzrDir.has_workingtree', ('quack/',),
590
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
592
self.assertFalse(a_bzrdir.has_workingtree())
593
self.assertFinished(client)
596
class TestBzrDirDestroyRepository(TestRemote):
598
def test_destroy_repository(self):
599
transport = self.get_transport('quack')
600
client = FakeClient(transport.base)
601
client.add_expected_call(
602
'BzrDir.destroy_repository', ('quack/',),
604
a_bzrdir = RemoteBzrDir(transport, RemoteBzrDirFormat(),
606
a_bzrdir.destroy_repository()
607
self.assertFinished(client)
484
610
class TestBzrDirOpen(TestRemote):
967
1121
return RemoteBranch(bzrdir, repo, _client=client, format=format)
1124
class TestBranchBreakLock(RemoteBranchTestCase):
1126
def test_break_lock(self):
1127
transport_path = 'quack'
1128
transport = MemoryTransport()
1129
client = FakeClient(transport.base)
1130
client.add_expected_call(
1131
'Branch.get_stacked_on_url', ('quack/',),
1132
'error', ('NotStacked',))
1133
client.add_expected_call(
1134
'Branch.break_lock', ('quack/',),
1136
transport.mkdir('quack')
1137
transport = transport.clone('quack')
1138
branch = self.make_remote_branch(transport, client)
1140
self.assertFinished(client)
1143
class TestBranchGetPhysicalLockStatus(RemoteBranchTestCase):
1145
def test_get_physical_lock_status_yes(self):
1146
transport = MemoryTransport()
1147
client = FakeClient(transport.base)
1148
client.add_expected_call(
1149
'Branch.get_stacked_on_url', ('quack/',),
1150
'error', ('NotStacked',))
1151
client.add_expected_call(
1152
'Branch.get_physical_lock_status', ('quack/',),
1153
'success', ('yes',))
1154
transport.mkdir('quack')
1155
transport = transport.clone('quack')
1156
branch = self.make_remote_branch(transport, client)
1157
result = branch.get_physical_lock_status()
1158
self.assertFinished(client)
1159
self.assertEqual(True, result)
1161
def test_get_physical_lock_status_no(self):
1162
transport = MemoryTransport()
1163
client = FakeClient(transport.base)
1164
client.add_expected_call(
1165
'Branch.get_stacked_on_url', ('quack/',),
1166
'error', ('NotStacked',))
1167
client.add_expected_call(
1168
'Branch.get_physical_lock_status', ('quack/',),
1170
transport.mkdir('quack')
1171
transport = transport.clone('quack')
1172
branch = self.make_remote_branch(transport, client)
1173
result = branch.get_physical_lock_status()
1174
self.assertFinished(client)
1175
self.assertEqual(False, result)
970
1178
class TestBranchGetParent(RemoteBranchTestCase):
972
1180
def test_no_parent(self):
1143
1355
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1358
class TestBranchHeadsToFetch(RemoteBranchTestCase):
1360
def test_uses_last_revision_info_and_tags_by_default(self):
1361
transport = MemoryTransport()
1362
client = FakeClient(transport.base)
1363
client.add_expected_call(
1364
'Branch.get_stacked_on_url', ('quack/',),
1365
'error', ('NotStacked',))
1366
client.add_expected_call(
1367
'Branch.last_revision_info', ('quack/',),
1368
'success', ('ok', '1', 'rev-tip'))
1369
client.add_expected_call(
1370
'Branch.get_config_file', ('quack/',),
1371
'success', ('ok',), '')
1372
transport.mkdir('quack')
1373
transport = transport.clone('quack')
1374
branch = self.make_remote_branch(transport, client)
1375
result = branch.heads_to_fetch()
1376
self.assertFinished(client)
1377
self.assertEqual((set(['rev-tip']), set()), result)
1379
def test_uses_last_revision_info_and_tags_when_set(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',), 'branch.fetch_tags = True')
1391
# XXX: this will break if the default format's serialization of tags
1392
# changes, or if the RPC for fetching tags changes from get_tags_bytes.
1393
client.add_expected_call(
1394
'Branch.get_tags_bytes', ('quack/',),
1395
'success', ('d5:tag-17:rev-foo5:tag-27:rev-bare',))
1396
transport.mkdir('quack')
1397
transport = transport.clone('quack')
1398
branch = self.make_remote_branch(transport, client)
1399
result = branch.heads_to_fetch()
1400
self.assertFinished(client)
1402
(set(['rev-tip']), set(['rev-foo', 'rev-bar'])), result)
1404
def test_uses_rpc_for_formats_with_non_default_heads_to_fetch(self):
1405
transport = MemoryTransport()
1406
client = FakeClient(transport.base)
1407
client.add_expected_call(
1408
'Branch.get_stacked_on_url', ('quack/',),
1409
'error', ('NotStacked',))
1410
client.add_expected_call(
1411
'Branch.heads_to_fetch', ('quack/',),
1412
'success', (['tip'], ['tagged-1', 'tagged-2']))
1413
transport.mkdir('quack')
1414
transport = transport.clone('quack')
1415
branch = self.make_remote_branch(transport, client)
1416
branch._format._use_default_local_heads_to_fetch = lambda: False
1417
result = branch.heads_to_fetch()
1418
self.assertFinished(client)
1419
self.assertEqual((set(['tip']), set(['tagged-1', 'tagged-2'])), result)
1421
def make_branch_with_tags(self):
1422
self.setup_smart_server_with_call_log()
1423
# Make a branch with a single revision.
1424
builder = self.make_branch_builder('foo')
1425
builder.start_series()
1426
builder.build_snapshot('tip', None, [
1427
('add', ('', 'root-id', 'directory', ''))])
1428
builder.finish_series()
1429
branch = builder.get_branch()
1430
# Add two tags to that branch
1431
branch.tags.set_tag('tag-1', 'rev-1')
1432
branch.tags.set_tag('tag-2', 'rev-2')
1435
def test_backwards_compatible(self):
1436
branch = self.make_branch_with_tags()
1437
c = branch.get_config()
1438
c.set_user_option('branch.fetch_tags', 'True')
1439
self.addCleanup(branch.lock_read().unlock)
1440
# Disable the heads_to_fetch verb
1441
verb = 'Branch.heads_to_fetch'
1442
self.disable_verb(verb)
1443
self.reset_smart_call_log()
1444
result = branch.heads_to_fetch()
1445
self.assertEqual((set(['tip']), set(['rev-1', 'rev-2'])), result)
1447
['Branch.last_revision_info', 'Branch.get_config_file',
1448
'Branch.get_tags_bytes'],
1449
[call.call.method for call in self.hpss_calls])
1451
def test_backwards_compatible_no_tags(self):
1452
branch = self.make_branch_with_tags()
1453
c = branch.get_config()
1454
c.set_user_option('branch.fetch_tags', 'False')
1455
self.addCleanup(branch.lock_read().unlock)
1456
# Disable the heads_to_fetch verb
1457
verb = 'Branch.heads_to_fetch'
1458
self.disable_verb(verb)
1459
self.reset_smart_call_log()
1460
result = branch.heads_to_fetch()
1461
self.assertEqual((set(['tip']), set()), result)
1463
['Branch.last_revision_info', 'Branch.get_config_file'],
1464
[call.call.method for call in self.hpss_calls])
1146
1467
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1148
1469
def test_empty_branch(self):
1664
2005
self.assertLength(10, self.hpss_calls)
1665
2006
self.assertEqual('value', branch._get_config().get_option('name'))
2008
def test_backwards_compat_set_option_with_dict(self):
2009
self.setup_smart_server_with_call_log()
2010
branch = self.make_branch('.')
2011
verb = 'Branch.set_config_option_dict'
2012
self.disable_verb(verb)
2014
self.addCleanup(branch.unlock)
2015
self.reset_smart_call_log()
2016
config = branch._get_config()
2017
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
2018
config.set_option(value_dict, 'name')
2019
self.assertLength(10, self.hpss_calls)
2020
self.assertEqual(value_dict, branch._get_config().get_option('name'))
2023
class TestBranchGetPutConfigStore(RemoteBranchTestCase):
2025
def test_get_branch_conf(self):
2026
# in an empty branch we decode the response properly
2027
client = FakeClient()
2028
client.add_expected_call(
2029
'Branch.get_stacked_on_url', ('memory:///',),
2030
'error', ('NotStacked',),)
2031
client.add_success_response_with_body('# config file body', 'ok')
2032
transport = MemoryTransport()
2033
branch = self.make_remote_branch(transport, client)
2034
config = branch.get_config_stack()
2036
config.get("log_format")
2038
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2039
('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
2042
def test_set_branch_conf(self):
2043
client = FakeClient()
2044
client.add_expected_call(
2045
'Branch.get_stacked_on_url', ('memory:///',),
2046
'error', ('NotStacked',),)
2047
client.add_expected_call(
2048
'Branch.lock_write', ('memory:///', '', ''),
2049
'success', ('ok', 'branch token', 'repo token'))
2050
client.add_expected_call(
2051
'Branch.get_config_file', ('memory:///', ),
2052
'success', ('ok', ), "# line 1\n")
2053
client.add_expected_call(
2054
'Branch.get_config_file', ('memory:///', ),
2055
'success', ('ok', ), "# line 1\n")
2056
client.add_expected_call(
2057
'Branch.put_config_file', ('memory:///', 'branch token',
2060
client.add_expected_call(
2061
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
2063
transport = MemoryTransport()
2064
branch = self.make_remote_branch(transport, client)
2066
config = branch.get_config_stack()
2067
config.set('email', 'The Dude <lebowski@example.com>')
2069
self.assertFinished(client)
2071
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
2072
('call', 'Branch.lock_write', ('memory:///', '', '')),
2073
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2074
('call_expecting_body', 'Branch.get_config_file', ('memory:///',)),
2075
('call_with_body_bytes_expecting_body', 'Branch.put_config_file',
2076
('memory:///', 'branch token', 'repo token'),
2077
'# line 1\nemail = The Dude <lebowski@example.com>\n'),
2078
('call', 'Branch.unlock', ('memory:///', 'branch token', 'repo token'))],
1668
2082
class TestBranchLockWrite(RemoteBranchTestCase):
1683
2097
self.assertFinished(client)
2100
class TestBranchRevisionIdToRevno(RemoteBranchTestCase):
2102
def test_simple(self):
2103
transport = MemoryTransport()
2104
client = FakeClient(transport.base)
2105
client.add_expected_call(
2106
'Branch.get_stacked_on_url', ('quack/',),
2107
'error', ('NotStacked',),)
2108
client.add_expected_call(
2109
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2110
'success', ('ok', '0',),)
2111
client.add_expected_call(
2112
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2113
'error', ('NoSuchRevision', 'unknown',),)
2114
transport.mkdir('quack')
2115
transport = transport.clone('quack')
2116
branch = self.make_remote_branch(transport, client)
2117
self.assertEquals(0, branch.revision_id_to_revno('null:'))
2118
self.assertRaises(errors.NoSuchRevision,
2119
branch.revision_id_to_revno, 'unknown')
2120
self.assertFinished(client)
2122
def test_dotted(self):
2123
transport = MemoryTransport()
2124
client = FakeClient(transport.base)
2125
client.add_expected_call(
2126
'Branch.get_stacked_on_url', ('quack/',),
2127
'error', ('NotStacked',),)
2128
client.add_expected_call(
2129
'Branch.revision_id_to_revno', ('quack/', 'null:'),
2130
'success', ('ok', '0',),)
2131
client.add_expected_call(
2132
'Branch.revision_id_to_revno', ('quack/', 'unknown'),
2133
'error', ('NoSuchRevision', 'unknown',),)
2134
transport.mkdir('quack')
2135
transport = transport.clone('quack')
2136
branch = self.make_remote_branch(transport, client)
2137
self.assertEquals((0, ), branch.revision_id_to_dotted_revno('null:'))
2138
self.assertRaises(errors.NoSuchRevision,
2139
branch.revision_id_to_dotted_revno, 'unknown')
2140
self.assertFinished(client)
2142
def test_dotted_no_smart_verb(self):
2143
self.setup_smart_server_with_call_log()
2144
branch = self.make_branch('.')
2145
self.disable_verb('Branch.revision_id_to_revno')
2146
self.reset_smart_call_log()
2147
self.assertEquals((0, ),
2148
branch.revision_id_to_dotted_revno('null:'))
2149
self.assertLength(7, self.hpss_calls)
1686
2152
class TestBzrDirGetSetConfig(RemoteBzrDirTestCase):
1688
2154
def test__get_config(self):
2397
class TestRepositoryBreakLock(TestRemoteRepository):
2399
def test_break_lock(self):
2400
transport_path = 'quack'
2401
repo, client = self.setup_fake_client_and_repository(transport_path)
2402
client.add_success_response('ok')
2405
[('call', 'Repository.break_lock', ('quack/',))],
2409
class TestRepositoryGetSerializerFormat(TestRemoteRepository):
2411
def test_get_serializer_format(self):
2412
transport_path = 'hill'
2413
repo, client = self.setup_fake_client_and_repository(transport_path)
2414
client.add_success_response('ok', '7')
2415
self.assertEquals('7', repo.get_serializer_format())
2417
[('call', 'VersionedFileRepository.get_serializer_format',
2422
class TestRepositoryReconcile(TestRemoteRepository):
2424
def test_reconcile(self):
2425
transport_path = 'hill'
2426
repo, client = self.setup_fake_client_and_repository(transport_path)
2427
body = ("garbage_inventories: 2\n"
2428
"inconsistent_parents: 3\n")
2429
client.add_expected_call(
2430
'Repository.lock_write', ('hill/', ''),
2431
'success', ('ok', 'a token'))
2432
client.add_success_response_with_body(body, 'ok')
2433
reconciler = repo.reconcile()
2435
[('call', 'Repository.lock_write', ('hill/', '')),
2436
('call_expecting_body', 'Repository.reconcile',
2437
('hill/', 'a token'))],
2439
self.assertEquals(2, reconciler.garbage_inventories)
2440
self.assertEquals(3, reconciler.inconsistent_parents)
2443
class TestRepositoryGetRevisionSignatureText(TestRemoteRepository):
2445
def test_text(self):
2446
# ('ok',), body with signature text
2447
transport_path = 'quack'
2448
repo, client = self.setup_fake_client_and_repository(transport_path)
2449
client.add_success_response_with_body(
2451
self.assertEquals("THETEXT", repo.get_signature_text("revid"))
2453
[('call_expecting_body', 'Repository.get_revision_signature_text',
2454
('quack/', 'revid'))],
2457
def test_no_signature(self):
2458
transport_path = 'quick'
2459
repo, client = self.setup_fake_client_and_repository(transport_path)
2460
client.add_error_response('nosuchrevision', 'unknown')
2461
self.assertRaises(errors.NoSuchRevision, repo.get_signature_text,
2464
[('call_expecting_body', 'Repository.get_revision_signature_text',
2465
('quick/', 'unknown'))],
1906
2469
class TestRepositoryGetGraph(TestRemoteRepository):
1908
2471
def test_get_graph(self):
3060
class TestRepositoryWriteGroups(TestRemoteRepository):
3062
def test_start_write_group(self):
3063
transport_path = 'quack'
3064
repo, client = self.setup_fake_client_and_repository(transport_path)
3065
client.add_expected_call(
3066
'Repository.lock_write', ('quack/', ''),
3067
'success', ('ok', 'a token'))
3068
client.add_expected_call(
3069
'Repository.start_write_group', ('quack/', 'a token'),
3070
'success', ('ok', ('token1', )))
3072
repo.start_write_group()
3074
def test_start_write_group_unsuspendable(self):
3075
# Some repositories do not support suspending write
3076
# groups. For those, fall back to the "real" repository.
3077
transport_path = 'quack'
3078
repo, client = self.setup_fake_client_and_repository(transport_path)
3079
def stub_ensure_real():
3080
client._calls.append(('_ensure_real',))
3081
repo._real_repository = _StubRealPackRepository(client._calls)
3082
repo._ensure_real = stub_ensure_real
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
'error', ('UnsuspendableWriteGroup',))
3090
repo.start_write_group()
3091
self.assertEquals(client._calls[-2:], [
3093
('start_write_group',)])
3095
def test_commit_write_group(self):
3096
transport_path = 'quack'
3097
repo, client = self.setup_fake_client_and_repository(transport_path)
3098
client.add_expected_call(
3099
'Repository.lock_write', ('quack/', ''),
3100
'success', ('ok', 'a token'))
3101
client.add_expected_call(
3102
'Repository.start_write_group', ('quack/', 'a token'),
3103
'success', ('ok', ['token1']))
3104
client.add_expected_call(
3105
'Repository.commit_write_group', ('quack/', 'a token', ['token1']),
3108
repo.start_write_group()
3109
repo.commit_write_group()
3111
def test_abort_write_group(self):
3112
transport_path = 'quack'
3113
repo, client = self.setup_fake_client_and_repository(transport_path)
3114
client.add_expected_call(
3115
'Repository.lock_write', ('quack/', ''),
3116
'success', ('ok', 'a token'))
3117
client.add_expected_call(
3118
'Repository.start_write_group', ('quack/', 'a token'),
3119
'success', ('ok', ['token1']))
3120
client.add_expected_call(
3121
'Repository.abort_write_group', ('quack/', 'a token', ['token1']),
3124
repo.start_write_group()
3125
repo.abort_write_group(False)
3127
def test_suspend_write_group(self):
3128
transport_path = 'quack'
3129
repo, client = self.setup_fake_client_and_repository(transport_path)
3130
self.assertEquals([], repo.suspend_write_group())
3132
def test_resume_write_group(self):
3133
transport_path = 'quack'
3134
repo, client = self.setup_fake_client_and_repository(transport_path)
3135
client.add_expected_call(
3136
'Repository.lock_write', ('quack/', ''),
3137
'success', ('ok', 'a token'))
3138
client.add_expected_call(
3139
'Repository.check_write_group', ('quack/', 'a token', ['token1']),
3142
repo.resume_write_group(['token1'])
2329
3145
class TestRepositorySetMakeWorkingTrees(TestRemoteRepository):
2331
3147
def test_backwards_compat(self):
2895
3765
expected_error = errors.PermissionDenied(path, extra)
2896
3766
self.assertEqual(expected_error, translated_error)
3768
# GZ 2011-03-02: TODO test for PermissionDenied with non-ascii 'extra'
3770
def test_NoSuchFile_context_path(self):
3771
local_path = "local path"
3772
translated_error = self.translateTuple(('ReadError', "remote path"),
3774
expected_error = errors.ReadError(local_path)
3775
self.assertEqual(expected_error, translated_error)
3777
def test_NoSuchFile_without_context(self):
3778
remote_path = "remote path"
3779
translated_error = self.translateTuple(('ReadError', remote_path))
3780
expected_error = errors.ReadError(remote_path)
3781
self.assertEqual(expected_error, translated_error)
3783
def test_ReadOnlyError(self):
3784
translated_error = self.translateTuple(('ReadOnlyError',))
3785
expected_error = errors.TransportNotPossible("readonly transport")
3786
self.assertEqual(expected_error, translated_error)
3788
def test_MemoryError(self):
3789
translated_error = self.translateTuple(('MemoryError',))
3790
self.assertStartsWith(str(translated_error),
3791
"remote server out of memory")
3793
def test_generic_IndexError_no_classname(self):
3794
err = errors.ErrorFromSmartServer(('error', "list index out of range"))
3795
translated_error = self.translateErrorFromSmartServer(err)
3796
expected_error = errors.UnknownErrorFromSmartServer(err)
3797
self.assertEqual(expected_error, translated_error)
3799
# GZ 2011-03-02: TODO test generic non-ascii error string
3801
def test_generic_KeyError(self):
3802
err = errors.ErrorFromSmartServer(('error', 'KeyError', "1"))
3803
translated_error = self.translateErrorFromSmartServer(err)
3804
expected_error = errors.UnknownErrorFromSmartServer(err)
3805
self.assertEqual(expected_error, translated_error)
2899
3808
class TestErrorTranslationRobustness(TestErrorTranslationBase):
2900
3809
"""Unit tests for bzrlib.remote._translate_error's robustness.
3143
4054
def test_copy_content_into_avoids_revision_history(self):
3144
4055
local = self.make_branch('local')
3145
remote_backing_tree = self.make_branch_and_tree('remote')
3146
remote_backing_tree.commit("Commit.")
4056
builder = self.make_branch_builder('remote')
4057
builder.build_commit(message="Commit.")
3147
4058
remote_branch_url = self.smart_server.get_url() + 'remote'
3148
4059
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
3149
4060
local.repository.fetch(remote_branch.repository)
3150
4061
self.hpss_calls = []
3151
4062
remote_branch.copy_content_into(local)
3152
4063
self.assertFalse('Branch.revision_history' in self.hpss_calls)
4065
def test_fetch_everything_needs_just_one_call(self):
4066
local = self.make_branch('local')
4067
builder = self.make_branch_builder('remote')
4068
builder.build_commit(message="Commit.")
4069
remote_branch_url = self.smart_server.get_url() + 'remote'
4070
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4071
self.hpss_calls = []
4072
local.repository.fetch(
4073
remote_branch.repository,
4074
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4075
self.assertEqual(['Repository.get_stream_1.19'], self.hpss_calls)
4077
def override_verb(self, verb_name, verb):
4078
request_handlers = request.request_handlers
4079
orig_verb = request_handlers.get(verb_name)
4080
orig_info = request_handlers.get_info(verb_name)
4081
request_handlers.register(verb_name, verb, override_existing=True)
4082
self.addCleanup(request_handlers.register, verb_name, orig_verb,
4083
override_existing=True, info=orig_info)
4085
def test_fetch_everything_backwards_compat(self):
4086
"""Can fetch with EverythingResult even with pre 2.4 servers.
4088
Pre-2.4 do not support 'everything' searches with the
4089
Repository.get_stream_1.19 verb.
4092
class OldGetStreamVerb(SmartServerRepositoryGetStream_1_19):
4093
"""A version of the Repository.get_stream_1.19 verb patched to
4094
reject 'everything' searches the way 2.3 and earlier do.
4096
def recreate_search(self, repository, search_bytes,
4097
discard_excess=False):
4098
verb_log.append(search_bytes.split('\n', 1)[0])
4099
if search_bytes == 'everything':
4101
request.FailedSmartServerResponse(('BadSearch',)))
4102
return super(OldGetStreamVerb,
4103
self).recreate_search(repository, search_bytes,
4104
discard_excess=discard_excess)
4105
self.override_verb('Repository.get_stream_1.19', OldGetStreamVerb)
4106
local = self.make_branch('local')
4107
builder = self.make_branch_builder('remote')
4108
builder.build_commit(message="Commit.")
4109
remote_branch_url = self.smart_server.get_url() + 'remote'
4110
remote_branch = bzrdir.BzrDir.open(remote_branch_url).open_branch()
4111
self.hpss_calls = []
4112
local.repository.fetch(
4113
remote_branch.repository,
4114
fetch_spec=vf_search.EverythingResult(remote_branch.repository))
4115
# make sure the overridden verb was used
4116
self.assertLength(1, verb_log)
4117
# more than one HPSS call is needed, but because it's a VFS callback
4118
# its hard to predict exactly how many.
4119
self.assertTrue(len(self.hpss_calls) > 1)
4122
class TestUpdateBoundBranchWithModifiedBoundLocation(
4123
tests.TestCaseWithTransport):
4124
"""Ensure correct handling of bound_location modifications.
4126
This is tested against a smart server as http://pad.lv/786980 was about a
4127
ReadOnlyError (write attempt during a read-only transaction) which can only
4128
happen in this context.
4132
super(TestUpdateBoundBranchWithModifiedBoundLocation, self).setUp()
4133
self.transport_server = test_server.SmartTCPServer_for_testing
4135
def make_master_and_checkout(self, master_name, checkout_name):
4136
# Create the master branch and its associated checkout
4137
self.master = self.make_branch_and_tree(master_name)
4138
self.checkout = self.master.branch.create_checkout(checkout_name)
4139
# Modify the master branch so there is something to update
4140
self.master.commit('add stuff')
4141
self.last_revid = self.master.commit('even more stuff')
4142
self.bound_location = self.checkout.branch.get_bound_location()
4144
def assertUpdateSucceeds(self, new_location):
4145
self.checkout.lock_write()
4147
self.checkout.branch.set_bound_location(new_location)
4148
self.checkout.update()
4150
self.checkout.unlock()
4151
self.assertEquals(self.last_revid, self.checkout.last_revision())
4153
def test_without_final_slash(self):
4154
self.make_master_and_checkout('master', 'checkout')
4155
# For unclear reasons some users have a bound_location without a final
4156
# '/', simulate that by forcing such a value
4157
self.assertEndsWith(self.bound_location, '/')
4158
self.assertUpdateSucceeds(self.bound_location.rstrip('/'))
4160
def test_plus_sign(self):
4161
self.make_master_and_checkout('+master', 'checkout')
4162
self.assertUpdateSucceeds(self.bound_location.replace('%2B', '+', 1))
4164
def test_tilda(self):
4165
# Embed ~ in the middle of the path just to avoid any $HOME
4167
self.make_master_and_checkout('mas~ter', 'checkout')
4168
self.assertUpdateSucceeds(self.bound_location.replace('%2E', '~', 1))
4171
class TestWithCustomErrorHandler(RemoteBranchTestCase):
4173
def test_no_context(self):
4174
class OutOfCoffee(errors.BzrError):
4175
"""A dummy exception for testing."""
4177
def __init__(self, urgency):
4178
self.urgency = urgency
4179
remote.no_context_error_translators.register("OutOfCoffee",
4180
lambda err: OutOfCoffee(err.error_args[0]))
4181
transport = MemoryTransport()
4182
client = FakeClient(transport.base)
4183
client.add_expected_call(
4184
'Branch.get_stacked_on_url', ('quack/',),
4185
'error', ('NotStacked',))
4186
client.add_expected_call(
4187
'Branch.last_revision_info',
4189
'error', ('OutOfCoffee', 'low'))
4190
transport.mkdir('quack')
4191
transport = transport.clone('quack')
4192
branch = self.make_remote_branch(transport, client)
4193
self.assertRaises(OutOfCoffee, branch.last_revision_info)
4194
self.assertFinished(client)
4196
def test_with_context(self):
4197
class OutOfTea(errors.BzrError):
4198
def __init__(self, branch, urgency):
4199
self.branch = branch
4200
self.urgency = urgency
4201
remote.error_translators.register("OutOfTea",
4202
lambda err, find, path: OutOfTea(err.error_args[0],
4204
transport = MemoryTransport()
4205
client = FakeClient(transport.base)
4206
client.add_expected_call(
4207
'Branch.get_stacked_on_url', ('quack/',),
4208
'error', ('NotStacked',))
4209
client.add_expected_call(
4210
'Branch.last_revision_info',
4212
'error', ('OutOfTea', 'low'))
4213
transport.mkdir('quack')
4214
transport = transport.clone('quack')
4215
branch = self.make_remote_branch(transport, client)
4216
self.assertRaises(OutOfTea, branch.last_revision_info)
4217
self.assertFinished(client)
4220
class TestRepositoryPack(TestRemoteRepository):
4222
def test_pack(self):
4223
transport_path = 'quack'
4224
repo, client = self.setup_fake_client_and_repository(transport_path)
4225
client.add_expected_call(
4226
'Repository.lock_write', ('quack/', ''),
4227
'success', ('ok', 'token'))
4228
client.add_expected_call(
4229
'Repository.pack', ('quack/', 'token', 'False'),
4230
'success', ('ok',), )
4231
client.add_expected_call(
4232
'Repository.unlock', ('quack/', 'token'),
4233
'success', ('ok', ))
4236
def test_pack_with_hint(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', 'False'),
4247
'success', ('ok', ))
4248
repo.pack(['hinta', 'hintb'])
4251
class TestRepositoryIterInventories(TestRemoteRepository):
4252
"""Test Repository.iter_inventories."""
4254
def _serialize_inv_delta(self, old_name, new_name, delta):
4255
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
4256
return "".join(serializer.delta_to_lines(old_name, new_name, delta))
4258
def test_single_empty(self):
4259
transport_path = 'quack'
4260
repo, client = self.setup_fake_client_and_repository(transport_path)
4261
fmt = bzrdir.format_registry.get('2a')().repository_format
4263
stream = [('inventory-deltas', [
4264
versionedfile.FulltextContentFactory('somerevid', None, None,
4265
self._serialize_inv_delta('null:', 'somerevid', []))])]
4266
client.add_expected_call(
4267
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4268
'success', ('ok', ),
4269
_stream_to_byte_stream(stream, fmt))
4270
ret = list(repo.iter_inventories(["somerevid"]))
4271
self.assertLength(1, ret)
4273
self.assertEquals("somerevid", inv.revision_id)
4275
def test_empty(self):
4276
transport_path = 'quack'
4277
repo, client = self.setup_fake_client_and_repository(transport_path)
4278
ret = list(repo.iter_inventories([]))
4279
self.assertEquals(ret, [])
4281
def test_missing(self):
4282
transport_path = 'quack'
4283
repo, client = self.setup_fake_client_and_repository(transport_path)
4284
client.add_expected_call(
4285
'VersionedFileRepository.get_inventories', ('quack/', 'unordered'),
4286
'success', ('ok', ), iter([]))
4287
self.assertRaises(errors.NoSuchRevision, list, repo.iter_inventories(