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(
1317
1579
backing = self.get_transport()
1318
1580
request = smart_repo.SmartServerRepositoryRequest(backing)
1319
1581
self.make_repository('.', shared=True)
1320
self.make_bzrdir('subdir')
1582
self.make_controldir('subdir')
1321
1583
self.assertRaises(errors.NoRepositoryPresent,
1322
1584
request.execute, 'subdir')
1587
class TestSmartServerRepositoryAddSignatureText(tests.TestCaseWithMemoryTransport):
1589
def test_add_text(self):
1590
backing = self.get_transport()
1591
request = smart_repo.SmartServerRepositoryAddSignatureText(backing)
1592
tree = self.make_branch_and_memory_tree('.')
1593
write_token = tree.lock_write()
1594
self.addCleanup(tree.unlock)
1596
tree.commit("Message", rev_id=b'rev1')
1597
tree.branch.repository.start_write_group()
1598
write_group_tokens = tree.branch.repository.suspend_write_group()
1599
self.assertEqual(None, request.execute(b'', write_token,
1600
b'rev1', *write_group_tokens))
1601
response = request.do_body('somesignature')
1602
self.assertTrue(response.is_successful())
1603
self.assertEqual(response.args[0], 'ok')
1604
write_group_tokens = response.args[1:]
1605
tree.branch.repository.resume_write_group(write_group_tokens)
1606
tree.branch.repository.commit_write_group()
1608
self.assertEqual("somesignature",
1609
tree.branch.repository.get_signature_text("rev1"))
1612
class TestSmartServerRepositoryAllRevisionIds(
1613
tests.TestCaseWithMemoryTransport):
1615
def test_empty(self):
1616
"""An empty body should be returned for an empty repository."""
1617
backing = self.get_transport()
1618
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1619
self.make_repository('.')
1621
smart_req.SuccessfulSmartServerResponse((b"ok", ), b""),
1622
request.execute(b''))
1624
def test_some_revisions(self):
1625
"""An empty body should be returned for an empty repository."""
1626
backing = self.get_transport()
1627
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1628
tree = self.make_branch_and_memory_tree('.')
1631
tree.commit(rev_id=b'origineel', message="message")
1632
tree.commit(rev_id=b'nog-een-revisie', message="message")
1635
smart_req.SuccessfulSmartServerResponse((b"ok", ),
1636
b"origineel\nnog-een-revisie"),
1637
request.execute(b''))
1640
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1642
def test_lock_to_break(self):
1643
backing = self.get_transport()
1644
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1645
tree = self.make_branch_and_memory_tree('.')
1646
tree.branch.repository.lock_write()
1648
smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1649
request.execute(b''))
1651
def test_nothing_to_break(self):
1652
backing = self.get_transport()
1653
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1654
tree = self.make_branch_and_memory_tree('.')
1656
smart_req.SuccessfulSmartServerResponse((b'ok', ), None),
1657
request.execute(b''))
1325
1660
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithMemoryTransport):
1327
1662
def test_trivial_bzipped(self):
1459
1838
repo = tree.branch.repository
1460
1839
return repo, r1, r2
1842
class TestSmartServerRepositoryGetStream(GetStreamTestBase):
1462
1844
def test_ancestry_of(self):
1463
1845
"""The search argument may be a 'ancestry-of' some heads'."""
1464
1846
backing = self.get_transport()
1465
1847
request = smart_repo.SmartServerRepositoryGetStream(backing)
1466
1848
repo, r1, r2 = self.make_two_commit_repo()
1467
fetch_spec = ['ancestry-of', r2]
1468
lines = '\n'.join(fetch_spec)
1469
request.execute('', repo._format.network_name())
1849
fetch_spec = [b'ancestry-of', r2]
1850
lines = b'\n'.join(fetch_spec)
1851
request.execute(b'', repo._format.network_name())
1470
1852
response = request.do_body(lines)
1471
self.assertEqual(('ok',), response.args)
1472
stream_bytes = ''.join(response.body_stream)
1473
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1853
self.assertEqual((b'ok',), response.args)
1854
stream_bytes = b''.join(response.body_stream)
1855
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1475
1857
def test_search(self):
1476
1858
"""The search argument may be a 'search' of some explicit keys."""
1477
1859
backing = self.get_transport()
1478
1860
request = smart_repo.SmartServerRepositoryGetStream(backing)
1479
1861
repo, r1, r2 = self.make_two_commit_repo()
1480
fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
1481
lines = '\n'.join(fetch_spec)
1482
request.execute('', repo._format.network_name())
1862
fetch_spec = [b'search', r1 + b' ' + r2, b'null:', b'2']
1863
lines = b'\n'.join(fetch_spec)
1864
request.execute(b'', repo._format.network_name())
1483
1865
response = request.do_body(lines)
1484
self.assertEqual(('ok',), response.args)
1485
stream_bytes = ''.join(response.body_stream)
1486
self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
1866
self.assertEqual((b'ok',), response.args)
1867
stream_bytes = b''.join(response.body_stream)
1868
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1870
def test_search_everything(self):
1871
"""A search of 'everything' returns a stream."""
1872
backing = self.get_transport()
1873
request = smart_repo.SmartServerRepositoryGetStream_1_19(backing)
1874
repo, r1, r2 = self.make_two_commit_repo()
1875
serialised_fetch_spec = b'everything'
1876
request.execute(b'', repo._format.network_name())
1877
response = request.do_body(serialised_fetch_spec)
1878
self.assertEqual((b'ok',), response.args)
1879
stream_bytes = b''.join(response.body_stream)
1880
self.assertStartsWith(stream_bytes, b'Bazaar pack format 1')
1489
1883
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
1507
1901
r1 = tree.commit('a commit', rev_id=rev_id_utf8)
1509
1903
self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
1510
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1511
request.execute('', rev_id_utf8))
1904
self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1905
request.execute(b'', rev_id_utf8))
1908
class TestSmartServerRepositoryIterFilesBytes(tests.TestCaseWithTransport):
1910
def test_single(self):
1911
backing = self.get_transport()
1912
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1913
t = self.make_branch_and_tree('.')
1914
self.addCleanup(t.lock_write().unlock)
1915
self.build_tree_contents([("file", b"somecontents")])
1916
t.add(["file"], [b"thefileid"])
1917
t.commit(rev_id=b'somerev', message="add file")
1918
self.assertIs(None, request.execute(b''))
1919
response = request.do_body(b"thefileid\0somerev\n")
1920
self.assertTrue(response.is_successful())
1921
self.assertEqual(response.args, (b"ok", ))
1922
self.assertEqual(b"".join(response.body_stream),
1923
b"ok\x000\n" + zlib.compress(b"somecontents"))
1925
def test_missing(self):
1926
backing = self.get_transport()
1927
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1928
t = self.make_branch_and_tree('.')
1929
self.addCleanup(t.lock_write().unlock)
1930
self.assertIs(None, request.execute(b''))
1931
response = request.do_body(b"thefileid\0revision\n")
1932
self.assertTrue(response.is_successful())
1933
self.assertEqual(response.args, (b"ok", ))
1934
self.assertEqual(b"".join(response.body_stream),
1935
b"absent\x00thefileid\x00revision\x000\n")
1938
class TestSmartServerRequestHasSignatureForRevisionId(
1939
tests.TestCaseWithMemoryTransport):
1941
def test_missing_revision(self):
1942
"""For a missing revision, NoSuchRevision is returned."""
1943
backing = self.get_transport()
1944
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1946
self.make_repository('.')
1948
smart_req.FailedSmartServerResponse(
1949
(b'nosuchrevision', b'revid'), None),
1950
request.execute(b'', b'revid'))
1952
def test_missing_signature(self):
1953
"""For a missing signature, ('no', ) is returned."""
1954
backing = self.get_transport()
1955
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1957
tree = self.make_branch_and_memory_tree('.')
1960
r1 = tree.commit('a commit', rev_id=b'A')
1962
self.assertTrue(tree.branch.repository.has_revision('A'))
1963
self.assertEqual(smart_req.SmartServerResponse((b'no', )),
1964
request.execute(b'', b'A'))
1966
def test_present_signature(self):
1967
"""For a present signature, ('yes', ) is returned."""
1968
backing = self.get_transport()
1969
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1971
strategy = gpg.LoopbackGPGStrategy(None)
1972
tree = self.make_branch_and_memory_tree('.')
1975
r1 = tree.commit('a commit', rev_id=b'A')
1976
tree.branch.repository.start_write_group()
1977
tree.branch.repository.sign_revision(b'A', strategy)
1978
tree.branch.repository.commit_write_group()
1980
self.assertTrue(tree.branch.repository.has_revision(b'A'))
1981
self.assertEqual(smart_req.SmartServerResponse((b'yes', )),
1982
request.execute(b'', b'A'))
1514
1985
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
1745
2313
repo.set_make_working_trees(False)
1746
2314
request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
1747
2315
request = request_class(backing)
1748
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
1749
request.execute('', 'True'))
1750
repo = repo.bzrdir.open_repository()
2316
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2317
request.execute(b'', b'True'))
2318
repo = repo.controldir.open_repository()
1751
2319
self.assertTrue(repo.make_working_trees())
2322
class TestSmartServerRepositoryGetSerializerFormat(
2323
tests.TestCaseWithMemoryTransport):
2325
def test_get_serializer_format(self):
2326
backing = self.get_transport()
2327
repo = self.make_repository('.', format='2a')
2328
request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2329
request = request_class(backing)
2331
smart_req.SuccessfulSmartServerResponse((b'ok', b'10')),
2332
request.execute(b''))
2335
class TestSmartServerRepositoryWriteGroup(
2336
tests.TestCaseWithMemoryTransport):
2338
def test_start_write_group(self):
2339
backing = self.get_transport()
2340
repo = self.make_repository('.')
2341
lock_token = repo.lock_write().repository_token
2342
self.addCleanup(repo.unlock)
2343
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2344
request = request_class(backing)
2345
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok', [])),
2346
request.execute(b'', lock_token))
2348
def test_start_write_group_unsuspendable(self):
2349
backing = self.get_transport()
2350
repo = self.make_repository('.', format='knit')
2351
lock_token = repo.lock_write().repository_token
2352
self.addCleanup(repo.unlock)
2353
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2354
request = request_class(backing)
2356
smart_req.FailedSmartServerResponse((b'UnsuspendableWriteGroup',)),
2357
request.execute(b'', lock_token))
2359
def test_commit_write_group(self):
2360
backing = self.get_transport()
2361
repo = self.make_repository('.')
2362
lock_token = repo.lock_write().repository_token
2363
self.addCleanup(repo.unlock)
2364
repo.start_write_group()
2365
tokens = repo.suspend_write_group()
2366
request_class = smart_repo.SmartServerRepositoryCommitWriteGroup
2367
request = request_class(backing)
2368
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2369
request.execute(b'', lock_token, tokens))
2371
def test_abort_write_group(self):
2372
backing = self.get_transport()
2373
repo = self.make_repository('.')
2374
lock_token = repo.lock_write().repository_token
2375
repo.start_write_group()
2376
tokens = repo.suspend_write_group()
2377
self.addCleanup(repo.unlock)
2378
request_class = smart_repo.SmartServerRepositoryAbortWriteGroup
2379
request = request_class(backing)
2380
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2381
request.execute(b'', lock_token, tokens))
2383
def test_check_write_group(self):
2384
backing = self.get_transport()
2385
repo = self.make_repository('.')
2386
lock_token = repo.lock_write().repository_token
2387
repo.start_write_group()
2388
tokens = repo.suspend_write_group()
2389
self.addCleanup(repo.unlock)
2390
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2391
request = request_class(backing)
2392
self.assertEqual(smart_req.SuccessfulSmartServerResponse((b'ok',)),
2393
request.execute(b'', lock_token, tokens))
2395
def test_check_write_group_invalid(self):
2396
backing = self.get_transport()
2397
repo = self.make_repository('.')
2398
lock_token = repo.lock_write().repository_token
2399
self.addCleanup(repo.unlock)
2400
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2401
request = request_class(backing)
2402
self.assertEqual(smart_req.FailedSmartServerResponse(
2403
(b'UnresumableWriteGroup', [b'random'],
2404
b'Malformed write group token')),
2405
request.execute(b'', lock_token, [b"random"]))
1754
2408
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1756
2410
def make_repo_needing_autopacking(self, path='.'):
1822
2476
"""All registered request_handlers can be found."""
1823
2477
# If there's a typo in a register_lazy call, this loop will fail with
1824
2478
# an AttributeError.
1825
for key, item in smart_req.request_handlers.iteritems():
2479
for key in smart_req.request_handlers.keys():
2481
item = smart_req.request_handlers.get(key)
2482
except AttributeError as e:
2483
raise AttributeError('failed to get %s: %s' % (key, e))
1828
2485
def assertHandlerEqual(self, verb, handler):
1829
2486
self.assertEqual(smart_req.request_handlers.get(verb), handler)
1831
2488
def test_registered_methods(self):
1832
2489
"""Test that known methods are registered to the correct object."""
1833
self.assertHandlerEqual('Branch.get_config_file',
2490
self.assertHandlerEqual(b'Branch.break_lock',
2491
smart_branch.SmartServerBranchBreakLock)
2492
self.assertHandlerEqual(b'Branch.get_config_file',
1834
2493
smart_branch.SmartServerBranchGetConfigFile)
1835
self.assertHandlerEqual('Branch.get_parent',
2494
self.assertHandlerEqual(b'Branch.put_config_file',
2495
smart_branch.SmartServerBranchPutConfigFile)
2496
self.assertHandlerEqual(b'Branch.get_parent',
1836
2497
smart_branch.SmartServerBranchGetParent)
1837
self.assertHandlerEqual('Branch.get_tags_bytes',
2498
self.assertHandlerEqual(b'Branch.get_physical_lock_status',
2499
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
2500
self.assertHandlerEqual(b'Branch.get_tags_bytes',
1838
2501
smart_branch.SmartServerBranchGetTagsBytes)
1839
self.assertHandlerEqual('Branch.lock_write',
2502
self.assertHandlerEqual(b'Branch.lock_write',
1840
2503
smart_branch.SmartServerBranchRequestLockWrite)
1841
self.assertHandlerEqual('Branch.last_revision_info',
2504
self.assertHandlerEqual(b'Branch.last_revision_info',
1842
2505
smart_branch.SmartServerBranchRequestLastRevisionInfo)
1843
self.assertHandlerEqual('Branch.revision_history',
2506
self.assertHandlerEqual(b'Branch.revision_history',
1844
2507
smart_branch.SmartServerRequestRevisionHistory)
1845
self.assertHandlerEqual('Branch.set_config_option',
2508
self.assertHandlerEqual(b'Branch.revision_id_to_revno',
2509
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
2510
self.assertHandlerEqual(b'Branch.set_config_option',
1846
2511
smart_branch.SmartServerBranchRequestSetConfigOption)
1847
self.assertHandlerEqual('Branch.set_last_revision',
2512
self.assertHandlerEqual(b'Branch.set_last_revision',
1848
2513
smart_branch.SmartServerBranchRequestSetLastRevision)
1849
self.assertHandlerEqual('Branch.set_last_revision_info',
2514
self.assertHandlerEqual(b'Branch.set_last_revision_info',
1850
2515
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
1851
self.assertHandlerEqual('Branch.set_last_revision_ex',
2516
self.assertHandlerEqual(b'Branch.set_last_revision_ex',
1852
2517
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
1853
self.assertHandlerEqual('Branch.set_parent_location',
2518
self.assertHandlerEqual(b'Branch.set_parent_location',
1854
2519
smart_branch.SmartServerBranchRequestSetParentLocation)
1855
self.assertHandlerEqual('Branch.unlock',
2520
self.assertHandlerEqual(b'Branch.unlock',
1856
2521
smart_branch.SmartServerBranchRequestUnlock)
1857
self.assertHandlerEqual('BzrDir.find_repository',
2522
self.assertHandlerEqual(b'BzrDir.destroy_branch',
2523
smart_dir.SmartServerBzrDirRequestDestroyBranch)
2524
self.assertHandlerEqual(b'BzrDir.find_repository',
1858
2525
smart_dir.SmartServerRequestFindRepositoryV1)
1859
self.assertHandlerEqual('BzrDir.find_repositoryV2',
2526
self.assertHandlerEqual(b'BzrDir.find_repositoryV2',
1860
2527
smart_dir.SmartServerRequestFindRepositoryV2)
1861
self.assertHandlerEqual('BzrDirFormat.initialize',
2528
self.assertHandlerEqual(b'BzrDirFormat.initialize',
1862
2529
smart_dir.SmartServerRequestInitializeBzrDir)
1863
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2530
self.assertHandlerEqual(b'BzrDirFormat.initialize_ex_1.16',
1864
2531
smart_dir.SmartServerRequestBzrDirInitializeEx)
1865
self.assertHandlerEqual('BzrDir.cloning_metadir',
2532
self.assertHandlerEqual(b'BzrDir.checkout_metadir',
2533
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2534
self.assertHandlerEqual(b'BzrDir.cloning_metadir',
1866
2535
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
1867
self.assertHandlerEqual('BzrDir.get_config_file',
2536
self.assertHandlerEqual(b'BzrDir.get_branches',
2537
smart_dir.SmartServerBzrDirRequestGetBranches)
2538
self.assertHandlerEqual(b'BzrDir.get_config_file',
1868
2539
smart_dir.SmartServerBzrDirRequestConfigFile)
1869
self.assertHandlerEqual('BzrDir.open_branch',
2540
self.assertHandlerEqual(b'BzrDir.open_branch',
1870
2541
smart_dir.SmartServerRequestOpenBranch)
1871
self.assertHandlerEqual('BzrDir.open_branchV2',
2542
self.assertHandlerEqual(b'BzrDir.open_branchV2',
1872
2543
smart_dir.SmartServerRequestOpenBranchV2)
1873
self.assertHandlerEqual('BzrDir.open_branchV3',
2544
self.assertHandlerEqual(b'BzrDir.open_branchV3',
1874
2545
smart_dir.SmartServerRequestOpenBranchV3)
1875
self.assertHandlerEqual('PackRepository.autopack',
2546
self.assertHandlerEqual(b'PackRepository.autopack',
1876
2547
smart_packrepo.SmartServerPackRepositoryAutopack)
1877
self.assertHandlerEqual('Repository.gather_stats',
2548
self.assertHandlerEqual(b'Repository.add_signature_text',
2549
smart_repo.SmartServerRepositoryAddSignatureText)
2550
self.assertHandlerEqual(b'Repository.all_revision_ids',
2551
smart_repo.SmartServerRepositoryAllRevisionIds)
2552
self.assertHandlerEqual(b'Repository.break_lock',
2553
smart_repo.SmartServerRepositoryBreakLock)
2554
self.assertHandlerEqual(b'Repository.gather_stats',
1878
2555
smart_repo.SmartServerRepositoryGatherStats)
1879
self.assertHandlerEqual('Repository.get_parent_map',
2556
self.assertHandlerEqual(b'Repository.get_parent_map',
1880
2557
smart_repo.SmartServerRepositoryGetParentMap)
1881
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
2558
self.assertHandlerEqual(b'Repository.get_physical_lock_status',
2559
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
2560
self.assertHandlerEqual(b'Repository.get_rev_id_for_revno',
1882
2561
smart_repo.SmartServerRepositoryGetRevIdForRevno)
1883
self.assertHandlerEqual('Repository.get_revision_graph',
2562
self.assertHandlerEqual(b'Repository.get_revision_graph',
1884
2563
smart_repo.SmartServerRepositoryGetRevisionGraph)
1885
self.assertHandlerEqual('Repository.get_stream',
2564
self.assertHandlerEqual(b'Repository.get_revision_signature_text',
2565
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
2566
self.assertHandlerEqual(b'Repository.get_stream',
1886
2567
smart_repo.SmartServerRepositoryGetStream)
1887
self.assertHandlerEqual('Repository.has_revision',
2568
self.assertHandlerEqual(b'Repository.get_stream_1.19',
2569
smart_repo.SmartServerRepositoryGetStream_1_19)
2570
self.assertHandlerEqual(b'Repository.iter_revisions',
2571
smart_repo.SmartServerRepositoryIterRevisions)
2572
self.assertHandlerEqual(b'Repository.has_revision',
1888
2573
smart_repo.SmartServerRequestHasRevision)
1889
self.assertHandlerEqual('Repository.insert_stream',
2574
self.assertHandlerEqual(b'Repository.insert_stream',
1890
2575
smart_repo.SmartServerRepositoryInsertStream)
1891
self.assertHandlerEqual('Repository.insert_stream_locked',
2576
self.assertHandlerEqual(b'Repository.insert_stream_locked',
1892
2577
smart_repo.SmartServerRepositoryInsertStreamLocked)
1893
self.assertHandlerEqual('Repository.is_shared',
2578
self.assertHandlerEqual(b'Repository.is_shared',
1894
2579
smart_repo.SmartServerRepositoryIsShared)
1895
self.assertHandlerEqual('Repository.lock_write',
2580
self.assertHandlerEqual(b'Repository.iter_files_bytes',
2581
smart_repo.SmartServerRepositoryIterFilesBytes)
2582
self.assertHandlerEqual(b'Repository.lock_write',
1896
2583
smart_repo.SmartServerRepositoryLockWrite)
1897
self.assertHandlerEqual('Repository.tarball',
2584
self.assertHandlerEqual(b'Repository.make_working_trees',
2585
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2586
self.assertHandlerEqual(b'Repository.pack',
2587
smart_repo.SmartServerRepositoryPack)
2588
self.assertHandlerEqual(b'Repository.reconcile',
2589
smart_repo.SmartServerRepositoryReconcile)
2590
self.assertHandlerEqual(b'Repository.tarball',
1898
2591
smart_repo.SmartServerRepositoryTarball)
1899
self.assertHandlerEqual('Repository.unlock',
2592
self.assertHandlerEqual(b'Repository.unlock',
1900
2593
smart_repo.SmartServerRepositoryUnlock)
1901
self.assertHandlerEqual('Transport.is_readonly',
2594
self.assertHandlerEqual(b'Repository.start_write_group',
2595
smart_repo.SmartServerRepositoryStartWriteGroup)
2596
self.assertHandlerEqual(b'Repository.check_write_group',
2597
smart_repo.SmartServerRepositoryCheckWriteGroup)
2598
self.assertHandlerEqual(b'Repository.commit_write_group',
2599
smart_repo.SmartServerRepositoryCommitWriteGroup)
2600
self.assertHandlerEqual(b'Repository.abort_write_group',
2601
smart_repo.SmartServerRepositoryAbortWriteGroup)
2602
self.assertHandlerEqual(b'VersionedFileRepository.get_serializer_format',
2603
smart_repo.SmartServerRepositoryGetSerializerFormat)
2604
self.assertHandlerEqual(b'VersionedFileRepository.get_inventories',
2605
smart_repo.SmartServerRepositoryGetInventories)
2606
self.assertHandlerEqual(b'Transport.is_readonly',
1902
2607
smart_req.SmartServerIsReadonly)
2610
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2611
"""Tests for SmartTCPServer hooks."""
2614
super(SmartTCPServerHookTests, self).setUp()
2615
self.server = server.SmartTCPServer(self.get_transport())
2617
def test_run_server_started_hooks(self):
2618
"""Test the server started hooks get fired properly."""
2620
server.SmartTCPServer.hooks.install_named_hook('server_started',
2621
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2623
started_ex_calls = []
2624
server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2625
lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2627
self.server._sockname = ('example.com', 42)
2628
self.server.run_server_started_hooks()
2629
self.assertEqual(started_calls,
2630
[([self.get_transport().base], 'bzr://example.com:42/')])
2631
self.assertEqual(started_ex_calls,
2632
[([self.get_transport().base], self.server)])
2634
def test_run_server_started_hooks_ipv6(self):
2635
"""Test that socknames can contain 4-tuples."""
2636
self.server._sockname = ('::', 42, 0, 0)
2638
server.SmartTCPServer.hooks.install_named_hook('server_started',
2639
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2641
self.server.run_server_started_hooks()
2642
self.assertEqual(started_calls,
2643
[([self.get_transport().base], 'bzr://:::42/')])
2645
def test_run_server_stopped_hooks(self):
2646
"""Test the server stopped hooks."""
2647
self.server._sockname = ('example.com', 42)
2649
server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2650
lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2652
self.server.run_server_stopped_hooks()
2653
self.assertEqual(stopped_calls,
2654
[([self.get_transport().base], 'bzr://example.com:42/')])
2657
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
2659
def test_pack(self):
2660
backing = self.get_transport()
2661
request = smart_repo.SmartServerRepositoryPack(backing)
2662
tree = self.make_branch_and_memory_tree('.')
2663
repo_token = tree.branch.repository.lock_write().repository_token
2665
self.assertIs(None, request.execute(b'', repo_token, False))
2668
smart_req.SuccessfulSmartServerResponse((b'ok', ), ),
2669
request.do_body(b''))
2672
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2674
def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2675
base_inv = repository.revision_tree(base_revid).root_inventory
2676
inv = repository.revision_tree(revid).root_inventory
2677
inv_delta = inv._make_delta(base_inv)
2678
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2679
return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2681
def test_single(self):
2682
backing = self.get_transport()
2683
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2684
t = self.make_branch_and_tree('.', format='2a')
2685
self.addCleanup(t.lock_write().unlock)
2686
self.build_tree_contents([("file", b"somecontents")])
2687
t.add(["file"], [b"thefileid"])
2688
t.commit(rev_id=b'somerev', message="add file")
2689
self.assertIs(None, request.execute(b'', b'unordered'))
2690
response = request.do_body(b"somerev\n")
2691
self.assertTrue(response.is_successful())
2692
self.assertEqual(response.args, (b"ok", ))
2693
stream = [('inventory-deltas', [
2694
versionedfile.FulltextContentFactory('somerev', None, None,
2695
self._get_serialized_inventory_delta(
2696
t.branch.repository, b'null:', b'somerev'))])]
2697
fmt = controldir.format_registry.get('2a')().repository_format
2699
b"".join(response.body_stream),
2700
b"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2702
def test_empty(self):
2703
backing = self.get_transport()
2704
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2705
t = self.make_branch_and_tree('.', format='2a')
2706
self.addCleanup(t.lock_write().unlock)
2707
self.build_tree_contents([("file", b"somecontents")])
2708
t.add(["file"], [b"thefileid"])
2709
t.commit(rev_id=b'somerev', message="add file")
2710
self.assertIs(None, request.execute(b'', b'unordered'))
2711
response = request.do_body(b"")
2712
self.assertTrue(response.is_successful())
2713
self.assertEqual(response.args, (b"ok", ))
2714
self.assertEqual(b"".join(response.body_stream),
2715
b"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")