478
448
self.assertEqual(bzrdir.BzrDirMetaFormat1, type(result))
479
449
self.assertEqual(None, result._repository_format)
480
450
self.assertEqual(None, result._branch_format)
481
self.assertFinished(client)
484
class TestBzrDirOpen(TestRemote):
486
def make_fake_client_and_transport(self, path='quack'):
487
transport = MemoryTransport()
488
transport.mkdir(path)
489
transport = transport.clone(path)
490
client = FakeClient(transport.base)
491
return client, transport
493
def test_absent(self):
494
client, transport = self.make_fake_client_and_transport()
495
client.add_expected_call(
496
'BzrDir.open_2.1', ('quack/',), 'success', ('no',))
497
self.assertRaises(errors.NotBranchError, RemoteBzrDir, transport,
498
remote.RemoteBzrDirFormat(), _client=client, _force_probe=True)
499
self.assertFinished(client)
501
def test_present_without_workingtree(self):
502
client, transport = self.make_fake_client_and_transport()
503
client.add_expected_call(
504
'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'no'))
505
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
506
_client=client, _force_probe=True)
507
self.assertIsInstance(bd, RemoteBzrDir)
508
self.assertFalse(bd.has_workingtree())
509
self.assertRaises(errors.NoWorkingTree, bd.open_workingtree)
510
self.assertFinished(client)
512
def test_present_with_workingtree(self):
513
client, transport = self.make_fake_client_and_transport()
514
client.add_expected_call(
515
'BzrDir.open_2.1', ('quack/',), 'success', ('yes', 'yes'))
516
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
517
_client=client, _force_probe=True)
518
self.assertIsInstance(bd, RemoteBzrDir)
519
self.assertTrue(bd.has_workingtree())
520
self.assertRaises(errors.NotLocalUrl, bd.open_workingtree)
521
self.assertFinished(client)
523
def test_backwards_compat(self):
524
client, transport = self.make_fake_client_and_transport()
525
client.add_expected_call(
526
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
527
client.add_expected_call(
528
'BzrDir.open', ('quack/',), 'success', ('yes',))
529
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
530
_client=client, _force_probe=True)
531
self.assertIsInstance(bd, RemoteBzrDir)
532
self.assertFinished(client)
534
def test_backwards_compat_hpss_v2(self):
535
client, transport = self.make_fake_client_and_transport()
536
# Monkey-patch fake client to simulate real-world behaviour with v2
537
# server: upon first RPC call detect the protocol version, and because
538
# the version is 2 also do _remember_remote_is_before((1, 6)) before
539
# continuing with the RPC.
540
orig_check_call = client._check_call
541
def check_call(method, args):
542
client._medium._protocol_version = 2
543
client._medium._remember_remote_is_before((1, 6))
544
client._check_call = orig_check_call
545
client._check_call(method, args)
546
client._check_call = check_call
547
client.add_expected_call(
548
'BzrDir.open_2.1', ('quack/',), 'unknown', ('BzrDir.open_2.1',))
549
client.add_expected_call(
550
'BzrDir.open', ('quack/',), 'success', ('yes',))
551
bd = RemoteBzrDir(transport, remote.RemoteBzrDirFormat(),
552
_client=client, _force_probe=True)
553
self.assertIsInstance(bd, RemoteBzrDir)
554
self.assertFinished(client)
451
client.finished_test()
557
454
class TestBzrDirOpenBranch(TestRemote):
848
740
self.assertEqual(network_name, repo._format.network_name())
851
class TestBzrDirFormatInitializeEx(TestRemote):
853
def test_success(self):
854
"""Simple test for typical successful call."""
855
fmt = bzrdir.RemoteBzrDirFormat()
856
default_format_name = BzrDirFormat.get_default_format().network_name()
857
transport = self.get_transport()
858
client = FakeClient(transport.base)
859
client.add_expected_call(
860
'BzrDirFormat.initialize_ex_1.16',
861
(default_format_name, 'path', 'False', 'False', 'False', '',
862
'', '', '', 'False'),
864
('.', 'no', 'no', 'yes', 'repo fmt', 'repo bzrdir fmt',
865
'bzrdir fmt', 'False', '', '', 'repo lock token'))
866
# XXX: It would be better to call fmt.initialize_on_transport_ex, but
867
# it's currently hard to test that without supplying a real remote
868
# transport connected to a real server.
869
result = fmt._initialize_on_transport_ex_rpc(client, 'path',
870
transport, False, False, False, None, None, None, None, False)
871
self.assertFinished(client)
873
def test_error(self):
874
"""Error responses are translated, e.g. 'PermissionDenied' raises the
875
corresponding error from the client.
877
fmt = bzrdir.RemoteBzrDirFormat()
878
default_format_name = BzrDirFormat.get_default_format().network_name()
879
transport = self.get_transport()
880
client = FakeClient(transport.base)
881
client.add_expected_call(
882
'BzrDirFormat.initialize_ex_1.16',
883
(default_format_name, 'path', 'False', 'False', 'False', '',
884
'', '', '', 'False'),
886
('PermissionDenied', 'path', 'extra info'))
887
# XXX: It would be better to call fmt.initialize_on_transport_ex, but
888
# it's currently hard to test that without supplying a real remote
889
# transport connected to a real server.
890
err = self.assertRaises(errors.PermissionDenied,
891
fmt._initialize_on_transport_ex_rpc, client, 'path', transport,
892
False, False, False, None, None, None, None, False)
893
self.assertEqual('path', err.path)
894
self.assertEqual(': extra info', err.extra)
895
self.assertFinished(client)
897
def test_error_from_real_server(self):
898
"""Integration test for error translation."""
899
transport = self.make_smart_server('foo')
900
transport = transport.clone('no-such-path')
901
fmt = bzrdir.RemoteBzrDirFormat()
902
err = self.assertRaises(errors.NoSuchFile,
903
fmt.initialize_on_transport_ex, transport, create_prefix=False)
906
743
class OldSmartClient(object):
907
744
"""A fake smart client for test_old_version that just returns a version one
908
745
response to the 'hello' (query version) command.
1091
863
transport = transport.clone('quack')
1092
864
branch = self.make_remote_branch(transport, client)
1093
865
result = branch.tags.get_tag_dict()
1094
self.assertFinished(client)
866
client.finished_test()
1095
867
self.assertEqual({}, result)
1098
class TestBranchSetTagsBytes(RemoteBranchTestCase):
1100
def test_trivial(self):
1101
transport = MemoryTransport()
1102
client = FakeClient(transport.base)
1103
client.add_expected_call(
1104
'Branch.get_stacked_on_url', ('quack/',),
1105
'error', ('NotStacked',))
1106
client.add_expected_call(
1107
'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1109
transport.mkdir('quack')
1110
transport = transport.clone('quack')
1111
branch = self.make_remote_branch(transport, client)
1112
self.lock_remote_branch(branch)
1113
branch._set_tags_bytes('tags bytes')
1114
self.assertFinished(client)
1115
self.assertEqual('tags bytes', client._calls[-1][-1])
1117
def test_backwards_compatible(self):
1118
transport = MemoryTransport()
1119
client = FakeClient(transport.base)
1120
client.add_expected_call(
1121
'Branch.get_stacked_on_url', ('quack/',),
1122
'error', ('NotStacked',))
1123
client.add_expected_call(
1124
'Branch.set_tags_bytes', ('quack/', 'branch token', 'repo token'),
1125
'unknown', ('Branch.set_tags_bytes',))
1126
transport.mkdir('quack')
1127
transport = transport.clone('quack')
1128
branch = self.make_remote_branch(transport, client)
1129
self.lock_remote_branch(branch)
1130
class StubRealBranch(object):
1133
def _set_tags_bytes(self, bytes):
1134
self.calls.append(('set_tags_bytes', bytes))
1135
real_branch = StubRealBranch()
1136
branch._real_branch = real_branch
1137
branch._set_tags_bytes('tags bytes')
1138
# Call a second time, to exercise the 'remote version already inferred'
1140
branch._set_tags_bytes('tags bytes')
1141
self.assertFinished(client)
1143
[('set_tags_bytes', 'tags bytes')] * 2, real_branch.calls)
1146
870
class TestBranchLastRevisionInfo(RemoteBranchTestCase):
1148
872
def test_empty_branch(self):
1597
1332
self.assertEqual('rejection message', err.msg)
1600
class TestBranchGetSetConfig(RemoteBranchTestCase):
1335
class TestBranchControlGetBranchConf(tests.TestCaseWithMemoryTransport):
1336
"""Getting the branch configuration should use an abstract method not vfs.
1602
1339
def test_get_branch_conf(self):
1603
# in an empty branch we decode the response properly
1604
client = FakeClient()
1605
client.add_expected_call(
1606
'Branch.get_stacked_on_url', ('memory:///',),
1607
'error', ('NotStacked',),)
1608
client.add_success_response_with_body('# config file body', 'ok')
1609
transport = MemoryTransport()
1610
branch = self.make_remote_branch(transport, client)
1611
config = branch.get_config()
1612
config.has_explicit_nickname()
1614
[('call', 'Branch.get_stacked_on_url', ('memory:///',)),
1615
('call_expecting_body', 'Branch.get_config_file', ('memory:///',))],
1618
def test_get_multi_line_branch_conf(self):
1619
# Make sure that multiple-line branch.conf files are supported
1621
# https://bugs.launchpad.net/bzr/+bug/354075
1622
client = FakeClient()
1623
client.add_expected_call(
1624
'Branch.get_stacked_on_url', ('memory:///',),
1625
'error', ('NotStacked',),)
1626
client.add_success_response_with_body('a = 1\nb = 2\nc = 3\n', 'ok')
1627
transport = MemoryTransport()
1628
branch = self.make_remote_branch(transport, client)
1629
config = branch.get_config()
1630
self.assertEqual(u'2', config.get_user_option('b'))
1632
def test_set_option(self):
1633
client = FakeClient()
1634
client.add_expected_call(
1635
'Branch.get_stacked_on_url', ('memory:///',),
1636
'error', ('NotStacked',),)
1637
client.add_expected_call(
1638
'Branch.lock_write', ('memory:///', '', ''),
1639
'success', ('ok', 'branch token', 'repo token'))
1640
client.add_expected_call(
1641
'Branch.set_config_option', ('memory:///', 'branch token',
1642
'repo token', 'foo', 'bar', ''),
1644
client.add_expected_call(
1645
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1647
transport = MemoryTransport()
1648
branch = self.make_remote_branch(transport, client)
1650
config = branch._get_config()
1651
config.set_option('foo', 'bar')
1653
self.assertFinished(client)
1655
def test_set_option_with_dict(self):
1656
client = FakeClient()
1657
client.add_expected_call(
1658
'Branch.get_stacked_on_url', ('memory:///',),
1659
'error', ('NotStacked',),)
1660
client.add_expected_call(
1661
'Branch.lock_write', ('memory:///', '', ''),
1662
'success', ('ok', 'branch token', 'repo token'))
1663
encoded_dict_value = 'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde'
1664
client.add_expected_call(
1665
'Branch.set_config_option_dict', ('memory:///', 'branch token',
1666
'repo token', encoded_dict_value, 'foo', ''),
1668
client.add_expected_call(
1669
'Branch.unlock', ('memory:///', 'branch token', 'repo token'),
1671
transport = MemoryTransport()
1672
branch = self.make_remote_branch(transport, client)
1674
config = branch._get_config()
1676
{'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'},
1679
self.assertFinished(client)
1681
def test_backwards_compat_set_option(self):
1682
self.setup_smart_server_with_call_log()
1683
branch = self.make_branch('.')
1684
verb = 'Branch.set_config_option'
1685
self.disable_verb(verb)
1687
self.addCleanup(branch.unlock)
1688
self.reset_smart_call_log()
1689
branch._get_config().set_option('value', 'name')
1690
self.assertLength(10, self.hpss_calls)
1691
self.assertEqual('value', branch._get_config().get_option('name'))
1693
def test_backwards_compat_set_option_with_dict(self):
1694
self.setup_smart_server_with_call_log()
1695
branch = self.make_branch('.')
1696
verb = 'Branch.set_config_option_dict'
1697
self.disable_verb(verb)
1699
self.addCleanup(branch.unlock)
1700
self.reset_smart_call_log()
1701
config = branch._get_config()
1702
value_dict = {'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
1703
config.set_option(value_dict, 'name')
1704
self.assertLength(10, self.hpss_calls)
1705
self.assertEqual(value_dict, branch._get_config().get_option('name'))
1340
raise tests.KnownFailure('branch.conf is not retrieved by get_config_file')
1341
## # We should see that branch.get_config() does a single rpc to get the
1342
## # remote configuration file, abstracting away where that is stored on
1343
## # the server. However at the moment it always falls back to using the
1344
## # vfs, and this would need some changes in config.py.
1346
## # in an empty branch we decode the response properly
1347
## client = FakeClient([(('ok', ), '# config file body')], self.get_url())
1348
## # we need to make a real branch because the remote_branch.control_files
1349
## # will trigger _ensure_real.
1350
## branch = self.make_branch('quack')
1351
## transport = branch.bzrdir.root_transport
1352
## # we do not want bzrdir to make any remote calls
1353
## bzrdir = RemoteBzrDir(transport, _client=False)
1354
## branch = RemoteBranch(bzrdir, None, _client=client)
1355
## config = branch.get_config()
1356
## self.assertEqual(
1357
## [('call_expecting_body', 'Branch.get_config_file', ('quack/',))],
1708
1361
class TestBranchLockWrite(RemoteBranchTestCase):
2230
1795
self.assertEqual(('AnUnexpectedError',), e.error_tuple)
2233
class TestRepositoryGetRevIdForRevno(TestRemoteRepository):
2236
repo, client = self.setup_fake_client_and_repository('quack')
2237
client.add_expected_call(
2238
'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2239
'success', ('ok', 'rev-five'))
2240
result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2241
self.assertEqual((True, 'rev-five'), result)
2242
self.assertFinished(client)
2244
def test_history_incomplete(self):
2245
repo, client = self.setup_fake_client_and_repository('quack')
2246
client.add_expected_call(
2247
'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2248
'success', ('history-incomplete', 10, 'rev-ten'))
2249
result = repo.get_rev_id_for_revno(5, (42, 'rev-foo'))
2250
self.assertEqual((False, (10, 'rev-ten')), result)
2251
self.assertFinished(client)
2253
def test_history_incomplete_with_fallback(self):
2254
"""A 'history-incomplete' response causes the fallback repository to be
2255
queried too, if one is set.
2257
# Make a repo with a fallback repo, both using a FakeClient.
2258
format = remote.response_tuple_to_repo_format(
2259
('yes', 'no', 'yes', self.get_repo_format().network_name()))
2260
repo, client = self.setup_fake_client_and_repository('quack')
2261
repo._format = format
2262
fallback_repo, ignored = self.setup_fake_client_and_repository(
2264
fallback_repo._client = client
2265
fallback_repo._format = format
2266
repo.add_fallback_repository(fallback_repo)
2267
# First the client should ask the primary repo
2268
client.add_expected_call(
2269
'Repository.get_rev_id_for_revno', ('quack/', 1, (42, 'rev-foo')),
2270
'success', ('history-incomplete', 2, 'rev-two'))
2271
# Then it should ask the fallback, using revno/revid from the
2272
# history-incomplete response as the known revno/revid.
2273
client.add_expected_call(
2274
'Repository.get_rev_id_for_revno',('fallback/', 1, (2, 'rev-two')),
2275
'success', ('ok', 'rev-one'))
2276
result = repo.get_rev_id_for_revno(1, (42, 'rev-foo'))
2277
self.assertEqual((True, 'rev-one'), result)
2278
self.assertFinished(client)
2280
def test_nosuchrevision(self):
2281
# 'nosuchrevision' is returned when the known-revid is not found in the
2282
# remote repo. The client translates that response to NoSuchRevision.
2283
repo, client = self.setup_fake_client_and_repository('quack')
2284
client.add_expected_call(
2285
'Repository.get_rev_id_for_revno', ('quack/', 5, (42, 'rev-foo')),
2286
'error', ('nosuchrevision', 'rev-foo'))
2288
errors.NoSuchRevision,
2289
repo.get_rev_id_for_revno, 5, (42, 'rev-foo'))
2290
self.assertFinished(client)
2292
def test_branch_fallback_locking(self):
2293
"""RemoteBranch.get_rev_id takes a read lock, and tries to call the
2294
get_rev_id_for_revno verb. If the verb is unknown the VFS fallback
2295
will be invoked, which will fail if the repo is unlocked.
2297
self.setup_smart_server_with_call_log()
2298
tree = self.make_branch_and_memory_tree('.')
2301
rev1 = tree.commit('First')
2302
rev2 = tree.commit('Second')
2304
branch = tree.branch
2305
self.assertFalse(branch.is_locked())
2306
self.reset_smart_call_log()
2307
verb = 'Repository.get_rev_id_for_revno'
2308
self.disable_verb(verb)
2309
self.assertEqual(rev1, branch.get_rev_id(1))
2310
self.assertLength(1, [call for call in self.hpss_calls if
2311
call.call.method == verb])
2314
1798
class TestRepositoryIsShared(TestRemoteRepository):
2316
1800
def test_is_shared(self):
2431
1915
self.assertEqual([], client._calls)
2434
class TestRepositoryInsertStreamBase(TestRemoteRepository):
2435
"""Base class for Repository.insert_stream and .insert_stream_1.19
2439
def checkInsertEmptyStream(self, repo, client):
2440
"""Insert an empty stream, checking the result.
2442
This checks that there are no resume_tokens or missing_keys, and that
2443
the client is finished.
2445
sink = repo._get_sink()
2446
fmt = repository.RepositoryFormat.get_default_format()
2447
resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
2448
self.assertEqual([], resume_tokens)
2449
self.assertEqual(set(), missing_keys)
2450
self.assertFinished(client)
2453
class TestRepositoryInsertStream(TestRepositoryInsertStreamBase):
2454
"""Tests for using Repository.insert_stream verb when the _1.19 variant is
2457
This test case is very similar to TestRepositoryInsertStream_1_19.
2461
TestRemoteRepository.setUp(self)
2462
self.disable_verb('Repository.insert_stream_1.19')
2464
def test_unlocked_repo(self):
2465
transport_path = 'quack'
2466
repo, client = self.setup_fake_client_and_repository(transport_path)
2467
client.add_expected_call(
2468
'Repository.insert_stream_1.19', ('quack/', ''),
2469
'unknown', ('Repository.insert_stream_1.19',))
2470
client.add_expected_call(
2471
'Repository.insert_stream', ('quack/', ''),
2473
client.add_expected_call(
2474
'Repository.insert_stream', ('quack/', ''),
2476
self.checkInsertEmptyStream(repo, client)
2478
def test_locked_repo_with_no_lock_token(self):
2479
transport_path = 'quack'
2480
repo, client = self.setup_fake_client_and_repository(transport_path)
2481
client.add_expected_call(
2482
'Repository.lock_write', ('quack/', ''),
2483
'success', ('ok', ''))
2484
client.add_expected_call(
2485
'Repository.insert_stream_1.19', ('quack/', ''),
2486
'unknown', ('Repository.insert_stream_1.19',))
2487
client.add_expected_call(
2488
'Repository.insert_stream', ('quack/', ''),
2490
client.add_expected_call(
2491
'Repository.insert_stream', ('quack/', ''),
2494
self.checkInsertEmptyStream(repo, client)
2496
def test_locked_repo_with_lock_token(self):
2497
transport_path = 'quack'
2498
repo, client = self.setup_fake_client_and_repository(transport_path)
2499
client.add_expected_call(
2500
'Repository.lock_write', ('quack/', ''),
2501
'success', ('ok', 'a token'))
2502
client.add_expected_call(
2503
'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2504
'unknown', ('Repository.insert_stream_1.19',))
2505
client.add_expected_call(
2506
'Repository.insert_stream_locked', ('quack/', '', 'a token'),
2508
client.add_expected_call(
2509
'Repository.insert_stream_locked', ('quack/', '', 'a token'),
2512
self.checkInsertEmptyStream(repo, client)
2514
def test_stream_with_inventory_deltas(self):
2515
"""'inventory-deltas' substreams cannot be sent to the
2516
Repository.insert_stream verb, because not all servers that implement
2517
that verb will accept them. So when one is encountered the RemoteSink
2518
immediately stops using that verb and falls back to VFS insert_stream.
2520
transport_path = 'quack'
2521
repo, client = self.setup_fake_client_and_repository(transport_path)
2522
client.add_expected_call(
2523
'Repository.insert_stream_1.19', ('quack/', ''),
2524
'unknown', ('Repository.insert_stream_1.19',))
2525
client.add_expected_call(
2526
'Repository.insert_stream', ('quack/', ''),
2528
client.add_expected_call(
2529
'Repository.insert_stream', ('quack/', ''),
2531
# Create a fake real repository for insert_stream to fall back on, so
2532
# that we can directly see the records the RemoteSink passes to the
2537
def insert_stream(self, stream, src_format, resume_tokens):
2538
for substream_kind, substream in stream:
2539
self.records.append(
2540
(substream_kind, [record.key for record in substream]))
2541
return ['fake tokens'], ['fake missing keys']
2542
fake_real_sink = FakeRealSink()
2543
class FakeRealRepository:
2544
def _get_sink(self):
2545
return fake_real_sink
2546
def is_in_write_group(self):
2548
def refresh_data(self):
2550
repo._real_repository = FakeRealRepository()
2551
sink = repo._get_sink()
2552
fmt = repository.RepositoryFormat.get_default_format()
2553
stream = self.make_stream_with_inv_deltas(fmt)
2554
resume_tokens, missing_keys = sink.insert_stream(stream, fmt, [])
2555
# Every record from the first inventory delta should have been sent to
2557
expected_records = [
2558
('inventory-deltas', [('rev2',), ('rev3',)]),
2559
('texts', [('some-rev', 'some-file')])]
2560
self.assertEqual(expected_records, fake_real_sink.records)
2561
# The return values from the real sink's insert_stream are propagated
2562
# back to the original caller.
2563
self.assertEqual(['fake tokens'], resume_tokens)
2564
self.assertEqual(['fake missing keys'], missing_keys)
2565
self.assertFinished(client)
2567
def make_stream_with_inv_deltas(self, fmt):
2568
"""Make a simple stream with an inventory delta followed by more
2569
records and more substreams to test that all records and substreams
2570
from that point on are used.
2572
This sends, in order:
2573
* inventories substream: rev1, rev2, rev3. rev2 and rev3 are
2575
* texts substream: (some-rev, some-file)
2577
# Define a stream using generators so that it isn't rewindable.
2578
inv = inventory.Inventory(revision_id='rev1')
2579
inv.root.revision = 'rev1'
2580
def stream_with_inv_delta():
2581
yield ('inventories', inventories_substream())
2582
yield ('inventory-deltas', inventory_delta_substream())
2584
versionedfile.FulltextContentFactory(
2585
('some-rev', 'some-file'), (), None, 'content')])
2586
def inventories_substream():
2587
# An empty inventory fulltext. This will be streamed normally.
2588
text = fmt._serializer.write_inventory_to_string(inv)
2589
yield versionedfile.FulltextContentFactory(
2590
('rev1',), (), None, text)
2591
def inventory_delta_substream():
2592
# An inventory delta. This can't be streamed via this verb, so it
2593
# will trigger a fallback to VFS insert_stream.
2594
entry = inv.make_entry(
2595
'directory', 'newdir', inv.root.file_id, 'newdir-id')
2596
entry.revision = 'ghost'
2597
delta = [(None, 'newdir', 'newdir-id', entry)]
2598
serializer = inventory_delta.InventoryDeltaSerializer(
2599
versioned_root=True, tree_references=False)
2600
lines = serializer.delta_to_lines('rev1', 'rev2', delta)
2601
yield versionedfile.ChunkedContentFactory(
2602
('rev2',), (('rev1',)), None, lines)
2604
lines = serializer.delta_to_lines('rev1', 'rev3', delta)
2605
yield versionedfile.ChunkedContentFactory(
2606
('rev3',), (('rev1',)), None, lines)
2607
return stream_with_inv_delta()
2610
class TestRepositoryInsertStream_1_19(TestRepositoryInsertStreamBase):
2612
def test_unlocked_repo(self):
2613
transport_path = 'quack'
2614
repo, client = self.setup_fake_client_and_repository(transport_path)
2615
client.add_expected_call(
2616
'Repository.insert_stream_1.19', ('quack/', ''),
2618
client.add_expected_call(
2619
'Repository.insert_stream_1.19', ('quack/', ''),
2621
self.checkInsertEmptyStream(repo, client)
2623
def test_locked_repo_with_no_lock_token(self):
2624
transport_path = 'quack'
2625
repo, client = self.setup_fake_client_and_repository(transport_path)
2626
client.add_expected_call(
2627
'Repository.lock_write', ('quack/', ''),
2628
'success', ('ok', ''))
2629
client.add_expected_call(
2630
'Repository.insert_stream_1.19', ('quack/', ''),
2632
client.add_expected_call(
2633
'Repository.insert_stream_1.19', ('quack/', ''),
2636
self.checkInsertEmptyStream(repo, client)
2638
def test_locked_repo_with_lock_token(self):
2639
transport_path = 'quack'
2640
repo, client = self.setup_fake_client_and_repository(transport_path)
2641
client.add_expected_call(
2642
'Repository.lock_write', ('quack/', ''),
2643
'success', ('ok', 'a token'))
2644
client.add_expected_call(
2645
'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2647
client.add_expected_call(
2648
'Repository.insert_stream_1.19', ('quack/', '', 'a token'),
2651
self.checkInsertEmptyStream(repo, client)
1918
class TestRepositoryInsertStream(TestRemoteRepository):
1920
def test_unlocked_repo(self):
1921
transport_path = 'quack'
1922
repo, client = self.setup_fake_client_and_repository(transport_path)
1923
client.add_expected_call(
1924
'Repository.insert_stream', ('quack/', ''),
1926
client.add_expected_call(
1927
'Repository.insert_stream', ('quack/', ''),
1929
sink = repo._get_sink()
1930
fmt = repository.RepositoryFormat.get_default_format()
1931
resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
1932
self.assertEqual([], resume_tokens)
1933
self.assertEqual(set(), missing_keys)
1934
client.finished_test()
1936
def test_locked_repo_with_no_lock_token(self):
1937
transport_path = 'quack'
1938
repo, client = self.setup_fake_client_and_repository(transport_path)
1939
client.add_expected_call(
1940
'Repository.lock_write', ('quack/', ''),
1941
'success', ('ok', ''))
1942
client.add_expected_call(
1943
'Repository.insert_stream', ('quack/', ''),
1945
client.add_expected_call(
1946
'Repository.insert_stream', ('quack/', ''),
1949
sink = repo._get_sink()
1950
fmt = repository.RepositoryFormat.get_default_format()
1951
resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
1952
self.assertEqual([], resume_tokens)
1953
self.assertEqual(set(), missing_keys)
1954
client.finished_test()
1956
def test_locked_repo_with_lock_token(self):
1957
transport_path = 'quack'
1958
repo, client = self.setup_fake_client_and_repository(transport_path)
1959
client.add_expected_call(
1960
'Repository.lock_write', ('quack/', ''),
1961
'success', ('ok', 'a token'))
1962
client.add_expected_call(
1963
'Repository.insert_stream_locked', ('quack/', '', 'a token'),
1965
client.add_expected_call(
1966
'Repository.insert_stream_locked', ('quack/', '', 'a token'),
1969
sink = repo._get_sink()
1970
fmt = repository.RepositoryFormat.get_default_format()
1971
resume_tokens, missing_keys = sink.insert_stream([], fmt, [])
1972
self.assertEqual([], resume_tokens)
1973
self.assertEqual(set(), missing_keys)
1974
client.finished_test()
2654
1977
class TestRepositoryTarball(TestRemoteRepository):