211
217
"""The request fails when bzrdir contains a branch reference."""
212
218
backing = self.get_transport()
213
219
referenced_branch = self.make_branch('referenced')
214
dir = self.make_bzrdir('.')
220
dir = self.make_controldir('.')
215
221
local_result = dir.cloning_metadir()
216
reference = _mod_branch.BranchReferenceFormat().initialize(
222
reference = _mod_bzrbranch.BranchReferenceFormat().initialize(
217
223
dir, target_branch=referenced_branch)
218
reference_url = _mod_branch.BranchReferenceFormat().get_reference(dir)
224
reference_url = _mod_bzrbranch.BranchReferenceFormat().get_reference(dir)
219
225
# The server shouldn't try to follow the branch reference, so it's fine
220
226
# if the referenced branch isn't reachable.
221
227
backing.rename('referenced', 'moved')
222
228
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
223
229
request = request_class(backing)
224
expected = smart_req.FailedSmartServerResponse(('BranchReference',))
230
expected = smart_req.FailedSmartServerResponse((b'BranchReference',))
225
231
self.assertEqual(expected, request.execute('', 'False'))
234
class TestSmartServerBzrDirRequestCloningMetaDir(
235
tests.TestCaseWithMemoryTransport):
236
"""Tests for BzrDir.checkout_metadir."""
238
def test_checkout_metadir(self):
239
backing = self.get_transport()
240
request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
242
branch = self.make_branch('.', format='2a')
243
response = request.execute('')
245
smart_req.SmartServerResponse(
246
('Bazaar-NG meta directory, format 1\n',
247
'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
248
'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
252
class TestSmartServerBzrDirRequestDestroyBranch(
253
tests.TestCaseWithMemoryTransport):
254
"""Tests for BzrDir.destroy_branch."""
256
def test_destroy_branch_default(self):
257
"""The default branch can be removed."""
258
backing = self.get_transport()
259
dir = self.make_branch('.').controldir
260
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
261
request = request_class(backing)
262
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
263
self.assertEqual(expected, request.execute('', None))
265
def test_destroy_branch_named(self):
266
"""A named branch can be removed."""
267
backing = self.get_transport()
268
dir = self.make_repository('.', format="development-colo").controldir
269
dir.create_branch(name="branchname")
270
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
271
request = request_class(backing)
272
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
273
self.assertEqual(expected, request.execute('', "branchname"))
275
def test_destroy_branch_missing(self):
276
"""An error is raised if the branch didn't exist."""
277
backing = self.get_transport()
278
dir = self.make_controldir('.', format="development-colo")
279
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
280
request = request_class(backing)
281
expected = smart_req.FailedSmartServerResponse((b'nobranch',), None)
282
self.assertEqual(expected, request.execute('', "branchname"))
285
class TestSmartServerBzrDirRequestHasWorkingTree(
286
tests.TestCaseWithTransport):
287
"""Tests for BzrDir.has_workingtree."""
289
def test_has_workingtree_yes(self):
290
"""A working tree is present."""
291
backing = self.get_transport()
292
dir = self.make_branch_and_tree('.').controldir
293
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
294
request = request_class(backing)
295
expected = smart_req.SuccessfulSmartServerResponse((b'yes',))
296
self.assertEqual(expected, request.execute(b''))
298
def test_has_workingtree_no(self):
299
"""A working tree is missing."""
300
backing = self.get_transport()
301
dir = self.make_controldir('.')
302
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
303
request = request_class(backing)
304
expected = smart_req.SuccessfulSmartServerResponse((b'no',))
305
self.assertEqual(expected, request.execute(b''))
308
class TestSmartServerBzrDirRequestDestroyRepository(
309
tests.TestCaseWithMemoryTransport):
310
"""Tests for BzrDir.destroy_repository."""
312
def test_destroy_repository_default(self):
313
"""The repository can be removed."""
314
backing = self.get_transport()
315
dir = self.make_repository('.').controldir
316
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
317
request = request_class(backing)
318
expected = smart_req.SuccessfulSmartServerResponse((b'ok',))
319
self.assertEqual(expected, request.execute(''))
321
def test_destroy_repository_missing(self):
322
"""An error is raised if the repository didn't exist."""
323
backing = self.get_transport()
324
dir = self.make_controldir('.')
325
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
326
request = request_class(backing)
327
expected = smart_req.FailedSmartServerResponse(
328
('norepository',), None)
329
self.assertEqual(expected, request.execute(''))
228
332
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
229
333
"""Tests for BzrDir.create_repository."""
231
335
def test_makes_repository(self):
232
336
"""When there is a bzrdir present, the call succeeds."""
233
337
backing = self.get_transport()
234
self.make_bzrdir('.')
338
self.make_controldir('.')
235
339
request_class = smart_dir.SmartServerRequestCreateRepository
236
340
request = request_class(backing)
237
reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
341
reference_bzrdir_format = controldir.format_registry.get('pack-0.92')()
238
342
reference_format = reference_bzrdir_format.repository_format
239
343
network_name = reference_format.network_name()
240
344
expected = smart_req.SuccessfulSmartServerResponse(
273
377
repo = self.make_repository('.', shared=shared, format=format)
274
378
if repo.supports_rich_root():
278
382
if repo._format.supports_tree_reference:
282
386
if repo._format.supports_external_lookups:
286
390
if (smart_dir.SmartServerRequestFindRepositoryV3 ==
287
391
self._request_class):
288
392
return smart_req.SuccessfulSmartServerResponse(
289
('ok', '', rich_root, subtrees, external,
393
(b'ok', b'', rich_root, subtrees, external,
290
394
repo._format.network_name()))
291
395
elif (smart_dir.SmartServerRequestFindRepositoryV2 ==
292
396
self._request_class):
293
397
# All tests so far are on formats, and for non-external
295
399
return smart_req.SuccessfulSmartServerResponse(
296
('ok', '', rich_root, subtrees, external))
400
(b'ok', b'', rich_root, subtrees, external))
298
402
return smart_req.SuccessfulSmartServerResponse(
299
('ok', '', rich_root, subtrees))
403
(b'ok', b'', rich_root, subtrees))
301
405
def test_shared_repository(self):
302
406
"""When there is a shared repository, we get 'ok', 'relpath-to-repo'."""
303
407
backing = self.get_transport()
304
408
request = self._request_class(backing)
305
409
result = self._make_repository_and_result(shared=True)
306
self.assertEqual(result, request.execute(''))
307
self.make_bzrdir('subdir')
410
self.assertEqual(result, request.execute(b''))
411
self.make_controldir('subdir')
308
412
result2 = smart_req.SmartServerResponse(
309
413
result.args[0:1] + ('..', ) + result.args[2:])
310
414
self.assertEqual(result2,
311
request.execute('subdir'))
312
self.make_bzrdir('subdir/deeper')
415
request.execute(b'subdir'))
416
self.make_controldir('subdir/deeper')
313
417
result3 = smart_req.SmartServerResponse(
314
418
result.args[0:1] + ('../..', ) + result.args[2:])
315
419
self.assertEqual(result3,
316
request.execute('subdir/deeper'))
420
request.execute(b'subdir/deeper'))
318
422
def test_rich_root_and_subtree_encoding(self):
319
423
"""Test for the format attributes for rich root and subtree support."""
320
424
backing = self.get_transport()
321
425
request = self._request_class(backing)
322
426
result = self._make_repository_and_result(
323
format='dirstate-with-subtree')
427
format='development-subtree')
324
428
# check the test will be valid
325
self.assertEqual('yes', result.args[2])
326
self.assertEqual('yes', result.args[3])
327
self.assertEqual(result, request.execute(''))
429
self.assertEqual(b'yes', result.args[2])
430
self.assertEqual(b'yes', result.args[3])
431
self.assertEqual(result, request.execute(b''))
329
433
def test_supports_external_lookups_no_v2(self):
330
434
"""Test for the supports_external_lookups attribute."""
331
435
backing = self.get_transport()
332
436
request = self._request_class(backing)
333
437
result = self._make_repository_and_result(
334
format='dirstate-with-subtree')
438
format='development-subtree')
335
439
# check the test will be valid
336
self.assertEqual('no', result.args[4])
337
self.assertEqual(result, request.execute(''))
440
self.assertEqual(b'yes', result.args[4])
441
self.assertEqual(result, request.execute(b''))
340
444
class TestSmartServerBzrDirRequestGetConfigFile(
1306
1568
backing = self.get_transport()
1307
1569
request = smart_repo.SmartServerRepositoryRequest(backing)
1308
1570
self.make_repository('.', shared=True)
1309
self.make_bzrdir('subdir')
1571
self.make_controldir('subdir')
1310
1572
self.assertRaises(errors.NoRepositoryPresent,
1311
1573
request.execute, 'subdir')
1576
class TestSmartServerRepositoryAddSignatureText(tests.TestCaseWithMemoryTransport):
1578
def test_add_text(self):
1579
backing = self.get_transport()
1580
request = smart_repo.SmartServerRepositoryAddSignatureText(backing)
1581
tree = self.make_branch_and_memory_tree('.')
1582
write_token = tree.lock_write()
1583
self.addCleanup(tree.unlock)
1585
tree.commit("Message", rev_id=b'rev1')
1586
tree.branch.repository.start_write_group()
1587
write_group_tokens = tree.branch.repository.suspend_write_group()
1588
self.assertEqual(None, request.execute(b'', write_token,
1589
b'rev1', *write_group_tokens))
1590
response = request.do_body('somesignature')
1591
self.assertTrue(response.is_successful())
1592
self.assertEqual(response.args[0], 'ok')
1593
write_group_tokens = response.args[1:]
1594
tree.branch.repository.resume_write_group(write_group_tokens)
1595
tree.branch.repository.commit_write_group()
1597
self.assertEqual("somesignature",
1598
tree.branch.repository.get_signature_text("rev1"))
1601
class TestSmartServerRepositoryAllRevisionIds(
1602
tests.TestCaseWithMemoryTransport):
1604
def test_empty(self):
1605
"""An empty body should be returned for an empty repository."""
1606
backing = self.get_transport()
1607
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1608
self.make_repository('.')
1610
smart_req.SuccessfulSmartServerResponse((b"ok", ), b""),
1611
request.execute(b''))
1613
def test_some_revisions(self):
1614
"""An empty body should be returned for an empty repository."""
1615
backing = self.get_transport()
1616
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1617
tree = self.make_branch_and_memory_tree('.')
1620
tree.commit(rev_id=b'origineel', message="message")
1621
tree.commit(rev_id=b'nog-een-revisie', message="message")
1624
smart_req.SuccessfulSmartServerResponse((b"ok", ),
1625
b"origineel\nnog-een-revisie"),
1626
request.execute(b''))
1629
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1631
def test_lock_to_break(self):
1632
backing = self.get_transport()
1633
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1634
tree = self.make_branch_and_memory_tree('.')
1635
tree.branch.repository.lock_write()
1637
smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1638
request.execute(b''))
1640
def test_nothing_to_break(self):
1641
backing = self.get_transport()
1642
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1643
tree = self.make_branch_and_memory_tree('.')
1645
smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1646
request.execute(b''))
1314
1649
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithMemoryTransport):
1316
1651
def test_trivial_bzipped(self):
1448
1827
repo = tree.branch.repository
1449
1828
return repo, r1, r2
1831
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
1451
1833
def test_ancestry_of(self):
1452
1834
"""The search argument may be a 'ancestry-of' some heads'."""
1453
1835
backing = self.get_transport()
1454
1836
request = smart_repo.SmartServerRepositoryGetStream(backing)
1455
1837
repo, r1, r2 = self.make_two_commit_repo()
1456
fetch_spec = ['ancestry-of', r2]
1457
lines = '\n'.join(fetch_spec)
1458
request.execute('', repo._format.network_name())
1838
fetch_spec = [b'ancestry-of', r2]
1839
lines = b'\n'.join(fetch_spec)
1840
request.execute(b'', repo._format.network_name())
1459
1841
response = request.do_body(lines)
1460
self.assertEqual(('ok',), response.args)
1461
stream_bytes = ''.join(response.body_stream)
1462
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1842
self.assertEqual((b'ok',), response.args)
1843
stream_bytes = b''.join(response.body_stream)
1844
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1464
1846
def test_search(self):
1465
1847
"""The search argument may be a 'search' of some explicit keys."""
1466
1848
backing = self.get_transport()
1467
1849
request = smart_repo.SmartServerRepositoryGetStream(backing)
1468
1850
repo, r1, r2 = self.make_two_commit_repo()
1469
fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1470
lines = '\n'.join(fetch_spec)
1471
request.execute('', repo._format.network_name())
1851
fetch_spec = [b'search', r1 + b' ' + r2, b'null:', b'2']
1852
lines = b'\n'.join(fetch_spec)
1853
request.execute(b'', repo._format.network_name())
1472
1854
response = request.do_body(lines)
1473
self.assertEqual(('ok',), response.args)
1474
stream_bytes = ''.join(response.body_stream)
1475
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1855
self.assertEqual((b'ok',), response.args)
1856
stream_bytes = b''.join(response.body_stream)
1857
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1859
def test_search_everything(self):
1860
"""A search of 'everything' returns a stream."""
1861
backing = self.get_transport()
1862
request = smart_repo.SmartServerRepositoryGetStream_1_19(backing)
1863
repo, r1, r2 = self.make_two_commit_repo()
1864
serialised_fetch_spec = b'everything'
1865
request.execute(b'', repo._format.network_name())
1866
response = request.do_body(serialised_fetch_spec)
1867
self.assertEqual((b'ok',), response.args)
1868
stream_bytes = b''.join(response.body_stream)
1869
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1478
1872
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
1496
1890
r1 = tree.commit('a commit', rev_id=rev_id_utf8)
1498
1892
self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
1499
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1500
request.execute('', rev_id_utf8))
1893
self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1894
request.execute(b'', rev_id_utf8))
1897
class TestSmartServerRepositoryIterFilesBytes(tests.TestCaseWithTransport):
1899
def test_single(self):
1900
backing = self.get_transport()
1901
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1902
t = self.make_branch_and_tree('.')
1903
self.addCleanup(t.lock_write().unlock)
1904
self.build_tree_contents([("file", b"somecontents")])
1905
t.add(["file"], [b"thefileid"])
1906
t.commit(rev_id=b'somerev', message="add file")
1907
self.assertIs(None, request.execute(b''))
1908
response = request.do_body(b"thefileid\0somerev\n")
1909
self.assertTrue(response.is_successful())
1910
self.assertEqual(response.args, (b"ok", ))
1911
self.assertEqual(b"".join(response.body_stream),
1912
b"ok\x000\n" + zlib.compress(b"somecontents"))
1914
def test_missing(self):
1915
backing = self.get_transport()
1916
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1917
t = self.make_branch_and_tree('.')
1918
self.addCleanup(t.lock_write().unlock)
1919
self.assertIs(None, request.execute(b''))
1920
response = request.do_body(b"thefileid\0revision\n")
1921
self.assertTrue(response.is_successful())
1922
self.assertEqual(response.args, (b"ok", ))
1923
self.assertEqual(b"".join(response.body_stream),
1924
b"absent\x00thefileid\x00revision\x000\n")
1927
class TestSmartServerRequestHasSignatureForRevisionId(
1928
tests.TestCaseWithMemoryTransport):
1930
def test_missing_revision(self):
1931
"""For a missing revision, NoSuchRevision is returned."""
1932
backing = self.get_transport()
1933
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1935
self.make_repository('.')
1937
smart_req.FailedSmartServerResponse(
1938
(b'nosuchrevision', b'revid'), None),
1939
request.execute(b'', b'revid'))
1941
def test_missing_signature(self):
1942
"""For a missing signature, ('no', ) is returned."""
1943
backing = self.get_transport()
1944
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1946
tree = self.make_branch_and_memory_tree('.')
1949
r1 = tree.commit('a commit', rev_id=b'A')
1951
self.assertTrue(tree.branch.repository.has_revision('A'))
1952
self.assertEqual(smart_req.SmartServerResponse((b'no', )),
1953
request.execute(b'', b'A'))
1955
def test_present_signature(self):
1956
"""For a present signature, ('yes', ) is returned."""
1957
backing = self.get_transport()
1958
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1960
strategy = gpg.LoopbackGPGStrategy(None)
1961
tree = self.make_branch_and_memory_tree('.')
1964
r1 = tree.commit('a commit', rev_id=b'A')
1965
tree.branch.repository.start_write_group()
1966
tree.branch.repository.sign_revision(b'A', strategy)
1967
tree.branch.repository.commit_write_group()
1969
self.assertTrue(tree.branch.repository.has_revision(b'A'))
1970
self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1971
request.execute(b'', b'A'))
1503
1974
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
1734
2302
repo.set_make_working_trees(False)
1735
2303
request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
1736
2304
request = request_class(backing)
1737
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
1738
request.execute('', 'True'))
1739
repo = repo.bzrdir.open_repository()
2305
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2306
request.execute(b'', b'True'))
2307
repo = repo.controldir.open_repository()
1740
2308
self.assertTrue(repo.make_working_trees())
2311
class TestSmartServerRepositoryGetSerializerFormat(
2312
tests.TestCaseWithMemoryTransport):
2314
def test_get_serializer_format(self):
2315
backing = self.get_transport()
2316
repo = self.make_repository('.', format='2a')
2317
request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2318
request = request_class(backing)
2320
smart_req.SuccessfulSmartServerResponse((b'ok', b'10')),
2321
request.execute(b''))
2324
class TestSmartServerRepositoryWriteGroup(
2325
tests.TestCaseWithMemoryTransport):
2327
def test_start_write_group(self):
2328
backing = self.get_transport()
2329
repo = self.make_repository('.')
2330
lock_token = repo.lock_write().repository_token
2331
self.addCleanup(repo.unlock)
2332
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2333
request = request_class(backing)
2334
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok', [])),
2335
request.execute(b'', lock_token))
2337
def test_start_write_group_unsuspendable(self):
2338
backing = self.get_transport()
2339
repo = self.make_repository('.', format='knit')
2340
lock_token = repo.lock_write().repository_token
2341
self.addCleanup(repo.unlock)
2342
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2343
request = request_class(backing)
2345
smart_req.FailedSmartServerResponse((b'UnsuspendableWriteGroup',)),
2346
request.execute(b'', lock_token))
2348
def test_commit_write_group(self):
2349
backing = self.get_transport()
2350
repo = self.make_repository('.')
2351
lock_token = repo.lock_write().repository_token
2352
self.addCleanup(repo.unlock)
2353
repo.start_write_group()
2354
tokens = repo.suspend_write_group()
2355
request_class = smart_repo.SmartServerRepositoryCommitWriteGroup
2356
request = request_class(backing)
2357
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2358
request.execute(b'', lock_token, tokens))
2360
def test_abort_write_group(self):
2361
backing = self.get_transport()
2362
repo = self.make_repository('.')
2363
lock_token = repo.lock_write().repository_token
2364
repo.start_write_group()
2365
tokens = repo.suspend_write_group()
2366
self.addCleanup(repo.unlock)
2367
request_class = smart_repo.SmartServerRepositoryAbortWriteGroup
2368
request = request_class(backing)
2369
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2370
request.execute(b'', lock_token, tokens))
2372
def test_check_write_group(self):
2373
backing = self.get_transport()
2374
repo = self.make_repository('.')
2375
lock_token = repo.lock_write().repository_token
2376
repo.start_write_group()
2377
tokens = repo.suspend_write_group()
2378
self.addCleanup(repo.unlock)
2379
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2380
request = request_class(backing)
2381
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2382
request.execute(b'', lock_token, tokens))
2384
def test_check_write_group_invalid(self):
2385
backing = self.get_transport()
2386
repo = self.make_repository('.')
2387
lock_token = repo.lock_write().repository_token
2388
self.addCleanup(repo.unlock)
2389
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2390
request = request_class(backing)
2391
self.assertEqual(smart_req.FailedSmartServerResponse(
2392
(b'UnresumableWriteGroup', [b'random'],
2393
b'Malformed write group token')),
2394
request.execute(b'', lock_token, [b"random"]))
1743
2397
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1745
2399
def make_repo_needing_autopacking(self, path='.'):
1811
2465
"""All registered request_handlers can be found."""
1812
2466
# If there's a typo in a register_lazy call, this loop will fail with
1813
2467
# an AttributeError.
1814
for key, item in smart_req.request_handlers.iteritems():
2468
for key in smart_req.request_handlers.keys():
2470
item = smart_req.request_handlers.get(key)
2471
except AttributeError as e:
2472
raise AttributeError('failed to get %s: %s' % (key, e))
1817
2474
def assertHandlerEqual(self, verb, handler):
1818
2475
self.assertEqual(smart_req.request_handlers.get(verb), handler)
1820
2477
def test_registered_methods(self):
1821
2478
"""Test that known methods are registered to the correct object."""
1822
self.assertHandlerEqual('Branch.get_config_file',
2479
self.assertHandlerEqual(b'Branch.break_lock',
2480
smart_branch.SmartServerBranchBreakLock)
2481
self.assertHandlerEqual(b'Branch.get_config_file',
1823
2482
smart_branch.SmartServerBranchGetConfigFile)
1824
self.assertHandlerEqual('Branch.get_parent',
2483
self.assertHandlerEqual(b'Branch.put_config_file',
2484
smart_branch.SmartServerBranchPutConfigFile)
2485
self.assertHandlerEqual(b'Branch.get_parent',
1825
2486
smart_branch.SmartServerBranchGetParent)
1826
self.assertHandlerEqual('Branch.get_tags_bytes',
2487
self.assertHandlerEqual(b'Branch.get_physical_lock_status',
2488
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2489
self.assertHandlerEqual(b'Branch.get_tags_bytes',
1827
2490
smart_branch.SmartServerBranchGetTagsBytes)
1828
self.assertHandlerEqual('Branch.lock_write',
2491
self.assertHandlerEqual(b'Branch.lock_write',
1829
2492
smart_branch.SmartServerBranchRequestLockWrite)
1830
self.assertHandlerEqual('Branch.last_revision_info',
2493
self.assertHandlerEqual(b'Branch.last_revision_info',
1831
2494
smart_branch.SmartServerBranchRequestLastRevisionInfo)
1832
self.assertHandlerEqual('Branch.revision_history',
2495
self.assertHandlerEqual(b'Branch.revision_history',
1833
2496
smart_branch.SmartServerRequestRevisionHistory)
1834
self.assertHandlerEqual('Branch.set_config_option',
2497
self.assertHandlerEqual(b'Branch.revision_id_to_revno',
2498
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2499
self.assertHandlerEqual(b'Branch.set_config_option',
1835
2500
smart_branch.SmartServerBranchRequestSetConfigOption)
1836
self.assertHandlerEqual('Branch.set_last_revision',
2501
self.assertHandlerEqual(b'Branch.set_last_revision',
1837
2502
smart_branch.SmartServerBranchRequestSetLastRevision)
1838
self.assertHandlerEqual('Branch.set_last_revision_info',
2503
self.assertHandlerEqual(b'Branch.set_last_revision_info',
1839
2504
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
1840
self.assertHandlerEqual('Branch.set_last_revision_ex',
2505
self.assertHandlerEqual(b'Branch.set_last_revision_ex',
1841
2506
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
1842
self.assertHandlerEqual('Branch.set_parent_location',
2507
self.assertHandlerEqual(b'Branch.set_parent_location',
1843
2508
smart_branch.SmartServerBranchRequestSetParentLocation)
1844
self.assertHandlerEqual('Branch.unlock',
2509
self.assertHandlerEqual(b'Branch.unlock',
1845
2510
smart_branch.SmartServerBranchRequestUnlock)
1846
self.assertHandlerEqual('BzrDir.find_repository',
2511
self.assertHandlerEqual(b'BzrDir.destroy_branch',
2512
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2513
self.assertHandlerEqual(b'BzrDir.find_repository',
1847
2514
smart_dir.SmartServerRequestFindRepositoryV1)
1848
self.assertHandlerEqual('BzrDir.find_repositoryV2',
2515
self.assertHandlerEqual(b'BzrDir.find_repositoryV2',
1849
2516
smart_dir.SmartServerRequestFindRepositoryV2)
1850
self.assertHandlerEqual('BzrDirFormat.initialize',
2517
self.assertHandlerEqual(b'BzrDirFormat.initialize',
1851
2518
smart_dir.SmartServerRequestInitializeBzrDir)
1852
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2519
self.assertHandlerEqual(b'BzrDirFormat.initialize_ex_1.16',
1853
2520
smart_dir.SmartServerRequestBzrDirInitializeEx)
1854
self.assertHandlerEqual('BzrDir.cloning_metadir',
2521
self.assertHandlerEqual(b'BzrDir.checkout_metadir',
2522
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2523
self.assertHandlerEqual(b'BzrDir.cloning_metadir',
1855
2524
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
1856
self.assertHandlerEqual('BzrDir.get_config_file',
2525
self.assertHandlerEqual(b'BzrDir.get_branches',
2526
smart_dir.SmartServerBzrDirRequestGetBranches)
2527
self.assertHandlerEqual(b'BzrDir.get_config_file',
1857
2528
smart_dir.SmartServerBzrDirRequestConfigFile)
1858
self.assertHandlerEqual('BzrDir.open_branch',
2529
self.assertHandlerEqual(b'BzrDir.open_branch',
1859
2530
smart_dir.SmartServerRequestOpenBranch)
1860
self.assertHandlerEqual('BzrDir.open_branchV2',
2531
self.assertHandlerEqual(b'BzrDir.open_branchV2',
1861
2532
smart_dir.SmartServerRequestOpenBranchV2)
1862
self.assertHandlerEqual('BzrDir.open_branchV3',
2533
self.assertHandlerEqual(b'BzrDir.open_branchV3',
1863
2534
smart_dir.SmartServerRequestOpenBranchV3)
1864
self.assertHandlerEqual('PackRepository.autopack',
2535
self.assertHandlerEqual(b'PackRepository.autopack',
1865
2536
smart_packrepo.SmartServerPackRepositoryAutopack)
1866
self.assertHandlerEqual('Repository.gather_stats',
2537
self.assertHandlerEqual(b'Repository.add_signature_text',
2538
smart_repo.SmartServerRepositoryAddSignatureText)
2539
self.assertHandlerEqual(b'Repository.all_revision_ids',
2540
smart_repo.SmartServerRepositoryAllRevisionIds)
2541
self.assertHandlerEqual(b'Repository.break_lock',
2542
smart_repo.SmartServerRepositoryBreakLock)
2543
self.assertHandlerEqual(b'Repository.gather_stats',
1867
2544
smart_repo.SmartServerRepositoryGatherStats)
1868
self.assertHandlerEqual('Repository.get_parent_map',
2545
self.assertHandlerEqual(b'Repository.get_parent_map',
1869
2546
smart_repo.SmartServerRepositoryGetParentMap)
1870
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
2547
self.assertHandlerEqual(b'Repository.get_physical_lock_status',
2548
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2549
self.assertHandlerEqual(b'Repository.get_rev_id_for_revno',
1871
2550
smart_repo.SmartServerRepositoryGetRevIdForRevno)
1872
self.assertHandlerEqual('Repository.get_revision_graph',
2551
self.assertHandlerEqual(b'Repository.get_revision_graph',
1873
2552
smart_repo.SmartServerRepositoryGetRevisionGraph)
1874
self.assertHandlerEqual('Repository.get_stream',
2553
self.assertHandlerEqual(b'Repository.get_revision_signature_text',
2554
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2555
self.assertHandlerEqual(b'Repository.get_stream',
1875
2556
smart_repo.SmartServerRepositoryGetStream)
1876
self.assertHandlerEqual('Repository.has_revision',
2557
self.assertHandlerEqual(b'Repository.get_stream_1.19',
2558
smart_repo.SmartServerRepositoryGetStream_1_19)
2559
self.assertHandlerEqual(b'Repository.iter_revisions',
2560
smart_repo.SmartServerRepositoryIterRevisions)
2561
self.assertHandlerEqual(b'Repository.has_revision',
1877
2562
smart_repo.SmartServerRequestHasRevision)
1878
self.assertHandlerEqual('Repository.insert_stream',
2563
self.assertHandlerEqual(b'Repository.insert_stream',
1879
2564
smart_repo.SmartServerRepositoryInsertStream)
1880
self.assertHandlerEqual('Repository.insert_stream_locked',
2565
self.assertHandlerEqual(b'Repository.insert_stream_locked',
1881
2566
smart_repo.SmartServerRepositoryInsertStreamLocked)
1882
self.assertHandlerEqual('Repository.is_shared',
2567
self.assertHandlerEqual(b'Repository.is_shared',
1883
2568
smart_repo.SmartServerRepositoryIsShared)
1884
self.assertHandlerEqual('Repository.lock_write',
2569
self.assertHandlerEqual(b'Repository.iter_files_bytes',
2570
smart_repo.SmartServerRepositoryIterFilesBytes)
2571
self.assertHandlerEqual(b'Repository.lock_write',
1885
2572
smart_repo.SmartServerRepositoryLockWrite)
1886
self.assertHandlerEqual('Repository.tarball',
2573
self.assertHandlerEqual(b'Repository.make_working_trees',
2574
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2575
self.assertHandlerEqual(b'Repository.pack',
2576
smart_repo.SmartServerRepositoryPack)
2577
self.assertHandlerEqual(b'Repository.reconcile',
2578
smart_repo.SmartServerRepositoryReconcile)
2579
self.assertHandlerEqual(b'Repository.tarball',
1887
2580
smart_repo.SmartServerRepositoryTarball)
1888
self.assertHandlerEqual('Repository.unlock',
2581
self.assertHandlerEqual(b'Repository.unlock',
1889
2582
smart_repo.SmartServerRepositoryUnlock)
1890
self.assertHandlerEqual('Transport.is_readonly',
2583
self.assertHandlerEqual(b'Repository.start_write_group',
2584
smart_repo.SmartServerRepositoryStartWriteGroup)
2585
self.assertHandlerEqual(b'Repository.check_write_group',
2586
smart_repo.SmartServerRepositoryCheckWriteGroup)
2587
self.assertHandlerEqual(b'Repository.commit_write_group',
2588
smart_repo.SmartServerRepositoryCommitWriteGroup)
2589
self.assertHandlerEqual(b'Repository.abort_write_group',
2590
smart_repo.SmartServerRepositoryAbortWriteGroup)
2591
self.assertHandlerEqual(b'VersionedFileRepository.get_serializer_format',
2592
smart_repo.SmartServerRepositoryGetSerializerFormat)
2593
self.assertHandlerEqual(b'VersionedFileRepository.get_inventories',
2594
smart_repo.SmartServerRepositoryGetInventories)
2595
self.assertHandlerEqual(b'Transport.is_readonly',
1891
2596
smart_req.SmartServerIsReadonly)
2599
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2600
"""Tests for SmartTCPServer hooks."""
2603
super(SmartTCPServerHookTests, self).setUp()
2604
self.server = server.SmartTCPServer(self.get_transport())
2606
def test_run_server_started_hooks(self):
2607
"""Test the server started hooks get fired properly."""
2609
server.SmartTCPServer.hooks.install_named_hook('server_started',
2610
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2612
started_ex_calls = []
2613
server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2614
lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2616
self.server._sockname = ('example.com', 42)
2617
self.server.run_server_started_hooks()
2618
self.assertEqual(started_calls,
2619
[([self.get_transport().base], 'bzr://example.com:42/')])
2620
self.assertEqual(started_ex_calls,
2621
[([self.get_transport().base], self.server)])
2623
def test_run_server_started_hooks_ipv6(self):
2624
"""Test that socknames can contain 4-tuples."""
2625
self.server._sockname = ('::', 42, 0, 0)
2627
server.SmartTCPServer.hooks.install_named_hook('server_started',
2628
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2630
self.server.run_server_started_hooks()
2631
self.assertEqual(started_calls,
2632
[([self.get_transport().base], 'bzr://:::42/')])
2634
def test_run_server_stopped_hooks(self):
2635
"""Test the server stopped hooks."""
2636
self.server._sockname = ('example.com', 42)
2638
server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2639
lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2641
self.server.run_server_stopped_hooks()
2642
self.assertEqual(stopped_calls,
2643
[([self.get_transport().base], 'bzr://example.com:42/')])
2646
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
2648
def test_pack(self):
2649
backing = self.get_transport()
2650
request = smart_repo.SmartServerRepositoryPack(backing)
2651
tree = self.make_branch_and_memory_tree('.')
2652
repo_token = tree.branch.repository.lock_write().repository_token
2654
self.assertIs(None, request.execute(b'', repo_token, False))
2657
smart_req.SuccessfulSmartServerResponse((b'ok', ), ),
2658
request.do_body(b''))
2661
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2663
def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2664
base_inv = repository.revision_tree(base_revid).root_inventory
2665
inv = repository.revision_tree(revid).root_inventory
2666
inv_delta = inv._make_delta(base_inv)
2667
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2668
return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2670
def test_single(self):
2671
backing = self.get_transport()
2672
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2673
t = self.make_branch_and_tree('.', format='2a')
2674
self.addCleanup(t.lock_write().unlock)
2675
self.build_tree_contents([("file", b"somecontents")])
2676
t.add(["file"], [b"thefileid"])
2677
t.commit(rev_id=b'somerev', message="add file")
2678
self.assertIs(None, request.execute(b'', b'unordered'))
2679
response = request.do_body(b"somerev\n")
2680
self.assertTrue(response.is_successful())
2681
self.assertEqual(response.args, (b"ok", ))
2682
stream = [('inventory-deltas', [
2683
versionedfile.FulltextContentFactory('somerev', None, None,
2684
self._get_serialized_inventory_delta(
2685
t.branch.repository, b'null:', b'somerev'))])]
2686
fmt = controldir.format_registry.get('2a')().repository_format
2688
b"".join(response.body_stream),
2689
b"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2691
def test_empty(self):
2692
backing = self.get_transport()
2693
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2694
t = self.make_branch_and_tree('.', format='2a')
2695
self.addCleanup(t.lock_write().unlock)
2696
self.build_tree_contents([("file", b"somecontents")])
2697
t.add(["file"], [b"thefileid"])
2698
t.commit(rev_id=b'somerev', message="add file")
2699
self.assertIs(None, request.execute(b'', b'unordered'))
2700
response = request.do_body(b"")
2701
self.assertTrue(response.is_successful())
2702
self.assertEqual(response.args, (b"ok", ))
2703
self.assertEqual(b"".join(response.body_stream),
2704
b"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")