/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: Jelmer Vernooij
  • Date: 2009-03-12 14:02:53 UTC
  • mfrom: (4135 +trunk)
  • mto: This revision was merged to the branch mainline in revision 4137.
  • Revision ID: jelmer@samba.org-20090312140253-bmldbzlmsitfdrzf
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
    )
39
39
from bzrlib.branch import Branch, BranchReferenceFormat
40
40
import bzrlib.smart.branch
41
 
import bzrlib.smart.bzrdir
 
41
import bzrlib.smart.bzrdir, bzrlib.smart.bzrdir as smart_dir
 
42
import bzrlib.smart.packrepository
42
43
import bzrlib.smart.repository
43
44
from bzrlib.smart.request import (
44
45
    FailedSmartServerResponse,
47
48
    SuccessfulSmartServerResponse,
48
49
    )
49
50
from bzrlib.tests import (
50
 
    iter_suite_tests,
51
51
    split_suite_by_re,
52
 
    TestScenarioApplier,
53
52
    )
54
53
from bzrlib.transport import chroot, get_transport
55
54
from bzrlib.util import bencode
59
58
    """Multiply tests version and protocol consistency."""
60
59
    # FindRepository tests.
61
60
    bzrdir_mod = bzrlib.smart.bzrdir
62
 
    applier = TestScenarioApplier()
63
 
    applier.scenarios = [
 
61
    scenarios = [
64
62
        ("find_repository", {
65
63
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV1}),
66
64
        ("find_repositoryV2", {
67
65
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV2}),
 
66
        ("find_repositoryV3", {
 
67
            "_request_class":bzrdir_mod.SmartServerRequestFindRepositoryV3}),
68
68
        ]
69
69
    to_adapt, result = split_suite_by_re(standard_tests,
70
70
        "TestSmartServerRequestFindRepository")
71
71
    v2_only, v1_and_2 = split_suite_by_re(to_adapt,
72
72
        "_v2")
73
 
    for test in iter_suite_tests(v1_and_2):
74
 
        result.addTests(applier.adapt(test))
75
 
    del applier.scenarios[0]
76
 
    for test in iter_suite_tests(v2_only):
77
 
        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)
78
77
    return result
79
78
 
80
79
 
160
159
            request.transport_from_client_path('foo/').base)
161
160
 
162
161
 
 
162
class TestSmartServerBzrDirRequestCloningMetaDir(
 
163
    tests.TestCaseWithMemoryTransport):
 
164
    """Tests for BzrDir.cloning_metadir."""
 
165
 
 
166
    def test_cloning_metadir(self):
 
167
        """When there is a bzrdir present, the call succeeds."""
 
168
        backing = self.get_transport()
 
169
        dir = self.make_bzrdir('.')
 
170
        local_result = dir.cloning_metadir()
 
171
        request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
 
172
        request = request_class(backing)
 
173
        expected = SuccessfulSmartServerResponse(
 
174
            (local_result.network_name(),
 
175
            local_result.repository_format.network_name(),
 
176
            ('branch', local_result.get_branch_format().network_name())))
 
177
        self.assertEqual(expected, request.execute('', 'False'))
 
178
 
 
179
    def test_cloning_metadir_reference(self):
 
180
        """The request works when bzrdir contains a branch reference."""
 
181
        backing = self.get_transport()
 
182
        referenced_branch = self.make_branch('referenced')
 
183
        dir = self.make_bzrdir('.')
 
184
        local_result = dir.cloning_metadir()
 
185
        reference = BranchReferenceFormat().initialize(dir, referenced_branch)
 
186
        reference_url = BranchReferenceFormat().get_reference(dir)
 
187
        # The server shouldn't try to follow the branch reference, so it's fine
 
188
        # if the referenced branch isn't reachable.
 
189
        backing.rename('referenced', 'moved')
 
190
        request_class = smart_dir.SmartServerBzrDirRequestCloningMetaDir
 
191
        request = request_class(backing)
 
192
        expected = SuccessfulSmartServerResponse(
 
193
            (local_result.network_name(),
 
194
            local_result.repository_format.network_name(),
 
195
            ('ref', reference_url)))
 
196
        self.assertEqual(expected, request.execute('', 'False'))
 
197
 
 
198
 
163
199
class TestSmartServerRequestCreateRepository(tests.TestCaseWithMemoryTransport):
164
200
    """Tests for BzrDir.create_repository."""
