119
121
stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
120
122
None, 'foo')]),('text', [
121
123
versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
122
fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
124
fmt = controldir.format_registry.get('pack-0.92')().repository_format
123
125
bytes = smart_repo._stream_to_byte_stream(stream, fmt)
125
127
# Iterate the resulting iterable; checking that we get only one stream
224
226
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')),
227
247
class TestSmartServerBzrDirRequestDestroyBranch(
228
248
tests.TestCaseWithMemoryTransport):
229
249
"""Tests for BzrDir.destroy_branch."""
399
419
backing = self.get_transport()
400
420
request = self._request_class(backing)
401
421
result = self._make_repository_and_result(
402
format='dirstate-with-subtree')
422
format='development-subtree')
403
423
# check the test will be valid
404
424
self.assertEqual('yes', result.args[2])
405
425
self.assertEqual('yes', result.args[3])
410
430
backing = self.get_transport()
411
431
request = self._request_class(backing)
412
432
result = self._make_repository_and_result(
413
format='dirstate-with-subtree')
433
format='development-subtree')
414
434
# check the test will be valid
415
self.assertEqual('no', result.args[4])
435
self.assertEqual('yes', result.args[4])
416
436
self.assertEqual(result, request.execute(''))
439
459
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(''))
442
488
class TestSmartServerRequestInitializeBzrDir(tests.TestCaseWithMemoryTransport):
444
490
def test_empty_dir(self):
447
493
request = smart_dir.SmartServerRequestInitializeBzrDir(backing)
448
494
self.assertEqual(smart_req.SmartServerResponse(('ok', )),
449
495
request.execute(''))
450
made_dir = bzrdir.BzrDir.open_from_transport(backing)
496
made_dir = controldir.ControlDir.open_from_transport(backing)
451
497
# no branch, tree or repository is expected with the current
452
498
# default formart.
453
499
self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
487
533
'False', '', '', '')),
488
534
request.execute(name, '', 'True', 'False', 'False', '', '', '', '',
490
made_dir = bzrdir.BzrDir.open_from_transport(backing)
536
made_dir = controldir.ControlDir.open_from_transport(backing)
491
537
# no branch, tree or repository is expected with the current
492
538
# default format.
493
539
self.assertRaises(errors.NoWorkingTree, made_dir.open_workingtree)
1286
1334
branch_token, repo_token = self.get_lock_tokens(branch)
1288
1336
response = request.execute('base', branch_token, repo_token,
1291
1339
branch.unlock()
1292
1340
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1293
self.assertEqual('http://bar/', branch.get_parent())
1341
refreshed = _mod_branch.Branch.open(branch.base)
1342
self.assertEqual('http://bar/', refreshed.get_parent())
1296
1345
class TestSmartServerBranchRequestGetTagsBytes(
2208
2245
request.execute('', ))
2248
class TestSmartServerRepositoryReconcile(tests.TestCaseWithTransport):
2250
def test_reconcile(self):
2251
backing = self.get_transport()
2252
repo = self.make_repository('.')
2253
token = repo.lock_write().repository_token
2254
self.addCleanup(repo.unlock)
2255
request_class = smart_repo.SmartServerRepositoryReconcile
2256
request = request_class(backing)
2257
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
2259
'garbage_inventories: 0\n'
2260
'inconsistent_parents: 0\n'),
2261
request.execute('', token))
2211
2264
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
2213
2266
def test_is_readonly_no(self):
2461
2514
smart_dir.SmartServerRequestInitializeBzrDir)
2462
2515
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
2463
2516
smart_dir.SmartServerRequestBzrDirInitializeEx)
2517
self.assertHandlerEqual('BzrDir.checkout_metadir',
2518
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
2464
2519
self.assertHandlerEqual('BzrDir.cloning_metadir',
2465
2520
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2521
self.assertHandlerEqual('BzrDir.get_branches',
2522
smart_dir.SmartServerBzrDirRequestGetBranches)
2466
2523
self.assertHandlerEqual('BzrDir.get_config_file',
2467
2524
smart_dir.SmartServerBzrDirRequestConfigFile)
2468
2525
self.assertHandlerEqual('BzrDir.open_branch',
2513
2570
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2514
2571
self.assertHandlerEqual('Repository.pack',
2515
2572
smart_repo.SmartServerRepositoryPack)
2573
self.assertHandlerEqual('Repository.reconcile',
2574
smart_repo.SmartServerRepositoryReconcile)
2516
2575
self.assertHandlerEqual('Repository.tarball',
2517
2576
smart_repo.SmartServerRepositoryTarball)
2518
2577
self.assertHandlerEqual('Repository.unlock',
2527
2586
smart_repo.SmartServerRepositoryAbortWriteGroup)
2528
2587
self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2529
2588
smart_repo.SmartServerRepositoryGetSerializerFormat)
2589
self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2590
smart_repo.SmartServerRepositoryGetInventories)
2530
2591
self.assertHandlerEqual('Transport.is_readonly',
2531
2592
smart_req.SmartServerIsReadonly)
2592
2653
smart_req.SuccessfulSmartServerResponse(('ok', ), ),
2593
2654
request.do_body(''))
2657
class TestSmartServerRepositoryGetInventories(tests.TestCaseWithTransport):
2659
def _get_serialized_inventory_delta(self, repository, base_revid, revid):
2660
base_inv = repository.revision_tree(base_revid).root_inventory
2661
inv = repository.revision_tree(revid).root_inventory
2662
inv_delta = inv._make_delta(base_inv)
2663
serializer = inventory_delta.InventoryDeltaSerializer(True, False)
2664
return "".join(serializer.delta_to_lines(base_revid, revid, inv_delta))
2666
def test_single(self):
2667
backing = self.get_transport()
2668
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2669
t = self.make_branch_and_tree('.', format='2a')
2670
self.addCleanup(t.lock_write().unlock)
2671
self.build_tree_contents([("file", "somecontents")])
2672
t.add(["file"], ["thefileid"])
2673
t.commit(rev_id='somerev', message="add file")
2674
self.assertIs(None, request.execute('', 'unordered'))
2675
response = request.do_body("somerev\n")
2676
self.assertTrue(response.is_successful())
2677
self.assertEquals(response.args, ("ok", ))
2678
stream = [('inventory-deltas', [
2679
versionedfile.FulltextContentFactory('somerev', None, None,
2680
self._get_serialized_inventory_delta(
2681
t.branch.repository, 'null:', 'somerev'))])]
2682
fmt = controldir.format_registry.get('2a')().repository_format
2684
"".join(response.body_stream),
2685
"".join(smart_repo._stream_to_byte_stream(stream, fmt)))
2687
def test_empty(self):
2688
backing = self.get_transport()
2689
request = smart_repo.SmartServerRepositoryGetInventories(backing)
2690
t = self.make_branch_and_tree('.', format='2a')
2691
self.addCleanup(t.lock_write().unlock)
2692
self.build_tree_contents([("file", "somecontents")])
2693
t.add(["file"], ["thefileid"])
2694
t.commit(rev_id='somerev', message="add file")
2695
self.assertIs(None, request.execute('', 'unordered'))
2696
response = request.do_body("")
2697
self.assertTrue(response.is_successful())
2698
self.assertEquals(response.args, ("ok", ))
2699
self.assertEquals("".join(response.body_stream),
2700
"Bazaar pack format 1 (introduced in 0.18)\nB54\n\nBazaar repository format 2a (needs bzr 1.16 or later)\nE")