88
87
if self._chroot_server is None:
89
88
backing_transport = tests.TestCaseWithTransport.get_transport(self)
90
89
self._chroot_server = chroot.ChrootServer(backing_transport)
91
self.start_server(self._chroot_server)
90
self._chroot_server.setUp()
91
self.addCleanup(self._chroot_server.tearDown)
92
92
t = get_transport(self._chroot_server.get_url())
93
93
if relpath is not None:
94
94
t = t.clone(relpath)
113
113
return self.get_transport().get_smart_medium()
116
class TestByteStreamToStream(tests.TestCase):
118
def test_repeated_substreams_same_kind_are_one_stream(self):
119
# Make a stream - an iterable of bytestrings.
120
stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
121
None, 'foo')]),('text', [
122
versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
123
fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
124
bytes = smart.repository._stream_to_byte_stream(stream, fmt)
126
# Iterate the resulting iterable; checking that we get only one stream
128
fmt, stream = smart.repository._byte_stream_to_stream(bytes)
129
for kind, substream in stream:
130
streams.append((kind, list(substream)))
131
self.assertLength(1, streams)
132
self.assertLength(2, streams[0][1])
135
116
class TestSmartServerResponse(tests.TestCase):
137
118
def test__eq__(self):
221
202
self.make_bzrdir('.')
222
203
request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository
223
204
request = request_class(backing)
224
reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
205
reference_bzrdir_format = bzrdir.format_registry.get('default')()
225
206
reference_format = reference_bzrdir_format.repository_format
226
207
network_name = reference_format.network_name()
227
208
expected = SuccessfulSmartServerResponse(
269
if repo._format.supports_external_lookups:
273
250
if (smart.bzrdir.SmartServerRequestFindRepositoryV3 ==
274
251
self._request_class):
275
252
return SuccessfulSmartServerResponse(
276
('ok', '', rich_root, subtrees, external,
253
('ok', '', rich_root, subtrees, 'no',
277
254
repo._format.network_name()))
278
255
elif (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
279
256
self._request_class):
280
257
# All tests so far are on formats, and for non-external
282
259
return SuccessfulSmartServerResponse(
283
('ok', '', rich_root, subtrees, external))
260
('ok', '', rich_root, subtrees, 'no'))
285
262
return SuccessfulSmartServerResponse(('ok', '', rich_root, subtrees))
404
381
'subdir/dir', 'False', 'False', 'False', '', '', '', '', 'False')
406
383
def test_initialized_dir(self):
407
"""Initializing an extant directory should fail like the bzrdir api."""
384
"""Initializing an extant dirctory should fail like the bzrdir api."""
408
385
backing = self.get_transport()
409
386
name = self.make_bzrdir('reference')._format.network_name()
410
387
request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
475
452
def test_stacked_branch(self):
476
453
"""Opening a stacked branch does not open the stacked-on branch."""
477
454
trunk = self.make_branch('trunk')
478
feature = self.make_branch('feature')
455
feature = self.make_branch('feature', format='1.9')
479
456
feature.set_stacked_on_url(trunk.base)
480
457
opened_branches = []
481
458
Branch.hooks.install_named_hook('open', opened_branches.append, None)
629
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
630
# Only called when the branch format and tags match [yay factory
631
# methods] so only need to test straight forward cases.
633
def test_set_bytes(self):
634
base_branch = self.make_branch('base')
635
tag_bytes = base_branch._get_tags_bytes()
636
# get_lock_tokens takes out a lock.
637
branch_token, repo_token = self.get_lock_tokens(base_branch)
638
request = smart.branch.SmartServerBranchSetTagsBytes(
639
self.get_transport())
640
response = request.execute('base', branch_token, repo_token)
641
self.assertEqual(None, response)
642
response = request.do_chunk(tag_bytes)
643
self.assertEqual(None, response)
644
response = request.do_end()
646
SuccessfulSmartServerResponse(()), response)
649
def test_lock_failed(self):
650
base_branch = self.make_branch('base')
651
base_branch.lock_write()
652
tag_bytes = base_branch._get_tags_bytes()
653
request = smart.branch.SmartServerBranchSetTagsBytes(
654
self.get_transport())
655
self.assertRaises(errors.TokenMismatch, request.execute,
656
'base', 'wrong token', 'wrong token')
657
# The request handler will keep processing the message parts, so even
658
# if the request fails immediately do_chunk and do_end are still
660
request.do_chunk(tag_bytes)
666
606
class SetLastRevisionTestBase(TestLockedBranch):
667
607
"""Base test case for verbs that implement set_last_revision."""
934
874
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
935
# Only called when the branch format and tags match [yay factory
936
# methods] so only need to test straight forward cases.
875
# Only called when the branch format and tags match [yay factory
876
# methods] so only need to test straight forward cases.
938
878
def test_get_bytes(self):
939
879
base_branch = self.make_branch('base')
1221
1161
request.execute('', 'missingrevision'))
1224
class TestSmartServerRepositoryGetRevIdForRevno(tests.TestCaseWithMemoryTransport):
1226
def test_revno_found(self):
1227
backing = self.get_transport()
1228
request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1229
tree = self.make_branch_and_memory_tree('.')
1232
rev1_id_utf8 = u'\xc8'.encode('utf-8')
1233
rev2_id_utf8 = u'\xc9'.encode('utf-8')
1234
tree.commit('1st commit', rev_id=rev1_id_utf8)
1235
tree.commit('2nd commit', rev_id=rev2_id_utf8)
1238
self.assertEqual(SmartServerResponse(('ok', rev1_id_utf8)),
1239
request.execute('', 1, (2, rev2_id_utf8)))
1241
def test_known_revid_missing(self):
1242
backing = self.get_transport()
1243
request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1244
repo = self.make_repository('.')
1246
FailedSmartServerResponse(('nosuchrevision', 'ghost')),
1247
request.execute('', 1, (2, 'ghost')))
1249
def test_history_incomplete(self):
1250
backing = self.get_transport()
1251
request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1252
parent = self.make_branch_and_memory_tree('parent', format='1.9')
1254
parent.add([''], ['TREE_ROOT'])
1255
r1 = parent.commit(message='first commit')
1256
r2 = parent.commit(message='second commit')
1258
local = self.make_branch_and_memory_tree('local', format='1.9')
1259
local.branch.pull(parent.branch)
1260
local.set_parent_ids([r2])
1261
r3 = local.commit(message='local commit')
1262
local.branch.create_clone_on_transport(
1263
self.get_transport('stacked'), stacked_on=self.get_url('parent'))
1265
SmartServerResponse(('history-incomplete', 2, r2)),
1266
request.execute('stacked', 1, (3, r3)))
1269
1164
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
1271
1166
def make_two_commit_repo(self):
1665
1560
smart.bzrdir.SmartServerRequestFindRepositoryV2)
1666
1561
self.assertHandlerEqual('BzrDirFormat.initialize',
1667
1562
smart.bzrdir.SmartServerRequestInitializeBzrDir)
1668
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
1563
self.assertHandlerEqual('BzrDirFormat.initialize_ex',
1669
1564
smart.bzrdir.SmartServerRequestBzrDirInitializeEx)
1670
1565
self.assertHandlerEqual('BzrDir.cloning_metadir',
1671
1566
smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1681
1576
smart.repository.SmartServerRepositoryGatherStats)
1682
1577
self.assertHandlerEqual('Repository.get_parent_map',
1683
1578
smart.repository.SmartServerRepositoryGetParentMap)
1684
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
1685
smart.repository.SmartServerRepositoryGetRevIdForRevno)
1686
1579
self.assertHandlerEqual('Repository.get_revision_graph',
1687
1580
smart.repository.SmartServerRepositoryGetRevisionGraph)
1688
1581
self.assertHandlerEqual('Repository.get_stream',