165
201
 
214
250
            subtrees = 'yes'
215
251
        else:
216
252
            subtrees = 'no'
217
 
        if (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
 
253
        if (smart.bzrdir.SmartServerRequestFindRepositoryV3 ==
 
254
            self._request_class):
 
255
            return SuccessfulSmartServerResponse(
 
256
                ('ok', '', rich_root, subtrees, 'no',
 
257
                 repo._format.network_name()))
 
258
        elif (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
218
259
            self._request_class):
219
260
            # All tests so far are on formats, and for non-external
220
261
            # repositories.
319
360
            request.execute('reference'))
320
361
 
321
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
 
322
393
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
323
394
 
324
395
    def test_empty(self):
632
703
        self.assertEqual('child-1', self.tree.branch.last_revision())
633
704
 
634
705
 
 
706
class TestSmartServerBranchRequestGetParent(tests.TestCaseWithMemoryTransport):
 
707
 
 
708
    def test_get_parent_none(self):
 
709
        base_branch = self.make_branch('base')
 
710
        request = smart.branch.SmartServerBranchGetParent(self.get_transport())
 
711
        response = request.execute('base')
 
712
        self.assertEquals(
 
713
            SuccessfulSmartServerResponse(('',)), response)
 
714
 
 
715
    def test_get_parent_something(self):
 
716
        base_branch = self.make_branch('base')
 
717
        base_branch.set_parent(self.get_url('foo'))
 
718
        request = smart.branch.SmartServerBranchGetParent(self.get_transport())
 
719
        response = request.execute('base')
 
720
        self.assertEquals(
 
721
            SuccessfulSmartServerResponse(("../foo",)),
 
722
            response)
 
723
 
 
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
 
635
738
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
636
739
 
637
740
    def test_get_stacked_on_url(self):
867
970
            request.execute('', 'missingrevision'))
868
971
 
869
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
 
870
1012
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
871
1013
 
872
1014
    def test_missing_revision(self):
1142
1284
            smart.request.request_handlers.get('Branch.get_config_file'),
1143
1285
            smart.branch.SmartServerBranchGetConfigFile)
1144
1286
        self.assertEqual(
 
1287
            smart.request.request_handlers.get('Branch.get_parent'),
 
1288
            smart.branch.SmartServerBranchGetParent)
 
1289
        self.assertEqual(
 
1290
            smart.request.request_handlers.get('Branch.get_tags_bytes'),
 
1291
            smart.branch.SmartServerBranchGetTagsBytes)
 
1292
        self.assertEqual(
1145
1293
            smart.request.request_handlers.get('Branch.lock_write'),
1146
1294
            smart.branch.SmartServerBranchRequestLockWrite)
1147
1295
        self.assertEqual(
1169
1317
            smart.request.request_handlers.get('BzrDirFormat.initialize'),
1170
1318
            smart.bzrdir.SmartServerRequestInitializeBzrDir)
1171
1319
        self.assertEqual(
 
1320
            smart.request.request_handlers.get('BzrDir.cloning_metadir'),
 
1321
            smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
 
1322
        self.assertEqual(
1172
1323
            smart.request.request_handlers.get('BzrDir.open_branch'),
1173
1324
            smart.bzrdir.SmartServerRequestOpenBranch)
1174
1325
        self.assertEqual(
 
1326
            smart.request.request_handlers.get('BzrDir.open_branchV2'),
 
1327
            smart.bzrdir.SmartServerRequestOpenBranchV2)
 
1328
        self.assertEqual(
1175
1329
            smart.request.request_handlers.get('PackRepository.autopack'),
1176
1330
            smart.packrepository.SmartServerPackRepositoryAutopack)
1177
1331
        self.assertEqual(
1194
1348
            smart.request.request_handlers.get('Repository.lock_write'),
1195
1349
            smart.repository.SmartServerRepositoryLockWrite)
1196
1350
        self.assertEqual(
 
1351
            smart.request.request_handlers.get('Repository.get_stream'),
 
1352
            smart.repository.SmartServerRepositoryGetStream)
 
1353
        self.assertEqual(
1197
1354
            smart.request.request_handlers.get('Repository.tarball'),
1198
1355
            smart.repository.SmartServerRepositoryTarball)
1199
1356
        self.assertEqual(