~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Matt Nordhoff
  • Date: 2009-06-23 05:12:07 UTC
  • mto: This revision was merged to the branch mainline in revision 4474.
  • Revision ID: mnordhoff@mattnordhoff.com-20090623051207-fksdtbzkwtnrw9dd
Update _add_text docstrings that still referred to add_text.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
import tarfile
30
30
 
31
31
from bzrlib import (
32
 
    bencode,
33
32
    bzrdir,
34
33
    errors,
35
34
    pack,
36
35
    smart,
37
36
    tests,
38
37
    urlutils,
39
 
    versionedfile,
40
38
    )
41
39
from bzrlib.branch import Branch, BranchReferenceFormat
42
40
import bzrlib.smart.branch
53
51
    split_suite_by_re,
54
52
    )
55
53
from bzrlib.transport import chroot, get_transport
 
54
from bzrlib.util import bencode
56
55
 
57
56
 
58
57
def load_tests(standard_tests, module, loader):
88
87
        if self._chroot_server is None:
89
88
            backing_transport = tests.TestCaseWithTransport.get_transport(self)
90
89
            self._chroot_server = chroot.ChrootServer(backing_transport)
91
 
            self.start_server(self._chroot_server)
 
90
            self._chroot_server.setUp()
 
91
            self.addCleanup(self._chroot_server.tearDown)
92
92
        t = get_transport(self._chroot_server.get_url())
93
93
        if relpath is not None:
94
94
            t = t.clone(relpath)
113
113
        return self.get_transport().get_smart_medium()
114
114
 
115
115
 
116
 
class TestByteStreamToStream(tests.TestCase):
117
 
 
118
 
    def test_repeated_substreams_same_kind_are_one_stream(self):
119
 
        # Make a stream - an iterable of bytestrings.
120
 
        stream = [('text', [versionedfile.FulltextContentFactory(('k1',), None,
121
 
            None, 'foo')]),('text', [
122
 
            versionedfile.FulltextContentFactory(('k2',), None, None, 'bar')])]
123
 
        fmt = bzrdir.format_registry.get('pack-0.92')().repository_format
124
 
        bytes = smart.repository._stream_to_byte_stream(stream, fmt)
125
 
        streams = []
126
 
        # Iterate the resulting iterable; checking that we get only one stream
127
 
        # out.
128
 
        fmt, stream = smart.repository._byte_stream_to_stream(bytes)
129
 
        for kind, substream in stream:
130
 
            streams.append((kind, list(substream)))
131
 
        self.assertLength(1, streams)
132
 
        self.assertLength(2, streams[0][1])
133
 
 
134
 
 
135
116
class TestSmartServerResponse(tests.TestCase):
136
117
 
137
118
    def test__eq__(self):
221
202
        self.make_bzrdir('.')
222
203
        request_class = bzrlib.smart.bzrdir.SmartServerRequestCreateRepository
223
204
        request = request_class(backing)
224
 
        reference_bzrdir_format = bzrdir.format_registry.get('pack-0.92')()
 
205
        reference_bzrdir_format = bzrdir.format_registry.get('default')()
225
206
        reference_format = reference_bzrdir_format.repository_format
226
207
        network_name = reference_format.network_name()
