215
214
referenced_branch = self.make_branch('referenced')
216
215
dir = self.make_bzrdir('.')
217
216
local_result = dir.cloning_metadir()
218
reference = BranchReferenceFormat().initialize(dir, referenced_branch)
219
reference_url = BranchReferenceFormat().get_reference(dir)
217
reference = _mod_branch.BranchReferenceFormat().initialize(
218
dir, target_branch=referenced_branch)
219
reference_url = _mod_branch.BranchReferenceFormat().get_reference(dir)
220
220
# The server shouldn't try to follow the branch reference, so it's fine
221
221
# if the referenced branch isn't reachable.
222
222
backing.rename('referenced', 'moved')
223
223
request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
224
224
request = request_class(backing)
225
expected = FailedSmartServerResponse(('BranchReference',))
225
expected = smart_req.FailedSmartServerResponse(('BranchReference',))
226
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')),
247
class TestSmartServerBzrDirRequestDestroyBranch(
248
tests.TestCaseWithMemoryTransport):
249
"""Tests for BzrDir.destroy_branch."""
251
def test_destroy_branch_default(self):
252
"""The default branch can be removed."""
253
backing = self.get_transport()
254
dir = self.make_branch('.').bzrdir
255
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
256
request = request_class(backing)
257
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
258
self.assertEqual(expected, request.execute('', None))
260
def test_destroy_branch_named(self):
261
"""A named branch can be removed."""
262
backing = self.get_transport()
263
dir = self.make_repository('.', format="development-colo").bzrdir
264
dir.create_branch(name="branchname")
265
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
266
request = request_class(backing)
267
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
268
self.assertEqual(expected, request.execute('', "branchname"))
270
def test_destroy_branch_missing(self):
271
"""An error is raised if the branch didn't exist."""
272
backing = self.get_transport()
273
dir = self.make_bzrdir('.', format="development-colo")
274
request_class = smart_dir.SmartServerBzrDirRequestDestroyBranch
275
request = request_class(backing)
276
expected = smart_req.FailedSmartServerResponse(('nobranch',), None)
277
self.assertEqual(expected, request.execute('', "branchname"))
280
class TestSmartServerBzrDirRequestHasWorkingTree(
281
tests.TestCaseWithTransport):
282
"""Tests for BzrDir.has_workingtree."""
284
def test_has_workingtree_yes(self):
285
"""A working tree is present."""
286
backing = self.get_transport()
287
dir = self.make_branch_and_tree('.').bzrdir
288
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
289
request = request_class(backing)
290
expected = smart_req.SuccessfulSmartServerResponse(('yes',))
291
self.assertEqual(expected, request.execute(''))
293
def test_has_workingtree_no(self):
294
"""A working tree is missing."""
295
backing = self.get_transport()
296
dir = self.make_bzrdir('.')
297
request_class = smart_dir.SmartServerBzrDirRequestHasWorkingTree
298
request = request_class(backing)
299
expected = smart_req.SuccessfulSmartServerResponse(('no',))
300
self.assertEqual(expected, request.execute(''))
303
class TestSmartServerBzrDirRequestDestroyRepository(
304
tests.TestCaseWithMemoryTransport):
305
"""Tests for BzrDir.destroy_repository."""
307
def test_destroy_repository_default(self):
308
"""The repository can be removed."""
309
backing = self.get_transport()
310
dir = self.make_repository('.').bzrdir
311
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
312
request = request_class(backing)
313
expected = smart_req.SuccessfulSmartServerResponse(('ok',))
314
self.assertEqual(expected, request.execute(''))
316
def test_destroy_repository_missing(self):
317
"""An error is raised if the repository didn't exist."""
318
backing = self.get_transport()
319
dir = self.make_bzrdir('.')
320
request_class = smart_dir.SmartServerBzrDirRequestDestroyRepository
321
request = request_class(backing)
322
expected = smart_req.FailedSmartServerResponse(
323
('norepository',), None)
324
self.assertEqual(expected, request.execute(''))
229
327
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
230
328
"""Tests for BzrDir.create_repository."""
421
552
"""Initializing an extant directory should fail like the bzrdir api."""
422
553
backing = self.get_transport()
423
554
name = self.make_bzrdir('reference')._format.network_name()
424
request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
555
request = smart_dir.SmartServerRequestBzrDirInitializeEx(backing)
425
556
self.make_bzrdir('subdir')
426
557
self.assertRaises(errors.FileExists, request.execute, name, 'subdir',
427
558
'False', 'False', 'False', '', '', '', '', 'False')
430
561
class TestSmartServerRequestOpenBzrDir(tests.TestCaseWithMemoryTransport):
432
563
def test_no_directory(self):
433
564
backing = self.get_transport()
434
request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing)
435
self.assertEqual(SmartServerResponse(('no', )),
565
request = smart_dir.SmartServerRequestOpenBzrDir(backing)
566
self.assertEqual(smart_req.SmartServerResponse(('no', )),
436
567
request.execute('does-not-exist'))
438
569
def test_empty_directory(self):
439
570
backing = self.get_transport()
440
571
backing.mkdir('empty')
441
request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing)
442
self.assertEqual(SmartServerResponse(('no', )),
572
request = smart_dir.SmartServerRequestOpenBzrDir(backing)
573
self.assertEqual(smart_req.SmartServerResponse(('no', )),
443
574
request.execute('empty'))
445
576
def test_outside_root_client_path(self):
446
577
backing = self.get_transport()
447
request = smart.bzrdir.SmartServerRequestOpenBzrDir(backing,
578
request = smart_dir.SmartServerRequestOpenBzrDir(backing,
448
579
root_client_path='root')
449
self.assertEqual(SmartServerResponse(('no', )),
580
self.assertEqual(smart_req.SmartServerResponse(('no', )),
450
581
request.execute('not-root'))
453
584
class TestSmartServerRequestOpenBzrDir_2_1(tests.TestCaseWithMemoryTransport):
455
586
def test_no_directory(self):
456
587
backing = self.get_transport()
457
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
458
self.assertEqual(SmartServerResponse(('no', )),
588
request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
589
self.assertEqual(smart_req.SmartServerResponse(('no', )),
459
590
request.execute('does-not-exist'))
461
592
def test_empty_directory(self):
462
593
backing = self.get_transport()
463
594
backing.mkdir('empty')
464
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
465
self.assertEqual(SmartServerResponse(('no', )),
595
request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
596
self.assertEqual(smart_req.SmartServerResponse(('no', )),
466
597
request.execute('empty'))
468
599
def test_present_without_workingtree(self):
469
600
backing = self.get_transport()
470
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
601
request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
471
602
self.make_bzrdir('.')
472
self.assertEqual(SmartServerResponse(('yes', 'no')),
603
self.assertEqual(smart_req.SmartServerResponse(('yes', 'no')),
473
604
request.execute(''))
475
606
def test_outside_root_client_path(self):
476
607
backing = self.get_transport()
477
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing,
608
request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing,
478
609
root_client_path='root')
479
self.assertEqual(SmartServerResponse(('no',)),
610
self.assertEqual(smart_req.SmartServerResponse(('no',)),
480
611
request.execute('not-root'))
483
614
class TestSmartServerRequestOpenBzrDir_2_1_disk(TestCaseWithChrootedTransport):
485
616
def test_present_with_workingtree(self):
486
self.vfs_transport_factory = local.LocalURLServer
617
self.vfs_transport_factory = test_server.LocalURLServer
487
618
backing = self.get_transport()
488
request = smart.bzrdir.SmartServerRequestOpenBzrDir_2_1(backing)
619
request = smart_dir.SmartServerRequestOpenBzrDir_2_1(backing)
489
620
bd = self.make_bzrdir('.')
490
621
bd.create_repository()
491
622
bd.create_branch()
492
623
bd.create_workingtree()
493
self.assertEqual(SmartServerResponse(('yes', 'yes')),
624
self.assertEqual(smart_req.SmartServerResponse(('yes', 'yes')),
494
625
request.execute(''))
531
671
"""When there is no branch, ('nobranch', ) is returned."""
532
672
backing = self.get_transport()
533
673
self.make_bzrdir('.')
534
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
535
self.assertEqual(SmartServerResponse(('nobranch', )),
538
def test_branch(self):
539
"""When there is a branch, 'ok' is returned."""
540
backing = self.get_transport()
541
expected = self.make_branch('.')._format.network_name()
542
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
543
self.assertEqual(SuccessfulSmartServerResponse(('branch', expected)),
546
def test_branch_reference(self):
547
"""When there is a branch reference, the reference URL is returned."""
548
self.vfs_transport_factory = local.LocalURLServer
549
backing = self.get_transport()
550
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
551
branch = self.make_branch('branch')
552
checkout = branch.create_checkout('reference',lightweight=True)
553
reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
554
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
555
self.assertEqual(SuccessfulSmartServerResponse(('ref', reference_url)),
556
request.execute('reference'))
558
def test_stacked_branch(self):
559
"""Opening a stacked branch does not open the stacked-on branch."""
560
trunk = self.make_branch('trunk')
561
feature = self.make_branch('feature')
562
feature.set_stacked_on_url(trunk.base)
564
Branch.hooks.install_named_hook('open', opened_branches.append, None)
565
backing = self.get_transport()
566
request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
569
response = request.execute('feature')
571
request.teardown_jail()
572
expected_format = feature._format.network_name()
574
SuccessfulSmartServerResponse(('branch', expected_format)),
576
self.assertLength(1, opened_branches)
674
request = smart_dir.SmartServerRequestOpenBranchV2(backing)
675
self.assertEqual(smart_req.SmartServerResponse(('nobranch', )),
678
def test_branch(self):
679
"""When there is a branch, 'ok' is returned."""
680
backing = self.get_transport()
681
expected = self.make_branch('.')._format.network_name()
682
request = smart_dir.SmartServerRequestOpenBranchV2(backing)
683
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
684
('branch', expected)),
687
def test_branch_reference(self):
688
"""When there is a branch reference, the reference URL is returned."""
689
self.vfs_transport_factory = test_server.LocalURLServer
690
backing = self.get_transport()
691
request = smart_dir.SmartServerRequestOpenBranchV2(backing)
692
branch = self.make_branch('branch')
693
checkout = branch.create_checkout('reference',lightweight=True)
694
reference_url = _mod_branch.BranchReferenceFormat().get_reference(
696
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
697
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
698
('ref', reference_url)),
699
request.execute('reference'))
701
def test_stacked_branch(self):
702
"""Opening a stacked branch does not open the stacked-on branch."""
703
trunk = self.make_branch('trunk')
704
feature = self.make_branch('feature')
705
feature.set_stacked_on_url(trunk.base)
707
_mod_branch.Branch.hooks.install_named_hook(
708
'open', opened_branches.append, None)
709
backing = self.get_transport()
710
request = smart_dir.SmartServerRequestOpenBranchV2(backing)
713
response = request.execute('feature')
715
request.teardown_jail()
716
expected_format = feature._format.network_name()
717
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
718
('branch', expected_format)),
720
self.assertLength(1, opened_branches)
722
def test_notification_on_branch_from_repository(self):
723
"""When there is a repository, the error should return details."""
724
backing = self.get_transport()
725
request = smart_dir.SmartServerRequestOpenBranchV2(backing)
726
repo = self.make_repository('.')
727
self.assertEqual(smart_req.SmartServerResponse(('nobranch',)),
731
class TestSmartServerRequestOpenBranchV3(TestCaseWithChrootedTransport):
733
def test_no_branch(self):
734
"""When there is no branch, ('nobranch', ) is returned."""
735
backing = self.get_transport()
736
self.make_bzrdir('.')
737
request = smart_dir.SmartServerRequestOpenBranchV3(backing)
738
self.assertEqual(smart_req.SmartServerResponse(('nobranch',)),
741
def test_branch(self):
742
"""When there is a branch, 'ok' is returned."""
743
backing = self.get_transport()
744
expected = self.make_branch('.')._format.network_name()
745
request = smart_dir.SmartServerRequestOpenBranchV3(backing)
746
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
747
('branch', expected)),
750
def test_branch_reference(self):
751
"""When there is a branch reference, the reference URL is returned."""
752
self.vfs_transport_factory = test_server.LocalURLServer
753
backing = self.get_transport()
754
request = smart_dir.SmartServerRequestOpenBranchV3(backing)
755
branch = self.make_branch('branch')
756
checkout = branch.create_checkout('reference',lightweight=True)
757
reference_url = _mod_branch.BranchReferenceFormat().get_reference(
759
self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
760
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
761
('ref', reference_url)),
762
request.execute('reference'))
764
def test_stacked_branch(self):
765
"""Opening a stacked branch does not open the stacked-on branch."""
766
trunk = self.make_branch('trunk')
767
feature = self.make_branch('feature')
768
feature.set_stacked_on_url(trunk.base)
770
_mod_branch.Branch.hooks.install_named_hook(
771
'open', opened_branches.append, None)
772
backing = self.get_transport()
773
request = smart_dir.SmartServerRequestOpenBranchV3(backing)
776
response = request.execute('feature')
778
request.teardown_jail()
779
expected_format = feature._format.network_name()
780
self.assertEqual(smart_req.SuccessfulSmartServerResponse(
781
('branch', expected_format)),
783
self.assertLength(1, opened_branches)
785
def test_notification_on_branch_from_repository(self):
786
"""When there is a repository, the error should return details."""
787
backing = self.get_transport()
788
request = smart_dir.SmartServerRequestOpenBranchV3(backing)
789
repo = self.make_repository('.')
790
self.assertEqual(smart_req.SmartServerResponse(
791
('nobranch', 'location is a repository')),
579
795
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
664
917
# branch.control_files.get('branch.conf') for now - in the future it may
665
918
# perform more complex processing.
666
919
backing = self.get_transport()
667
request = smart.branch.SmartServerBranchGetConfigFile(backing)
920
request = smart_branch.SmartServerBranchGetConfigFile(backing)
668
921
branch = self.make_branch('.')
669
922
branch._transport.put_bytes('branch.conf', 'foo bar baz')
670
self.assertEqual(SmartServerResponse(('ok', ), 'foo bar baz'),
923
self.assertEqual(smart_req.SmartServerResponse(('ok', ), 'foo bar baz'),
671
924
request.execute(''))
674
927
class TestLockedBranch(tests.TestCaseWithMemoryTransport):
676
929
def get_lock_tokens(self, branch):
677
branch_token = branch.lock_write()
678
repo_token = branch.repository.lock_write()
930
branch_token = branch.lock_write().branch_token
931
repo_token = branch.repository.lock_write().repository_token
679
932
branch.repository.unlock()
680
933
return branch_token, repo_token
936
class TestSmartServerBranchRequestPutConfigFile(TestLockedBranch):
938
def test_with_content(self):
939
backing = self.get_transport()
940
request = smart_branch.SmartServerBranchPutConfigFile(backing)
941
branch = self.make_branch('.')
942
branch_token, repo_token = self.get_lock_tokens(branch)
943
self.assertIs(None, request.execute('', branch_token, repo_token))
945
smart_req.SmartServerResponse(('ok', )),
946
request.do_body('foo bar baz'))
948
branch.control_transport.get_bytes('branch.conf'),
683
953
class TestSmartServerBranchRequestSetConfigOption(TestLockedBranch):
685
955
def test_value_name(self):
686
956
branch = self.make_branch('.')
687
request = smart.branch.SmartServerBranchRequestSetConfigOption(
957
request = smart_branch.SmartServerBranchRequestSetConfigOption(
688
958
branch.bzrdir.root_transport)
689
959
branch_token, repo_token = self.get_lock_tokens(branch)
690
960
config = branch._get_config()
691
961
result = request.execute('', branch_token, repo_token, 'bar', 'foo',
693
self.assertEqual(SuccessfulSmartServerResponse(()), result)
963
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
694
964
self.assertEqual('bar', config.get_option('foo'))
698
968
def test_value_name_section(self):
699
969
branch = self.make_branch('.')
700
request = smart.branch.SmartServerBranchRequestSetConfigOption(
970
request = smart_branch.SmartServerBranchRequestSetConfigOption(
701
971
branch.bzrdir.root_transport)
702
972
branch_token, repo_token = self.get_lock_tokens(branch)
703
973
config = branch._get_config()
704
974
result = request.execute('', branch_token, repo_token, 'bar', 'foo',
706
self.assertEqual(SuccessfulSmartServerResponse(()), result)
976
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
707
977
self.assertEqual('bar', config.get_option('foo', 'gam'))
982
class TestSmartServerBranchRequestSetConfigOptionDict(TestLockedBranch):
985
TestLockedBranch.setUp(self)
986
# A dict with non-ascii keys and values to exercise unicode
988
self.encoded_value_dict = (
989
'd5:ascii1:a11:unicode \xe2\x8c\x9a3:\xe2\x80\xbde')
991
'ascii': 'a', u'unicode \N{WATCH}': u'\N{INTERROBANG}'}
993
def test_value_name(self):
994
branch = self.make_branch('.')
995
request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
996
branch.bzrdir.root_transport)
997
branch_token, repo_token = self.get_lock_tokens(branch)
998
config = branch._get_config()
999
result = request.execute('', branch_token, repo_token,
1000
self.encoded_value_dict, 'foo', '')
1001
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
1002
self.assertEqual(self.value_dict, config.get_option('foo'))
1006
def test_value_name_section(self):
1007
branch = self.make_branch('.')
1008
request = smart_branch.SmartServerBranchRequestSetConfigOptionDict(
1009
branch.bzrdir.root_transport)
1010
branch_token, repo_token = self.get_lock_tokens(branch)
1011
config = branch._get_config()
1012
result = request.execute('', branch_token, repo_token,
1013
self.encoded_value_dict, 'foo', 'gam')
1014
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), result)
1015
self.assertEqual(self.value_dict, config.get_option('foo', 'gam'))
712
1020
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
713
1021
# Only called when the branch format and tags match [yay factory
714
1022
# methods] so only need to test straight forward cases.
953
1262
response = self.request.execute(
954
1263
'', branch_token, repo_token, 'child-1', 1, 0)
955
1264
self.assertEqual(
956
SuccessfulSmartServerResponse(('ok', 2, 'child-1')),
1265
smart_req.SuccessfulSmartServerResponse(('ok', 2, 'child-1')),
958
1267
self.unlock_branch()
959
1268
# The branch tip was changed.
960
1269
self.assertEqual('child-1', self.tree.branch.last_revision())
1272
class TestSmartServerBranchBreakLock(tests.TestCaseWithMemoryTransport):
1274
def test_lock_to_break(self):
1275
base_branch = self.make_branch('base')
1276
request = smart_branch.SmartServerBranchBreakLock(
1277
self.get_transport())
1278
base_branch.lock_write()
1280
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1281
request.execute('base'))
1283
def test_nothing_to_break(self):
1284
base_branch = self.make_branch('base')
1285
request = smart_branch.SmartServerBranchBreakLock(
1286
self.get_transport())
1288
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1289
request.execute('base'))
963
1292
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
965
1294
def test_get_parent_none(self):
966
1295
base_branch = self.make_branch('base')
967
request = smart.branch.SmartServerBranchGetParent(self.get_transport())
1296
request = smart_branch.SmartServerBranchGetParent(self.get_transport())
968
1297
response = request.execute('base')
969
1298
self.assertEquals(
970
SuccessfulSmartServerResponse(('',)), response)
1299
smart_req.SuccessfulSmartServerResponse(('',)), response)
972
1301
def test_get_parent_something(self):
973
1302
base_branch = self.make_branch('base')
974
1303
base_branch.set_parent(self.get_url('foo'))
975
request = smart.branch.SmartServerBranchGetParent(self.get_transport())
1304
request = smart_branch.SmartServerBranchGetParent(self.get_transport())
976
1305
response = request.execute('base')
977
1306
self.assertEquals(
978
SuccessfulSmartServerResponse(("../foo",)),
1307
smart_req.SuccessfulSmartServerResponse(("../foo",)),
982
class TestSmartServerBranchRequestSetParent(tests.TestCaseWithMemoryTransport):
1311
class TestSmartServerBranchRequestSetParent(TestLockedBranch):
984
1313
def test_set_parent_none(self):
985
1314
branch = self.make_branch('base', format="1.9")
986
1315
branch.lock_write()
987
1316
branch._set_parent_location('foo')
989
request = smart.branch.SmartServerBranchRequestSetParentLocation(
1318
request = smart_branch.SmartServerBranchRequestSetParentLocation(
990
1319
self.get_transport())
991
branch_token = branch.lock_write()
992
repo_token = branch.repository.lock_write()
1320
branch_token, repo_token = self.get_lock_tokens(branch)
994
1322
response = request.execute('base', branch_token, repo_token, '')
996
branch.repository.unlock()
998
self.assertEqual(SuccessfulSmartServerResponse(()), response)
1325
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1326
# Refresh branch as SetParentLocation modified it
1327
branch = branch.bzrdir.open_branch()
999
1328
self.assertEqual(None, branch.get_parent())
1001
1330
def test_set_parent_something(self):
1002
1331
branch = self.make_branch('base', format="1.9")
1003
request = smart.branch.SmartServerBranchRequestSetParentLocation(
1332
request = smart_branch.SmartServerBranchRequestSetParentLocation(
1004
1333
self.get_transport())
1005
branch_token = branch.lock_write()
1006
repo_token = branch.repository.lock_write()
1334
branch_token, repo_token = self.get_lock_tokens(branch)
1008
1336
response = request.execute('base', branch_token, repo_token,
1011
branch.repository.unlock()
1012
1339
branch.unlock()
1013
self.assertEqual(SuccessfulSmartServerResponse(()), response)
1014
self.assertEqual('http://bar/', branch.get_parent())
1017
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
1340
self.assertEqual(smart_req.SuccessfulSmartServerResponse(()), response)
1341
refreshed = _mod_branch.Branch.open(branch.base)
1342
self.assertEqual('http://bar/', refreshed.get_parent())
1345
class TestSmartServerBranchRequestGetTagsBytes(
1346
tests.TestCaseWithMemoryTransport):
1018
1347
# Only called when the branch format and tags match [yay factory
1019
1348
# methods] so only need to test straight forward cases.
1021
1350
def test_get_bytes(self):
1022
1351
base_branch = self.make_branch('base')
1023
request = smart.branch.SmartServerBranchGetTagsBytes(
1352
request = smart_branch.SmartServerBranchGetTagsBytes(
1024
1353
self.get_transport())
1025
1354
response = request.execute('base')
1026
1355
self.assertEquals(
1027
SuccessfulSmartServerResponse(('',)), response)
1356
smart_req.SuccessfulSmartServerResponse(('',)), response)
1030
1359
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
1219
1561
# its the exact path being looked at and the server is not
1221
1563
backing = self.get_transport()
1222
request = smart.repository.SmartServerRepositoryRequest(backing)
1564
request = smart_repo.SmartServerRepositoryRequest(backing)
1223
1565
self.make_repository('.', shared=True)
1224
1566
self.make_bzrdir('subdir')
1225
1567
self.assertRaises(errors.NoRepositoryPresent,
1226
1568
request.execute, 'subdir')
1571
class TestSmartServerRepositoryAddSignatureText(tests.TestCaseWithMemoryTransport):
1573
def test_add_text(self):
1574
backing = self.get_transport()
1575
request = smart_repo.SmartServerRepositoryAddSignatureText(backing)
1576
tree = self.make_branch_and_memory_tree('.')
1577
write_token = tree.lock_write()
1578
self.addCleanup(tree.unlock)
1580
tree.commit("Message", rev_id='rev1')
1581
tree.branch.repository.start_write_group()
1582
write_group_tokens = tree.branch.repository.suspend_write_group()
1583
self.assertEqual(None, request.execute('', write_token,
1584
'rev1', *write_group_tokens))
1585
response = request.do_body('somesignature')
1586
self.assertTrue(response.is_successful())
1587
self.assertEqual(response.args[0], 'ok')
1588
write_group_tokens = response.args[1:]
1589
tree.branch.repository.resume_write_group(write_group_tokens)
1590
tree.branch.repository.commit_write_group()
1592
self.assertEqual("somesignature",
1593
tree.branch.repository.get_signature_text("rev1"))
1596
class TestSmartServerRepositoryAllRevisionIds(
1597
tests.TestCaseWithMemoryTransport):
1599
def test_empty(self):
1600
"""An empty body should be returned for an empty repository."""
1601
backing = self.get_transport()
1602
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1603
self.make_repository('.')
1605
smart_req.SuccessfulSmartServerResponse(("ok", ), ""),
1606
request.execute(''))
1608
def test_some_revisions(self):
1609
"""An empty body should be returned for an empty repository."""
1610
backing = self.get_transport()
1611
request = smart_repo.SmartServerRepositoryAllRevisionIds(backing)
1612
tree = self.make_branch_and_memory_tree('.')
1615
tree.commit(rev_id='origineel', message="message")
1616
tree.commit(rev_id='nog-een-revisie', message="message")
1619
smart_req.SuccessfulSmartServerResponse(("ok", ),
1620
"origineel\nnog-een-revisie"),
1621
request.execute(''))
1624
class TestSmartServerRepositoryBreakLock(tests.TestCaseWithMemoryTransport):
1626
def test_lock_to_break(self):
1627
backing = self.get_transport()
1628
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1629
tree = self.make_branch_and_memory_tree('.')
1630
tree.branch.repository.lock_write()
1632
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1633
request.execute(''))
1635
def test_nothing_to_break(self):
1636
backing = self.get_transport()
1637
request = smart_repo.SmartServerRepositoryBreakLock(backing)
1638
tree = self.make_branch_and_memory_tree('.')
1640
smart_req.SuccessfulSmartServerResponse(('ok', ), None),
1641
request.execute(''))
1229
1644
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithMemoryTransport):
1231
1646
def test_trivial_bzipped(self):
1232
1647
# This tests that the wire encoding is actually bzipped
1233
1648
backing = self.get_transport()
1234
request = smart.repository.SmartServerRepositoryGetParentMap(backing)
1649
request = smart_repo.SmartServerRepositoryGetParentMap(backing)
1235
1650
tree = self.make_branch_and_memory_tree('.')
1237
1652
self.assertEqual(None,
1238
1653
request.execute('', 'missing-id'))
1239
1654
# Note that it returns a body that is bzipped.
1240
1655
self.assertEqual(
1241
SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
1656
smart_req.SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
1242
1657
request.do_body('\n\n0\n'))
1244
1659
def test_trivial_include_missing(self):
1245
1660
backing = self.get_transport()
1246
request = smart.repository.SmartServerRepositoryGetParentMap(backing)
1661
request = smart_repo.SmartServerRepositoryGetParentMap(backing)
1247
1662
tree = self.make_branch_and_memory_tree('.')
1249
1664
self.assertEqual(None,
1250
1665
request.execute('', 'missing-id', 'include-missing:'))
1251
1666
self.assertEqual(
1252
SuccessfulSmartServerResponse(('ok', ),
1667
smart_req.SuccessfulSmartServerResponse(('ok', ),
1253
1668
bz2.compress('missing:missing-id')),
1254
1669
request.do_body('\n\n0\n'))
1257
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithMemoryTransport):
1672
class TestSmartServerRepositoryGetRevisionGraph(
1673
tests.TestCaseWithMemoryTransport):
1259
1675
def test_none_argument(self):
1260
1676
backing = self.get_transport()
1261
request = smart.repository.SmartServerRepositoryGetRevisionGraph(backing)
1677
request = smart_repo.SmartServerRepositoryGetRevisionGraph(backing)
1262
1678
tree = self.make_branch_and_memory_tree('.')
1263
1679
tree.lock_write()
1409
1885
r1 = tree.commit('a commit', rev_id=rev_id_utf8)
1411
1887
self.assertTrue(tree.branch.repository.has_revision(rev_id_utf8))
1412
self.assertEqual(SmartServerResponse(('yes', )),
1888
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1413
1889
request.execute('', rev_id_utf8))
1892
class TestSmartServerRepositoryIterFilesBytes(tests.TestCaseWithTransport):
1894
def test_single(self):
1895
backing = self.get_transport()
1896
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1897
t = self.make_branch_and_tree('.')
1898
self.addCleanup(t.lock_write().unlock)
1899
self.build_tree_contents([("file", "somecontents")])
1900
t.add(["file"], ["thefileid"])
1901
t.commit(rev_id='somerev', message="add file")
1902
self.assertIs(None, request.execute(''))
1903
response = request.do_body("thefileid\0somerev\n")
1904
self.assertTrue(response.is_successful())
1905
self.assertEquals(response.args, ("ok", ))
1906
self.assertEquals("".join(response.body_stream),
1907
"ok\x000\n" + zlib.compress("somecontents"))
1909
def test_missing(self):
1910
backing = self.get_transport()
1911
request = smart_repo.SmartServerRepositoryIterFilesBytes(backing)
1912
t = self.make_branch_and_tree('.')
1913
self.addCleanup(t.lock_write().unlock)
1914
self.assertIs(None, request.execute(''))
1915
response = request.do_body("thefileid\0revision\n")
1916
self.assertTrue(response.is_successful())
1917
self.assertEquals(response.args, ("ok", ))
1918
self.assertEquals("".join(response.body_stream),
1919
"absent\x00thefileid\x00revision\x000\n")
1922
class TestSmartServerRequestHasSignatureForRevisionId(
1923
tests.TestCaseWithMemoryTransport):
1925
def test_missing_revision(self):
1926
"""For a missing revision, NoSuchRevision is returned."""
1927
backing = self.get_transport()
1928
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1930
self.make_repository('.')
1932
smart_req.FailedSmartServerResponse(
1933
('nosuchrevision', 'revid'), None),
1934
request.execute('', 'revid'))
1936
def test_missing_signature(self):
1937
"""For a missing signature, ('no', ) is returned."""
1938
backing = self.get_transport()
1939
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1941
tree = self.make_branch_and_memory_tree('.')
1944
r1 = tree.commit('a commit', rev_id='A')
1946
self.assertTrue(tree.branch.repository.has_revision('A'))
1947
self.assertEqual(smart_req.SmartServerResponse(('no', )),
1948
request.execute('', 'A'))
1950
def test_present_signature(self):
1951
"""For a present signature, ('yes', ) is returned."""
1952
backing = self.get_transport()
1953
request = smart_repo.SmartServerRequestHasSignatureForRevisionId(
1955
strategy = gpg.LoopbackGPGStrategy(None)
1956
tree = self.make_branch_and_memory_tree('.')
1959
r1 = tree.commit('a commit', rev_id='A')
1960
tree.branch.repository.start_write_group()
1961
tree.branch.repository.sign_revision('A', strategy)
1962
tree.branch.repository.commit_write_group()
1964
self.assertTrue(tree.branch.repository.has_revision('A'))
1965
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1966
request.execute('', 'A'))
1416
1969
class TestSmartServerRepositoryGatherStats(tests.TestCaseWithMemoryTransport):
1418
1971
def test_empty_revid(self):
1419
1972
"""With an empty revid, we get only size an number and revisions"""
1420
1973
backing = self.get_transport()
1421
request = smart.repository.SmartServerRepositoryGatherStats(backing)
1974
request = smart_repo.SmartServerRepositoryGatherStats(backing)
1422
1975
repository = self.make_repository('.')
1423
1976
stats = repository.gather_stats()
1424
1977
expected_body = 'revisions: 0\n'
1425
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
1978
self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
1426
1979
request.execute('', '', 'no'))
1428
1981
def test_revid_with_committers(self):
1429
1982
"""For a revid we get more infos."""
1430
1983
backing = self.get_transport()
1431
1984
rev_id_utf8 = u'\xc8abc'.encode('utf-8')
1432
request = smart.repository.SmartServerRepositoryGatherStats(backing)
1985
request = smart_repo.SmartServerRepositoryGatherStats(backing)
1433
1986
tree = self.make_branch_and_memory_tree('.')
1434
1987
tree.lock_write()
1467
2020
'firstrev: 123456.200 3600\n'
1468
2021
'latestrev: 654321.400 0\n'
1469
2022
'revisions: 2\n')
1470
self.assertEqual(SmartServerResponse(('ok', ), expected_body),
2023
self.assertEqual(smart_req.SmartServerResponse(('ok', ), expected_body),
1471
2024
request.execute('',
1472
2025
rev_id_utf8, 'yes'))
2027
def test_unknown_revid(self):
2028
"""An unknown revision id causes a 'nosuchrevision' error."""
2029
backing = self.get_transport()
2030
request = smart_repo.SmartServerRepositoryGatherStats(backing)
2031
repository = self.make_repository('.')
2032
expected_body = 'revisions: 0\n'
2034
smart_req.FailedSmartServerResponse(
2035
('nosuchrevision', 'mia'), None),
2036
request.execute('', 'mia', 'yes'))
1475
2039
class TestSmartServerRepositoryIsShared(tests.TestCaseWithMemoryTransport):
1477
2041
def test_is_shared(self):
1478
2042
"""For a shared repository, ('yes', ) is returned."""
1479
2043
backing = self.get_transport()
1480
request = smart.repository.SmartServerRepositoryIsShared(backing)
2044
request = smart_repo.SmartServerRepositoryIsShared(backing)
1481
2045
self.make_repository('.', shared=True)
1482
self.assertEqual(SmartServerResponse(('yes', )),
2046
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
1483
2047
request.execute('', ))
1485
2049
def test_is_not_shared(self):
1486
2050
"""For a shared repository, ('no', ) is returned."""
1487
2051
backing = self.get_transport()
1488
request = smart.repository.SmartServerRepositoryIsShared(backing)
2052
request = smart_repo.SmartServerRepositoryIsShared(backing)
1489
2053
self.make_repository('.', shared=False)
1490
self.assertEqual(SmartServerResponse(('no', )),
2054
self.assertEqual(smart_req.SmartServerResponse(('no', )),
2055
request.execute('', ))
2058
class TestSmartServerRepositoryGetRevisionSignatureText(
2059
tests.TestCaseWithMemoryTransport):
2061
def test_get_signature(self):
2062
backing = self.get_transport()
2063
request = smart_repo.SmartServerRepositoryGetRevisionSignatureText(
2065
bb = self.make_branch_builder('.')
2066
bb.build_commit(rev_id='A')
2067
repo = bb.get_branch().repository
2068
strategy = gpg.LoopbackGPGStrategy(None)
2069
self.addCleanup(repo.lock_write().unlock)
2070
repo.start_write_group()
2071
repo.sign_revision('A', strategy)
2072
repo.commit_write_group()
2074
'-----BEGIN PSEUDO-SIGNED CONTENT-----\n' +
2075
Testament.from_revision(repo, 'A').as_short_text() +
2076
'-----END PSEUDO-SIGNED CONTENT-----\n')
2078
smart_req.SmartServerResponse(('ok', ), expected_body),
2079
request.execute('', 'A'))
2082
class TestSmartServerRepositoryMakeWorkingTrees(
2083
tests.TestCaseWithMemoryTransport):
2085
def test_make_working_trees(self):
2086
"""For a repository with working trees, ('yes', ) is returned."""
2087
backing = self.get_transport()
2088
request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2089
r = self.make_repository('.')
2090
r.set_make_working_trees(True)
2091
self.assertEqual(smart_req.SmartServerResponse(('yes', )),
2092
request.execute('', ))
2094
def test_is_not_shared(self):
2095
"""For a repository with working trees, ('no', ) is returned."""
2096
backing = self.get_transport()
2097
request = smart_repo.SmartServerRepositoryMakeWorkingTrees(backing)
2098
r = self.make_repository('.')
2099
r.set_make_working_trees(False)
2100
self.assertEqual(smart_req.SmartServerResponse(('no', )),
1491
2101
request.execute('', ))
1604
2211
def test_unlock_on_unlocked_repo(self):
1605
2212
backing = self.get_transport()
1606
request = smart.repository.SmartServerRepositoryUnlock(backing)
2213
request = smart_repo.SmartServerRepositoryUnlock(backing)
1607
2214
repository = self.make_repository('.', format='knit')
1608
2215
response = request.execute('', 'some token')
1609
2216
self.assertEqual(
1610
SmartServerResponse(('TokenMismatch',)), response)
2217
smart_req.SmartServerResponse(('TokenMismatch',)), response)
2220
class TestSmartServerRepositoryGetPhysicalLockStatus(
2221
tests.TestCaseWithTransport):
2223
def test_with_write_lock(self):
2224
backing = self.get_transport()
2225
repo = self.make_repository('.')
2226
self.addCleanup(repo.lock_write().unlock)
2227
# lock_write() doesn't necessarily actually take a physical
2229
if repo.get_physical_lock_status():
2233
request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2234
request = request_class(backing)
2235
self.assertEqual(smart_req.SuccessfulSmartServerResponse((expected,)),
2236
request.execute('', ))
2238
def test_without_write_lock(self):
2239
backing = self.get_transport()
2240
repo = self.make_repository('.')
2241
self.assertEquals(False, repo.get_physical_lock_status())
2242
request_class = smart_repo.SmartServerRepositoryGetPhysicalLockStatus
2243
request = request_class(backing)
2244
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('no',)),
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))
1613
2264
class TestSmartServerIsReadonly(tests.TestCaseWithMemoryTransport):
1615
2266
def test_is_readonly_no(self):
1616
2267
backing = self.get_transport()
1617
request = smart.request.SmartServerIsReadonly(backing)
2268
request = smart_req.SmartServerIsReadonly(backing)
1618
2269
response = request.execute()
1619
2270
self.assertEqual(
1620
SmartServerResponse(('no',)), response)
2271
smart_req.SmartServerResponse(('no',)), response)
1622
2273
def test_is_readonly_yes(self):
1623
2274
backing = self.get_readonly_transport()
1624
request = smart.request.SmartServerIsReadonly(backing)
2275
request = smart_req.SmartServerIsReadonly(backing)
1625
2276
response = request.execute()
1626
2277
self.assertEqual(
1627
SmartServerResponse(('yes',)), response)
1630
class TestSmartServerRepositorySetMakeWorkingTrees(tests.TestCaseWithMemoryTransport):
2278
smart_req.SmartServerResponse(('yes',)), response)
2281
class TestSmartServerRepositorySetMakeWorkingTrees(
2282
tests.TestCaseWithMemoryTransport):
1632
2284
def test_set_false(self):
1633
2285
backing = self.get_transport()
1634
2286
repo = self.make_repository('.', shared=True)
1635
2287
repo.set_make_working_trees(True)
1636
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
2288
request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
1637
2289
request = request_class(backing)
1638
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
2290
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
1639
2291
request.execute('', 'False'))
1640
2292
repo = repo.bzrdir.open_repository()
1641
2293
self.assertFalse(repo.make_working_trees())
1644
2296
backing = self.get_transport()
1645
2297
repo = self.make_repository('.', shared=True)
1646
2298
repo.set_make_working_trees(False)
1647
request_class = smart.repository.SmartServerRepositorySetMakeWorkingTrees
2299
request_class = smart_repo.SmartServerRepositorySetMakeWorkingTrees
1648
2300
request = request_class(backing)
1649
self.assertEqual(SuccessfulSmartServerResponse(('ok',)),
2301
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
1650
2302
request.execute('', 'True'))
1651
2303
repo = repo.bzrdir.open_repository()
1652
2304
self.assertTrue(repo.make_working_trees())
2307
class TestSmartServerRepositoryGetSerializerFormat(
2308
tests.TestCaseWithMemoryTransport):
2310
def test_get_serializer_format(self):
2311
backing = self.get_transport()
2312
repo = self.make_repository('.', format='2a')
2313
request_class = smart_repo.SmartServerRepositoryGetSerializerFormat
2314
request = request_class(backing)
2316
smart_req.SuccessfulSmartServerResponse(('ok', '10')),
2317
request.execute(''))
2320
class TestSmartServerRepositoryWriteGroup(
2321
tests.TestCaseWithMemoryTransport):
2323
def test_start_write_group(self):
2324
backing = self.get_transport()
2325
repo = self.make_repository('.')
2326
lock_token = repo.lock_write().repository_token
2327
self.addCleanup(repo.unlock)
2328
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2329
request = request_class(backing)
2330
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok', [])),
2331
request.execute('', lock_token))
2333
def test_start_write_group_unsuspendable(self):
2334
backing = self.get_transport()
2335
repo = self.make_repository('.', format='knit')
2336
lock_token = repo.lock_write().repository_token
2337
self.addCleanup(repo.unlock)
2338
request_class = smart_repo.SmartServerRepositoryStartWriteGroup
2339
request = request_class(backing)
2341
smart_req.FailedSmartServerResponse(('UnsuspendableWriteGroup',)),
2342
request.execute('', lock_token))
2344
def test_commit_write_group(self):
2345
backing = self.get_transport()
2346
repo = self.make_repository('.')
2347
lock_token = repo.lock_write().repository_token
2348
self.addCleanup(repo.unlock)
2349
repo.start_write_group()
2350
tokens = repo.suspend_write_group()
2351
request_class = smart_repo.SmartServerRepositoryCommitWriteGroup
2352
request = request_class(backing)
2353
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2354
request.execute('', lock_token, tokens))
2356
def test_abort_write_group(self):
2357
backing = self.get_transport()
2358
repo = self.make_repository('.')
2359
lock_token = repo.lock_write().repository_token
2360
repo.start_write_group()
2361
tokens = repo.suspend_write_group()
2362
self.addCleanup(repo.unlock)
2363
request_class = smart_repo.SmartServerRepositoryAbortWriteGroup
2364
request = request_class(backing)
2365
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2366
request.execute('', lock_token, tokens))
2368
def test_check_write_group(self):
2369
backing = self.get_transport()
2370
repo = self.make_repository('.')
2371
lock_token = repo.lock_write().repository_token
2372
repo.start_write_group()
2373
tokens = repo.suspend_write_group()
2374
self.addCleanup(repo.unlock)
2375
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2376
request = request_class(backing)
2377
self.assertEqual(smart_req.SuccessfulSmartServerResponse(('ok',)),
2378
request.execute('', lock_token, tokens))
2380
def test_check_write_group_invalid(self):
2381
backing = self.get_transport()
2382
repo = self.make_repository('.')
2383
lock_token = repo.lock_write().repository_token
2384
self.addCleanup(repo.unlock)
2385
request_class = smart_repo.SmartServerRepositoryCheckWriteGroup
2386
request = request_class(backing)
2387
self.assertEqual(smart_req.FailedSmartServerResponse(
2388
('UnresumableWriteGroup', ['random'],
2389
'Malformed write group token')),
2390
request.execute('', lock_token, ["random"]))
1655
2393
class TestSmartServerPackRepositoryAutopack(tests.TestCaseWithTransport):
1657
2395
def make_repo_needing_autopacking(self, path='.'):
1723
2461
"""All registered request_handlers can be found."""
1724
2462
# If there's a typo in a register_lazy call, this loop will fail with
1725
2463
# an AttributeError.
1726
for key, item in smart.request.request_handlers.iteritems():
2464
for key in smart_req.request_handlers.keys():
2466
item = smart_req.request_handlers.get(key)
2467
except AttributeError, e:
2468
raise AttributeError('failed to get %s: %s' % (key, e))
1729
2470
def assertHandlerEqual(self, verb, handler):
1730
self.assertEqual(smart.request.request_handlers.get(verb), handler)
2471
self.assertEqual(smart_req.request_handlers.get(verb), handler)
1732
2473
def test_registered_methods(self):
1733
2474
"""Test that known methods are registered to the correct object."""
2475
self.assertHandlerEqual('Branch.break_lock',
2476
smart_branch.SmartServerBranchBreakLock)
1734
2477
self.assertHandlerEqual('Branch.get_config_file',
1735
smart.branch.SmartServerBranchGetConfigFile)
2478
smart_branch.SmartServerBranchGetConfigFile)
2479
self.assertHandlerEqual('Branch.put_config_file',
2480
smart_branch.SmartServerBranchPutConfigFile)
1736
2481
self.assertHandlerEqual('Branch.get_parent',
1737
smart.branch.SmartServerBranchGetParent)
2482
smart_branch.SmartServerBranchGetParent)
2483
self.assertHandlerEqual('Branch.get_physical_lock_status',
2484
smart_branch.SmartServerBranchRequestGetPhysicalLockStatus)
1738
2485
self.assertHandlerEqual('Branch.get_tags_bytes',
1739
smart.branch.SmartServerBranchGetTagsBytes)
2486
smart_branch.SmartServerBranchGetTagsBytes)
1740
2487
self.assertHandlerEqual('Branch.lock_write',
1741
smart.branch.SmartServerBranchRequestLockWrite)
2488
smart_branch.SmartServerBranchRequestLockWrite)
1742
2489
self.assertHandlerEqual('Branch.last_revision_info',
1743
smart.branch.SmartServerBranchRequestLastRevisionInfo)
2490
smart_branch.SmartServerBranchRequestLastRevisionInfo)
1744
2491
self.assertHandlerEqual('Branch.revision_history',
1745
smart.branch.SmartServerRequestRevisionHistory)
2492
smart_branch.SmartServerRequestRevisionHistory)
2493
self.assertHandlerEqual('Branch.revision_id_to_revno',
2494
smart_branch.SmartServerBranchRequestRevisionIdToRevno)
1746
2495
self.assertHandlerEqual('Branch.set_config_option',
1747
smart.branch.SmartServerBranchRequestSetConfigOption)
2496
smart_branch.SmartServerBranchRequestSetConfigOption)
1748
2497
self.assertHandlerEqual('Branch.set_last_revision',
1749
smart.branch.SmartServerBranchRequestSetLastRevision)
2498
smart_branch.SmartServerBranchRequestSetLastRevision)
1750
2499
self.assertHandlerEqual('Branch.set_last_revision_info',
1751
smart.branch.SmartServerBranchRequestSetLastRevisionInfo)
2500
smart_branch.SmartServerBranchRequestSetLastRevisionInfo)
1752
2501
self.assertHandlerEqual('Branch.set_last_revision_ex',
1753
smart.branch.SmartServerBranchRequestSetLastRevisionEx)
2502
smart_branch.SmartServerBranchRequestSetLastRevisionEx)
1754
2503
self.assertHandlerEqual('Branch.set_parent_location',
1755
smart.branch.SmartServerBranchRequestSetParentLocation)
2504
smart_branch.SmartServerBranchRequestSetParentLocation)
1756
2505
self.assertHandlerEqual('Branch.unlock',
1757
smart.branch.SmartServerBranchRequestUnlock)
2506
smart_branch.SmartServerBranchRequestUnlock)
2507
self.assertHandlerEqual('BzrDir.destroy_branch',
2508
smart_dir.SmartServerBzrDirRequestDestroyBranch)
1758
2509
self.assertHandlerEqual('BzrDir.find_repository',
1759
smart.bzrdir.SmartServerRequestFindRepositoryV1)
2510
smart_dir.SmartServerRequestFindRepositoryV1)
1760
2511
self.assertHandlerEqual('BzrDir.find_repositoryV2',
1761
smart.bzrdir.SmartServerRequestFindRepositoryV2)
2512
smart_dir.SmartServerRequestFindRepositoryV2)
1762
2513
self.assertHandlerEqual('BzrDirFormat.initialize',
1763
smart.bzrdir.SmartServerRequestInitializeBzrDir)
2514
smart_dir.SmartServerRequestInitializeBzrDir)
1764
2515
self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
1765
smart.bzrdir.SmartServerRequestBzrDirInitializeEx)
2516
smart_dir.SmartServerRequestBzrDirInitializeEx)
2517
self.assertHandlerEqual('BzrDir.checkout_metadir',
2518
smart_dir.SmartServerBzrDirRequestCheckoutMetaDir)
1766
2519
self.assertHandlerEqual('BzrDir.cloning_metadir',
1767
smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
2520
smart_dir.SmartServerBzrDirRequestCloningMetaDir)
2521
self.assertHandlerEqual('BzrDir.get_branches',
2522
smart_dir.SmartServerBzrDirRequestGetBranches)
1768
2523
self.assertHandlerEqual('BzrDir.get_config_file',
1769
smart.bzrdir.SmartServerBzrDirRequestConfigFile)
2524
smart_dir.SmartServerBzrDirRequestConfigFile)
1770
2525
self.assertHandlerEqual('BzrDir.open_branch',
1771
smart.bzrdir.SmartServerRequestOpenBranch)
2526
smart_dir.SmartServerRequestOpenBranch)
1772
2527
self.assertHandlerEqual('BzrDir.open_branchV2',
1773
smart.bzrdir.SmartServerRequestOpenBranchV2)
2528
smart_dir.SmartServerRequestOpenBranchV2)
2529
self.assertHandlerEqual('BzrDir.open_branchV3',
2530
smart_dir.SmartServerRequestOpenBranchV3)
1774
2531
self.assertHandlerEqual('PackRepository.autopack',
1775
smart.packrepository.SmartServerPackRepositoryAutopack)
2532
smart_packrepo.SmartServerPackRepositoryAutopack)
2533
self.assertHandlerEqual('Repository.add_signature_text',
2534
smart_repo.SmartServerRepositoryAddSignatureText)
2535
self.assertHandlerEqual('Repository.all_revision_ids',
2536
smart_repo.SmartServerRepositoryAllRevisionIds)
2537
self.assertHandlerEqual('Repository.break_lock',
2538
smart_repo.SmartServerRepositoryBreakLock)
1776
2539
self.assertHandlerEqual('Repository.gather_stats',
1777
smart.repository.SmartServerRepositoryGatherStats)
2540
smart_repo.SmartServerRepositoryGatherStats)
1778
2541
self.assertHandlerEqual('Repository.get_parent_map',
1779
smart.repository.SmartServerRepositoryGetParentMap)
2542
smart_repo.SmartServerRepositoryGetParentMap)
2543
self.assertHandlerEqual('Repository.get_physical_lock_status',
2544
smart_repo.SmartServerRepositoryGetPhysicalLockStatus)
1780
2545
self.assertHandlerEqual('Repository.get_rev_id_for_revno',
1781
smart.repository.SmartServerRepositoryGetRevIdForRevno)
2546
smart_repo.SmartServerRepositoryGetRevIdForRevno)
1782
2547
self.assertHandlerEqual('Repository.get_revision_graph',
1783
smart.repository.SmartServerRepositoryGetRevisionGraph)
2548
smart_repo.SmartServerRepositoryGetRevisionGraph)
2549
self.assertHandlerEqual('Repository.get_revision_signature_text',
2550
smart_repo.SmartServerRepositoryGetRevisionSignatureText)
1784
2551
self.assertHandlerEqual('Repository.get_stream',
1785
smart.repository.SmartServerRepositoryGetStream)
2552
smart_repo.SmartServerRepositoryGetStream)
2553
self.assertHandlerEqual('Repository.get_stream_1.19',
2554
smart_repo.SmartServerRepositoryGetStream_1_19)
2555
self.assertHandlerEqual('Repository.iter_revisions',
2556
smart_repo.SmartServerRepositoryIterRevisions)
1786
2557
self.assertHandlerEqual('Repository.has_revision',
1787
smart.repository.SmartServerRequestHasRevision)
2558
smart_repo.SmartServerRequestHasRevision)
1788
2559
self.assertHandlerEqual('Repository.insert_stream',
1789
smart.repository.SmartServerRepositoryInsertStream)
2560
smart_repo.SmartServerRepositoryInsertStream)
1790
2561
self.assertHandlerEqual('Repository.insert_stream_locked',
1791
smart.repository.SmartServerRepositoryInsertStreamLocked)
2562
smart_repo.SmartServerRepositoryInsertStreamLocked)
1792
2563
self.assertHandlerEqual('Repository.is_shared',
1793
smart.repository.SmartServerRepositoryIsShared)
2564
smart_repo.SmartServerRepositoryIsShared)
2565
self.assertHandlerEqual('Repository.iter_files_bytes',
2566
smart_repo.SmartServerRepositoryIterFilesBytes)
1794
2567
self.assertHandlerEqual('Repository.lock_write',
1795
smart.repository.SmartServerRepositoryLockWrite)
2568
smart_repo.SmartServerRepositoryLockWrite)
2569
self.assertHandlerEqual('Repository.make_working_trees',
2570
smart_repo.SmartServerRepositoryMakeWorkingTrees)
2571
self.assertHandlerEqual('Repository.pack',
2572
smart_repo.SmartServerRepositoryPack)
2573
self.assertHandlerEqual('Repository.reconcile',
2574
smart_repo.SmartServerRepositoryReconcile)
1796
2575
self.assertHandlerEqual('Repository.tarball',
1797
smart.repository.SmartServerRepositoryTarball)
2576
smart_repo.SmartServerRepositoryTarball)
1798
2577
self.assertHandlerEqual('Repository.unlock',
1799
smart.repository.SmartServerRepositoryUnlock)
2578
smart_repo.SmartServerRepositoryUnlock)
2579
self.assertHandlerEqual('Repository.start_write_group',
2580
smart_repo.SmartServerRepositoryStartWriteGroup)
2581
self.assertHandlerEqual('Repository.check_write_group',
2582
smart_repo.SmartServerRepositoryCheckWriteGroup)
2583
self.assertHandlerEqual('Repository.commit_write_group',
2584
smart_repo.SmartServerRepositoryCommitWriteGroup)
2585
self.assertHandlerEqual('Repository.abort_write_group',
2586
smart_repo.SmartServerRepositoryAbortWriteGroup)
2587
self.assertHandlerEqual('VersionedFileRepository.get_serializer_format',
2588
smart_repo.SmartServerRepositoryGetSerializerFormat)
2589
self.assertHandlerEqual('VersionedFileRepository.get_inventories',
2590
smart_repo.SmartServerRepositoryGetInventories)
1800
2591
self.assertHandlerEqual('Transport.is_readonly',
1801
smart.request.SmartServerIsReadonly)
2592
smart_req.SmartServerIsReadonly)
2595
class SmartTCPServerHookTests(tests.TestCaseWithMemoryTransport):
2596
"""Tests for SmartTCPServer hooks."""
2599
super(SmartTCPServerHookTests, self).setUp()
2600
self.server = server.SmartTCPServer(self.get_transport())
2602
def test_run_server_started_hooks(self):
2603
"""Test the server started hooks get fired properly."""
2605
server.SmartTCPServer.hooks.install_named_hook('server_started',
2606
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2608
started_ex_calls = []
2609
server.SmartTCPServer.hooks.install_named_hook('server_started_ex',
2610
lambda backing_urls, url: started_ex_calls.append((backing_urls, url)),
2612
self.server._sockname = ('example.com', 42)
2613
self.server.run_server_started_hooks()
2614
self.assertEquals(started_calls,
2615
[([self.get_transport().base], 'bzr://example.com:42/')])
2616
self.assertEquals(started_ex_calls,
2617
[([self.get_transport().base], self.server)])
2619
def test_run_server_started_hooks_ipv6(self):
2620
"""Test that socknames can contain 4-tuples."""
2621
self.server._sockname = ('::', 42, 0, 0)
2623
server.SmartTCPServer.hooks.install_named_hook('server_started',
2624
lambda backing_urls, url: started_calls.append((backing_urls, url)),
2626
self.server.run_server_started_hooks()
2627
self.assertEquals(started_calls,
2628
[([self.get_transport().base], 'bzr://:::42/')])
2630
def test_run_server_stopped_hooks(self):
2631
"""Test the server stopped hooks."""
2632
self.server._sockname = ('example.com', 42)
2634
server.SmartTCPServer.hooks.install_named_hook('server_stopped',
2635
lambda backing_urls, url: stopped_calls.append((backing_urls, url)),
2637
self.server.run_server_stopped_hooks()
2638
self.assertEquals(stopped_calls,
2639
[([self.get_transport().base], 'bzr://example.com:42/')])
2642
class TestSmartServerRepositoryPack(tests.TestCaseWithMemoryTransport):
2644
def test_pack(self):
2645
backing = self.get_transport()
2646
request = smart_repo.SmartServerRepositoryPack(backing)
2647
tree = self.make_branch_and_memory_tree('.')
2648
repo_token = tree.branch.repository.lock_write().repository_token
2650
self.assertIs(None, request.execute('', repo_token, False))
2653
smart_req.SuccessfulSmartServerResponse(('ok', ), ),
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")