/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Robert Collins
  • Date: 2009-03-10 00:35:11 UTC
  • mfrom: (4098 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4102.
  • Revision ID: robertc@robertcollins.net-20090310003511-pvtygbimxywwton0
Merge bzr.dev, commands.py was conflicting.

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
    SuccessfulSmartServerResponse,
49
49
    )
50
50
from bzrlib.tests import (
51
 
    iter_suite_tests,
52
51
    split_suite_by_re,
53
 
    TestScenarioApplier,
54
52
    )
55
53
from bzrlib.transport import chroot, get_transport
56
54
from bzrlib.util import bencode
60
58
    """Multiply tests version and protocol consistency."""
61
59
    # FindRepository tests.
62
60
    bzrdir_mod = bzrlib.smart.bzrdir
63
 
    applier = TestScenarioApplier()
64
 
    applier.scenarios = [
 
61
    scenarios = [
65
62
        ("find_repository", {
66
63
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}),
67
64
        ("find_repositoryV2", {
73
70
        "TestSmartServerRequestFindRepository")
74
71
    v2_only, v1_and_2 = split_suite_by_re(to_adapt,
75
72
        "_v2")
76
 
    for test in iter_suite_tests(v1_and_2):
77
 
        result.addTests(applier.adapt(test))
78
 
    del applier.scenarios[0]
79
 
    for test in iter_suite_tests(v2_only):
80
 
        result.addTests(applier.adapt(test))
 
73
    tests.multiply_tests(v1_and_2, scenarios, result)
 
74
    # The first scenario is only applicable to v1 protocols, it is deleted
 
75
    # since.
 
76
    tests.multiply_tests(v2_only, scenarios[1:], result)
81
77
    return result
82
78
 
83
79
 
177
173
        expected = SuccessfulSmartServerResponse(
178
174
            (local_result.network_name(),
179
175
            local_result.repository_format.network_name(),
180
 
            ('direct', local_result.get_branch_format().network_name())))
 
176
            ('branch', local_result.get_branch_format().network_name())))
181
177
        self.assertEqual(expected, request.execute('', 'False'))
182
178
 
183
179
    def test_cloning_metadir_reference(self):
196
192
        expected = SuccessfulSmartServerResponse(
197
193
            (local_result.network_name(),
198
194
            local_result.repository_format.network_name(),
199
 
            ('reference', reference_url)))
 
195
            ('ref', reference_url)))
200
196
        self.assertEqual(expected, request.execute('', 'False'))
201
197
 
202
198
 
364
360
            request.execute('reference'))
365
361
 
366
362
 
 
363
class TestSmartServerRequestOpenBranchV2(TestCaseWithChrootedTransport):
 
364
 
 
365
    def test_no_branch(self):
 
366
        """When there is no branch, ('nobranch', ) is returned."""
 
367
        backing = self.get_transport()
 
368
        self.make_bzrdir('.')
 
369
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
 
370
        self.assertEqual(SmartServerResponse(('nobranch', )),
 
371
            request.execute(''))
 
372
 
 
373
    def test_branch(self):
 
374
        """When there is a branch, 'ok' is returned."""
 
375
        backing = self.get_transport()
 
376
        expected = self.make_branch('.')._format.network_name()
 
377
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
 
378
        self.assertEqual(SuccessfulSmartServerResponse(('branch', expected)),
 
379
            request.execute(''))
 
380
 
 
381
    def test_branch_reference(self):
 
382
        """When there is a branch reference, the reference URL is returned."""
 
383
        backing = self.get_transport()
 
384
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
 
385
        branch = self.make_branch('branch')
 
386
        checkout = branch.create_checkout('reference',lightweight=True)
 
387
        reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
 
388
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
 
389
        self.assertEqual(SuccessfulSmartServerResponse(('ref', reference_url)),
 
390
            request.execute('reference'))
 
391
 
 
392
 
367
393
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
368
394
 
369
395
    def test_empty(self):
696
722
            response)
697
723
 
698
724
 
 
725
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
 
726
# Only called when the branch format and tags match [yay factory
 
727
# methods] so only need to test straight forward cases.
 
728
 
 
729
    def test_get_bytes(self):
 
730
        base_branch = self.make_branch('base')
 
731
        request = smart.branch.SmartServerBranchGetTagsBytes(
 
732
            self.get_transport())
 
733
        response = request.execute('base')
 
734
        self.assertEquals(
 
735
            SuccessfulSmartServerResponse(('',)), response)
 
736
 
 
737
 
699
738
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
700
739
 
701
740
    def test_get_stacked_on_url(self):
931
970
            request.execute('', 'missingrevision'))
932
971
 
933
972
 
 
973
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
 
974
 
 
975
    def make_two_commit_repo(self):
 
976
        tree = self.make_branch_and_memory_tree('.')
 
977
        tree.lock_write()
 
978
        tree.add('')
 
979
        r1 = tree.commit('1st commit')
 
980
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
 
981
        tree.unlock()
 
982
        repo = tree.branch.repository
 
983
        return repo, r1, r2
 
984
 
 
985
    def test_ancestry_of(self):
 
986
        """The search argument may be a 'ancestry-of' some heads'."""
 
987
        backing = self.get_transport()
 
988
        request = smart.repository.SmartServerRepositoryGetStream(backing)
 
989
        repo, r1, r2 = self.make_two_commit_repo()
 
990
        fetch_spec = ['ancestry-of', r2]
 
991
        lines = '\n'.join(fetch_spec)
 
992
        request.execute('', repo._format.network_name())
 
993
        response = request.do_body(lines)
 
994
        self.assertEqual(('ok',), response.args)
 
995
        stream_bytes = ''.join(response.body_stream)
 
996
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
 
997
 
 
998
    def test_search(self):
 
999
        """The search argument may be a 'search' of some explicit keys."""
 
1000
        backing = self.get_transport()
 
1001
        request = smart.repository.SmartServerRepositoryGetStream(backing)
 
1002
        repo, r1, r2 = self.make_two_commit_repo()
 
1003
        fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
 
1004
        lines = '\n'.join(fetch_spec)
 
1005
        request.execute('', repo._format.network_name())
 
1006
        response = request.do_body(lines)
 
1007
        self.assertEqual(('ok',), response.args)
 
1008
        stream_bytes = ''.join(response.body_stream)
 
1009
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
 
1010
 
 
1011
 
934
1012
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
935
1013
 
936
1014
    def test_missing_revision(self):
1209
1287
            smart.request.request_handlers.get('Branch.get_parent'),
1210
1288
            smart.branch.SmartServerBranchGetParent)
1211
1289
        self.assertEqual(
 
1290
            smart.request.request_handlers.get('Branch.get_tags_bytes'),
 
1291
            smart.branch.SmartServerBranchGetTagsBytes)
 
1292
        self.assertEqual(
1212
1293
            smart.request.request_handlers.get('Branch.lock_write'),
1213
1294
            smart.branch.SmartServerBranchRequestLockWrite)
1214
1295
        self.assertEqual(
1242
1323
            smart.request.request_handlers.get('BzrDir.open_branch'),
1243
1324
            smart.bzrdir.SmartServerRequestOpenBranch)
1244
1325
        self.assertEqual(
 
1326
            smart.request.request_handlers.get('BzrDir.open_branchV2'),
 
1327
            smart.bzrdir.SmartServerRequestOpenBranchV2)
 
1328
        self.assertEqual(
1245
1329
            smart.request.request_handlers.get('PackRepository.autopack'),
1246
1330
            smart.packrepository.SmartServerPackRepositoryAutopack)
1247
1331
        self.assertEqual(