~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-03-06 19:35:39 UTC
  • mfrom: (4086.1.4 hpss-integration)
  • Revision ID: pqm@pqm.ubuntu.com-20090306193539-h0q6dlyayhgcehta
(robertc, andrew) Add Branch.get_tags_dict RPC;
        Add optional 'fetch_spec' argument to Repository.fetch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
177
177
        expected = SuccessfulSmartServerResponse(
178
178
            (local_result.network_name(),
179
179
            local_result.repository_format.network_name(),
180
 
            ('direct', local_result.get_branch_format().network_name())))
 
180
            ('branch', local_result.get_branch_format().network_name())))
181
181
        self.assertEqual(expected, request.execute('', 'False'))
182
182
 
183
183
    def test_cloning_metadir_reference(self):
196
196
        expected = SuccessfulSmartServerResponse(
197
197
            (local_result.network_name(),
198
198
            local_result.repository_format.network_name(),
199
 
            ('reference', reference_url)))
 
199
            ('ref', reference_url)))
200
200
        self.assertEqual(expected, request.execute('', 'False'))
201
201
 
202
202
 
364
364
            request.execute('reference'))
365
365
 
366
366
 
 
367
class TestSmartServerRequestOpenBranchV2(TestCaseWithChrootedTransport):
 
368
 
 
369
    def test_no_branch(self):
 
370
        """When there is no branch, ('nobranch', ) is returned."""
 
371
        backing = self.get_transport()
 
372
        self.make_bzrdir('.')
 
373
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
 
374
        self.assertEqual(SmartServerResponse(('nobranch', )),
 
375
            request.execute(''))
 
376
 
 
377
    def test_branch(self):
 
378
        """When there is a branch, 'ok' is returned."""
 
379
        backing = self.get_transport()
 
380
        expected = self.make_branch('.')._format.network_name()
 
381
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
 
382
        self.assertEqual(SuccessfulSmartServerResponse(('branch', expected)),
 
383
            request.execute(''))
 
384
 
 
385
    def test_branch_reference(self):
 
386
        """When there is a branch reference, the reference URL is returned."""
 
387
        backing = self.get_transport()
 
388
        request = smart.bzrdir.SmartServerRequestOpenBranchV2(backing)
 
389
        branch = self.make_branch('branch')
 
390
        checkout = branch.create_checkout('reference',lightweight=True)
 
391
        reference_url = BranchReferenceFormat().get_reference(checkout.bzrdir)
 
392
        self.assertFileEqual(reference_url, 'reference/.bzr/branch/location')
 
393
        self.assertEqual(SuccessfulSmartServerResponse(('ref', reference_url)),
 
394
            request.execute('reference'))
 
395
 
 
396
 
367
397
class TestSmartServerRequestRevisionHistory(tests.TestCaseWithMemoryTransport):
368
398
 
369
399
    def test_empty(self):
696
726
            response)
697
727
 
698
728
 
 
729
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
 
730
# Only called when the branch format and tags match [yay factory
 
731
# methods] so only need to test straight forward cases.
 
732
 
 
733
    def test_get_bytes(self):
 
734
        base_branch = self.make_branch('base')
 
735
        request = smart.branch.SmartServerBranchGetTagsBytes(
 
736
            self.get_transport())
 
737
        response = request.execute('base')
 
738
        self.assertEquals(
 
739
            SuccessfulSmartServerResponse(('',)), response)
 
740
 
 
741
 
699
742
class TestSmartServerBranchRequestGetStackedOnURL(tests.TestCaseWithMemoryTransport):
700
743
 
701
744
    def test_get_stacked_on_url(self):
931
974
            request.execute('', 'missingrevision'))
932
975
 
933
976
 
 
977
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
 
978
 
 
979
    def make_two_commit_repo(self):
 
980
        tree = self.make_branch_and_memory_tree('.')
 
981
        tree.lock_write()
 
982
        tree.add('')
 
983
        r1 = tree.commit('1st commit')
 
984
        r2 = tree.commit('2nd commit', rev_id=u'\xc8'.encode('utf-8'))
 
985
        tree.unlock()
 
986
        repo = tree.branch.repository
 
987
        return repo, r1, r2
 
988
 
 
989
    def test_ancestry_of(self):
 
990
        """The search argument may be a 'ancestry-of' some heads'."""
 
991
        backing = self.get_transport()
 
992
        request = smart.repository.SmartServerRepositoryGetStream(backing)
 
993
        repo, r1, r2 = self.make_two_commit_repo()
 
994
        fetch_spec = ['ancestry-of', r2]
 
995
        lines = '\n'.join(fetch_spec)
 
996
        request.execute('', repo._format.network_name())
 
997
        response = request.do_body(lines)
 
998
        self.assertEqual(('ok',), response.args)
 
999
        stream_bytes = ''.join(response.body_stream)
 
1000
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
 
1001
 
 
1002
    def test_search(self):
 
1003
        """The search argument may be a 'search' of some explicit keys."""
 
1004
        backing = self.get_transport()
 
1005
        request = smart.repository.SmartServerRepositoryGetStream(backing)
 
1006
        repo, r1, r2 = self.make_two_commit_repo()
 
1007
        fetch_spec = ['search', '%s %s' % (r1, r2), 'null:', '2']
 
1008
        lines = '\n'.join(fetch_spec)
 
1009
        request.execute('', repo._format.network_name())
 
1010
        response = request.do_body(lines)
 
1011
        self.assertEqual(('ok',), response.args)
 
1012
        stream_bytes = ''.join(response.body_stream)
 
1013
        self.assertStartsWith(stream_bytes, 'Bazaar pack format 1')
 
1014
 
 
1015
 
934
1016
class TestSmartServerRequestHasRevision(tests.TestCaseWithMemoryTransport):
935
1017
 
936
1018
    def test_missing_revision(self):
1209
1291
            smart.request.request_handlers.get('Branch.get_parent'),
1210
1292
            smart.branch.SmartServerBranchGetParent)
1211
1293
        self.assertEqual(
 
1294
            smart.request.request_handlers.get('Branch.get_tags_bytes'),
 
1295
            smart.branch.SmartServerBranchGetTagsBytes)
 
1296
        self.assertEqual(
1212
1297
            smart.request.request_handlers.get('Branch.lock_write'),
1213
1298
            smart.branch.SmartServerBranchRequestLockWrite)
1214
1299
        self.assertEqual(
1242
1327
            smart.request.request_handlers.get('BzrDir.open_branch'),
1243
1328
            smart.bzrdir.SmartServerRequestOpenBranch)
1244
1329
        self.assertEqual(
 
1330
            smart.request.request_handlers.get('BzrDir.open_branchV2'),
 
1331
            smart.bzrdir.SmartServerRequestOpenBranchV2)
 
1332
        self.assertEqual(
1245
1333
            smart.request.request_handlers.get('PackRepository.autopack'),
1246
1334
            smart.packrepository.SmartServerPackRepositoryAutopack)
1247
1335
        self.assertEqual(