226
224
self.assertEqual(expected, request.execute('', 'False'))
229
class TestSmartServerBzrDirRequestCloningMetaDir(
230
tests.TestCaseWithMemoryTransport):
231
"""Tests for BzrDir.checkout_metadir."""
233
def test_checkout_metadir(self):
234
backing = self.get_transport()
235
request = smart_dir.SmartServerBzrDirRequestCheckoutMetaDir(
237
branch = self.make_branch('.', format='2a')
238
response = request.execute('')
240
smart_req.SmartServerResponse(
241
('Bazaar-NG meta directory, format 1\n',
242
'Bazaar repository format 2a (needs bzr 1.16 or later)\n',
243
'Bazaar Branch Format 7 (needs bzr 1.6)\n')),
247
227
class TestSmartServerBzrDirRequestDestroyBranch(
248
228
tests.TestCaseWithMemoryTransport):
249
229
"""Tests for BzrDir.destroy_branch."""
419
399
backing = self.get_transport()
420
400
request = self._request_class(backing)
421
401
result = self._make_repository_and_result(
422
format='development-subtree')
402
format='dirstate-with-subtree')
423
403
# check the test will be valid
424
404
self.assertEqual('yes', result.args[2])
425
405
self.assertEqual('yes', result.args[3])
430
410
backing = self.get_transport()
431
411
request = self._request_class(backing)
432
412
result = self._make_repository_and_result(
433
format='development-subtree')
413
format='dirstate-with-subtree')
434
414
# check the test will be valid
435
self.assertEqual('yes', result.args[4])
415
self.assertEqual('no', result.args[4])
436
416
self.assertEqual(result, request.execute(''))
459
439
self.assertEqual(expected, request.execute(''))
462
class TestSmartServerBzrDirRequestGetBranches(
463
tests.TestCaseWithMemoryTransport):
464
"""Tests for BzrDir.get_branches."""
466
def test_simple(self):
467
backing = self.get_transport()
468
branch = self.make_branch('.')
469
request_class = smart_dir.SmartServerBzrDirRequestGetBranches
470
request = request_class(backing)
471
local_result = bencode.bencode(
472
{"": ("branch", branch._format.network_name())})
473
expected = smart_req.SuccessfulSmartServerResponse(
474
("success", ), local_result)
475
self.assertEqual(expected, request.execute(''))
477
def test_empty(self):
478
backing = self.get_transport()
479
dir = self.make_bzrdir('.')
480
request_class = smart_dir.SmartServerBzrDirRequestGetBranches
481
request = request_class(backing)
482
local_result = bencode.bencode({})
483
expected = smart_req.SuccessfulSmartServerResponse(
484
('success',), local_result)
485
self.assertEqual(expected, request.execute(''))
488
442
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
490
444
def test_empty_dir(self):
1334
1286
branch_token, repo_token = self.get_lock_tokens(branch)
1336
1288
response = request.execute('base', branch_token, repo_token,
1339
1291
branch.unlock()
1340
1292
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1341
refreshed = _mod_branch.Branch.open(branch.base)
1342
self.assertEqual('http://bar/', refreshed.get_parent())
1293
self.assertEqual('http://bar/', branch.get_parent())
1345
1296
class TestSmartServerBranchRequestGetTagsBytes(
2257
2208
request.execute('', ))
2260
class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
2262
def test_reconcile(self):
2263
backing = self.get_transport()
2264
repo = self.make_repository('.')
2265
token = repo.lock_write().repository_token
2266
self.addCleanup(repo.unlock)
2267
request_class = smart_repo.SmartServerRepositoryReconcile
2268
request = request_class(backing)
2269
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
2271
'garbage_inventories: 0\n'
2272
'inconsistent_parents: 0\n'),
2273
request.execute('', token))
2276
2211
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
2278
2213
def test_is_readonly_no(self):
2526
2461
smart_dir.SmartServerRequestInitializeBzrDir)
2527
2462
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2528
2463
smart_dir.SmartServerRequestBzrDirInitializeEx)
2529
self.assertHandlerEqual('BzrDir.checkout_metadir',
2530
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2531
2464
self.assertHandlerEqual('BzrDir.cloning_metadir',
2532
2465
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2533
self.assertHandlerEqual('BzrDir.get_branches',
2534
smart_dir.SmartServerBzrDirRequestGetBranches)
2535
2466
self.assertHandlerEqual('BzrDir.get_config_file',
2536
2467
smart_dir.SmartServerBzrDirRequestConfigFile)
2537
2468
self.assertHandlerEqual('BzrDir.open_branch',
2582
2513
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2583
2514
self.assertHandlerEqual('Repository.pack',
2584
2515
smart_repo.SmartServerRepositoryPack)
2585
self.assertHandlerEqual('Repository.reconcile',
2586
smart_repo.SmartServerRepositoryReconcile)
2587
2516
self.assertHandlerEqual('Repository.tarball',
2588
2517
smart_repo.SmartServerRepositoryTarball)
2589
2518
self.assertHandlerEqual('Repository.unlock',
2598
2527
smart_repo.SmartServerRepositoryAbortWriteGroup)
2599
2528
self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2600
2529
smart_repo.SmartServerRepositoryGetSerializerFormat)
2601
self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2602
smart_repo.SmartServerRepositoryGetInventories)
2603
2530
self.assertHandlerEqual('Transport.is_readonly',
2604
2531
smart_req.SmartServerIsReadonly)
2665
2592
smart_req.SuccessfulSmartServerResponse(('ok', ), ),
2666
2593
request.do_body(''))
2669
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2671
def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2672
base_inv = repository.revision_tree(base_revid).root_inventory
2673
inv = repository.revision_tree(revid).root_inventory
2674
inv_delta = inv._make_delta(base_inv)
2675
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2676
return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2678
def test_single(self):
2679
backing = self.get_transport()
2680
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2681
t = self.make_branch_and_tree('.', format='2a')
2682
self.addCleanup(t.lock_write().unlock)
2683
self.build_tree_contents([("file", "somecontents")])
2684
t.add(["file"], ["thefileid"])
2685
t.commit(rev_id='somerev', message="add file")
2686
self.assertIs(None, request.execute('', 'unordered'))
2687
response = request.do_body("somerev\n")
2688
self.assertTrue(response.is_successful())
2689
self.assertEquals(response.args, ("ok", ))
2690
stream = [('inventory-deltas', [
2691
versionedfile.FulltextContentFactory('somerev', None, None,
2692
self._get_serialized_inventory_delta(
2693
t.branch.repository, 'null:', 'somerev'))])]
2694
fmt = bzrdir.format_registry.get('2a')().repository_format
2696
"".join(response.body_stream),
2697
"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2699
def test_empty(self):
2700
backing = self.get_transport()
2701
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2702
t = self.make_branch_and_tree('.', format='2a')
2703
self.addCleanup(t.lock_write().unlock)
2704
self.build_tree_contents([("file", "somecontents")])
2705
t.add(["file"], ["thefileid"])
2706
t.commit(rev_id='somerev', message="add file")
2707
self.assertIs(None, request.execute('', 'unordered'))
2708
response = request.do_body("")
2709
self.assertTrue(response.is_successful())
2710
self.assertEquals(response.args, ("ok", ))
2711
self.assertEquals("".join(response.body_stream),
2712
"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")