73
70
"TestSmartServerRequestFindRepository")
74
71
v2_only, v1_and_2 = split_suite_by_re(to_adapt,
76
for test in iter_suite_tests(v1_and_2):
77
result.addTests(applier.adapt(test))
78
del applier.scenarios[0]
79
for test in iter_suite_tests(v2_only):
80
result.addTests(applier.adapt(test))
73
tests.multiply_tests(v1_and_2, scenarios, result)
74
# The first scenario is only applicable to v1 protocols, it is deleted
76
tests.multiply_tests(v2_only, scenarios[1:], result)
177
173
expected = SuccessfulSmartServerResponse(
178
174
(local_result.network_name(),
179
175
local_result.repository_format.network_name(),
180
('direct', local_result.get_branch_format().network_name())))
176
('branch', local_result.get_branch_format().network_name())))
181
177
self.assertEqual(expected, request.execute('', 'False'))
183
179
def test_cloning_metadir_reference(self):
196
192
expected = SuccessfulSmartServerResponse(
197
193
(local_result.network_name(),
198
194
local_result.repository_format.network_name(),
199
('reference', reference_url)))
195
('ref', reference_url)))
200
196
self.assertEqual(expected, request.execute('', 'False'))
364
360
request.execute('reference'))
363
class TestSmartServerRequestOpenBranchV2(TestCaseWithChrootedTransport):
365
def test_no_branch(self):
366
"""When there is no branch, ('nobranch', ) is returned."""
367
backing = self.get_transport()
368
self.make_bzrdir('.')
369
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
370
self.assertEqual(SmartServerResponse(('nobranch', )),
373
def test_branch(self):
374
"""When there is a branch, 'ok' is returned."""
375
backing = self.get_transport()
376
expected = self.make_branch('.')._format.network_name()
377
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
378
self.assertEqual(SuccessfulSmartServerResponse(('branch', expected)),
381
def test_branch_reference(self):
382
"""When there is a branch reference, the reference URL is returned."""
383
backing = self.get_transport()
384
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
385
branch = self.make_branch('branch')
386
checkout = branch.create_checkout('reference',lightweight=True)
387
reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
388
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
389
self.assertEqual(SuccessfulSmartServerResponse(('ref', reference_url)),
390
request.execute('reference'))
367
393
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
369
395
def test_empty(self):
725
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
726
# Only called when the branch format and tags match [yay factory
727
# methods] so only need to test straight forward cases.
729
def test_get_bytes(self):
730
base_branch = self.make_branch('base')
731
request = smart.branch.SmartServerBranchGetTagsBytes(
732
self.get_transport())
733
response = request.execute('base')
735
SuccessfulSmartServerResponse(('',)), response)
699
738
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
701
740
def test_get_stacked_on_url(self):
931
970
request.execute('', 'missingrevision'))
973
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
975
def make_two_commit_repo(self):
976
tree = self.make_branch_and_memory_tree('.')
979
r1 = tree.commit('1st commit')
980
r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
982
repo = tree.branch.repository
985
def test_ancestry_of(self):
986
"""The search argument may be a 'ancestry-of' some heads'."""
987
backing = self.get_transport()
988
request = smart.repository.SmartServerRepositoryGetStream(backing)
989
repo, r1, r2 = self.make_two_commit_repo()
990
fetch_spec = ['ancestry-of', r2]
991
lines = '\n'.join(fetch_spec)
992
request.execute('', repo._format.network_name())
993
response = request.do_body(lines)
994
self.assertEqual(('ok',), response.args)
995
stream_bytes = ''.join(response.body_stream)
996
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
998
def test_search(self):
999
"""The search argument may be a 'search' of some explicit keys."""
1000
backing = self.get_transport()
1001
request = smart.repository.SmartServerRepositoryGetStream(backing)
1002
repo, r1, r2 = self.make_two_commit_repo()
1003
fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1004
lines = '\n'.join(fetch_spec)
1005
request.execute('', repo._format.network_name())
1006
response = request.do_body(lines)
1007
self.assertEqual(('ok',), response.args)
1008
stream_bytes = ''.join(response.body_stream)
1009
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
934
1012
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
936
1014
def test_missing_revision(self):
1209
1287
smart.request.request_handlers.get('Branch.get_parent'),
1210
1288
smart.branch.SmartServerBranchGetParent)
1211
1289
self.assertEqual(
1290
smart.request.request_handlers.get('Branch.get_tags_bytes'),
1291
smart.branch.SmartServerBranchGetTagsBytes)
1212
1293
smart.request.request_handlers.get('Branch.lock_write'),
1213
1294
smart.branch.SmartServerBranchRequestLockWrite)
1214
1295
self.assertEqual(
1242
1323
smart.request.request_handlers.get('BzrDir.open_branch'),
1243
1324
smart.bzrdir.SmartServerRequestOpenBranch)
1244
1325
self.assertEqual(
1326
smart.request.request_handlers.get('BzrDir.open_branchV2'),
1327
smart.bzrdir.SmartServerRequestOpenBranchV2)
1245
1329
smart.request.request_handlers.get('PackRepository.autopack'),
1246
1330
smart.packrepository.SmartServerPackRepositoryAutopack)
1247
1331
self.assertEqual(