227
208
        expected = SuccessfulSmartServerResponse(
266
247
            subtrees = 'yes'
267
248
        else:
268
249
            subtrees = 'no'
269
 
        if repo._format.supports_external_lookups:
270
 
            external = 'yes'
271
 
        else:
272
 
            external = 'no'
273
250
        if (smart.bzrdir.SmartServerRequestFindRepositoryV3 ==
274
251
            self._request_class):
275
252
            return SuccessfulSmartServerResponse(
276
 
                ('ok', '', rich_root, subtrees, external,
 
253
                ('ok', '', rich_root, subtrees, 'no',
277
254
                 repo._format.network_name()))
278
255
        elif (smart.bzrdir.SmartServerRequestFindRepositoryV2 ==
279
256
            self._request_class):
280
257
            # All tests so far are on formats, and for non-external
281
258
            # repositories.
282
259
            return SuccessfulSmartServerResponse(
283
 
                ('ok', '', rich_root, subtrees, external))
 
260
                ('ok', '', rich_root, subtrees, 'no'))
284
261
        else:
285
262
            return SuccessfulSmartServerResponse(('ok', '', rich_root, subtrees))
286
263
 
374
351
 
375
352
 
376
353
class TestSmartServerRequestBzrDirInitializeEx(tests.TestCaseWithMemoryTransport):
377
 
    """Basic tests for BzrDir.initialize_ex_1.16 in the smart server.
 
354
    """Basic tests for BzrDir.initialize_ex in the smart server.
378
355
 
379
356
    The main unit tests in test_bzrdir exercise the API comprehensively.
380
357
    """
404
381
            'subdir/dir', 'False', 'False', 'False', '', '', '', '', 'False')
405
382
 
406
383
    def test_initialized_dir(self):
407
 
        """Initializing an extant directory should fail like the bzrdir api."""
 
384
        """Initializing an extant dirctory should fail like the bzrdir api."""
408
385
        backing = self.get_transport()
409
386
        name = self.make_bzrdir('reference')._format.network_name()
410
387
        request = smart.bzrdir.SmartServerRequestBzrDirInitializeEx(backing)
475
452
    def test_stacked_branch(self):
476
453
        """Opening a stacked branch does not open the stacked-on branch."""
477
454
        trunk = self.make_branch('trunk')
478
 
        feature = self.make_branch('feature')
 
455
        feature = self.make_branch('feature', format='1.9')
479
456
        feature.set_stacked_on_url(trunk.base)
480
457
        opened_branches = []
481
458
        Branch.hooks.install_named_hook('open', opened_branches.append, None)
626
603
        branch.unlock()
627
604
 
628
605
 
629
 
class TestSmartServerBranchRequestSetTagsBytes(TestLockedBranch):
630
 
    # Only called when the branch format and tags match [yay factory
631
 
    # methods] so only need to test straight forward cases.
632
 
 
633
 
    def test_set_bytes(self):
634
 
        base_branch = self.make_branch('base')
635
 
        tag_bytes = base_branch._get_tags_bytes()
636
 
        # get_lock_tokens takes out a lock.
637
 
        branch_token, repo_token = self.get_lock_tokens(base_branch)
638
 
        request = smart.branch.SmartServerBranchSetTagsBytes(
639
 
            self.get_transport())
640
 
        response = request.execute('base', branch_token, repo_token)
641
 
        self.assertEqual(None, response)
642
 
        response = request.do_chunk(tag_bytes)
643
 
        self.assertEqual(None, response)
644
 
        response = request.do_end()
645
 
        self.assertEquals(
646
 
            SuccessfulSmartServerResponse(()), response)
647
 
        base_branch.unlock()
648
 
 
649
 
    def test_lock_failed(self):
650
 
        base_branch = self.make_branch('base')
651
 
        base_branch.lock_write()
652
 
        tag_bytes = base_branch._get_tags_bytes()
653
 
        request = smart.branch.SmartServerBranchSetTagsBytes(
654
 
            self.get_transport())
655
 
        self.assertRaises(errors.TokenMismatch, request.execute,
656
 
            'base', 'wrong token', 'wrong token')
657
 
        # The request handler will keep processing the message parts, so even
658
 
        # if the request fails immediately do_chunk and do_end are still
659
 
        # called.
660
 
        request.do_chunk(tag_bytes)
661
 
        request.do_end()
662
 
        base_branch.unlock()
663
 
 
664
 
 
665
 
 
666
606
class SetLastRevisionTestBase(TestLockedBranch):
667
607
    """Base test case for verbs that implement set_last_revision."""
668
608
 
932
872
 
933
873
 
934
874
class TestSmartServerBranchRequestGetTagsBytes(tests.TestCaseWithMemoryTransport):
935
 
    # Only called when the branch format and tags match [yay factory
936
 
    # methods] so only need to test straight forward cases.
 
875
# Only called when the branch format and tags match [yay factory
 
876
# methods] so only need to test straight forward cases.
937
877
 
938
878
    def test_get_bytes(self):
939
879
        base_branch = self.make_branch('base')
1221
1161
            request.execute('', 'missingrevision'))
1222
1162
 
1223
1163
 
1224
 
class TestSmartServerRepositoryGetRevIdForRevno(tests.TestCaseWithMemoryTransport):
1225
 
 
1226
 
    def test_revno_found(self):
1227
 
        backing = self.get_transport()
1228
 
        request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1229
 
        tree = self.make_branch_and_memory_tree('.')
1230
 
        tree.lock_write()
1231
 
        tree.add('')
1232
 
        rev1_id_utf8 = u'\xc8'.encode('utf-8')
1233
 
        rev2_id_utf8 = u'\xc9'.encode('utf-8')
1234
 
        tree.commit('1st commit', rev_id=rev1_id_utf8)
1235
 
        tree.commit('2nd commit', rev_id=rev2_id_utf8)
1236
 
        tree.unlock()
1237
 
 
1238
 
        self.assertEqual(SmartServerResponse(('ok', rev1_id_utf8)),
1239
 
            request.execute('', 1, (2, rev2_id_utf8)))
1240
 
 
1241
 
    def test_known_revid_missing(self):
1242
 
        backing = self.get_transport()
1243
 
        request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1244
 
        repo = self.make_repository('.')
1245
 
        self.assertEqual(
1246
 
            FailedSmartServerResponse(('nosuchrevision', 'ghost')),
1247
 
            request.execute('', 1, (2, 'ghost')))
1248
 
 
1249
 
    def test_history_incomplete(self):
1250
 
        backing = self.get_transport()
1251
 
        request = smart.repository.SmartServerRepositoryGetRevIdForRevno(backing)
1252
 
        parent = self.make_branch_and_memory_tree('parent', format='1.9')
1253
 
        parent.lock_write()
1254
 
        parent.add([''], ['TREE_ROOT'])
1255
 
        r1 = parent.commit(message='first commit')
1256
 
        r2 = parent.commit(message='second commit')
1257
 
        parent.unlock()
1258
 
        local = self.make_branch_and_memory_tree('local', format='1.9')
1259
 
        local.branch.pull(parent.branch)
1260
 
        local.set_parent_ids([r2])
1261
 
        r3 = local.commit(message='local commit')
1262
 
        local.branch.create_clone_on_transport(
1263
 
            self.get_transport('stacked'), stacked_on=self.get_url('parent'))
1264
 
        self.assertEqual(
1265
 
            SmartServerResponse(('history-incomplete', 2, r2)),
1266
 
            request.execute('stacked', 1, (3, r3)))
1267
 
 
1268
 
 
1269
1164
class TestSmartServerRepositoryGetStream(tests.TestCaseWithMemoryTransport):
1270
1165
 
1271
1166
    def make_two_commit_repo(self):
1665
1560
            smart.bzrdir.SmartServerRequestFindRepositoryV2)
1666
1561
        self.assertHandlerEqual('BzrDirFormat.initialize',
1667
1562
            smart.bzrdir.SmartServerRequestInitializeBzrDir)
1668
 
        self.assertHandlerEqual('BzrDirFormat.initialize_ex_1.16',
 
1563
        self.assertHandlerEqual('BzrDirFormat.initialize_ex',
1669
1564
            smart.bzrdir.SmartServerRequestBzrDirInitializeEx)
1670
1565
        self.assertHandlerEqual('BzrDir.cloning_metadir',
1671
1566
            smart.bzrdir.SmartServerBzrDirRequestCloningMetaDir)
1681
1576
            smart.repository.SmartServerRepositoryGatherStats)
1682
1577
        self.assertHandlerEqual('Repository.get_parent_map',
1683
1578
            smart.repository.SmartServerRepositoryGetParentMap)
1684
 
        self.assertHandlerEqual('Repository.get_rev_id_for_revno',
1685
 
            smart.repository.SmartServerRepositoryGetRevIdForRevno)
1686
1579
        self.assertHandlerEqual('Repository.get_revision_graph',
1687
1580
            smart.repository.SmartServerRepositoryGetRevisionGraph)
1688
1581
        self.assertHandlerEqual('Repository.get_stream',