~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart.py

  • Committer: Ian Clatworthy
  • Date: 2007-12-17 02:44:40 UTC
  • mto: (3119.1.1 ianc-integration)
  • mto: This revision was merged to the branch mainline in revision 3120.
  • Revision ID: ian.clatworthy@internode.on.net-20071217024440-gb6e5qds0ol0r6sz
Dump help topics into text files in doc/en/user-reference

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
Tests for low-level protocol encoding are found in test_smart_transport.
25
25
"""
26
26
 
27
 
import bz2
28
27
from StringIO import StringIO
29
28
import tempfile
30
29
import tarfile
31
30
 
32
31
from bzrlib import bzrdir, errors, pack, smart, tests
33
 
from bzrlib.smart.request import (
34
 
    FailedSmartServerResponse,
35
 
    SmartServerResponse,
36
 
    SuccessfulSmartServerResponse,
37
 
    )
 
32
from bzrlib.smart.request import SmartServerResponse
38
33
import bzrlib.smart.bzrdir
39
34
import bzrlib.smart.branch
40
35
import bzrlib.smart.repository
530
525
            request.execute, backing.local_abspath('subdir'))
531
526
 
532
527
 
533
 
class TestSmartServerRepositoryGetParentMap(tests.TestCaseWithTransport):
534
 
 
535
 
    def test_trivial_bzipped(self):
536
 
        # This tests that the wire encoding is actually bzipped
537
 
        backing = self.get_transport()
538
 
        request = smart.repository.SmartServerRepositoryGetParentMap(backing)
539
 
        tree = self.make_branch_and_memory_tree('.')
540
 
 
541
 
        self.assertEqual(None,
542
 
            request.execute(backing.local_abspath(''), 'missing-id'))
543
 
        # Note that it returns a body (of '' bzipped).
544
 
        self.assertEqual(
545
 
            SuccessfulSmartServerResponse(('ok', ), bz2.compress('')),
546
 
            request.do_body('\n\n0\n'))
547
 
 
548
 
 
549
528
class TestSmartServerRepositoryGetRevisionGraph(tests.TestCaseWithTransport):
550
529
 
551
530
    def test_none_argument(self):
835
814
            response)
836
815
 
837
816
 
838
 
class TestSmartServerRepositoryStreamRevisionsChunked(tests.TestCaseWithTransport):
839
 
 
840
 
    def test_fetch_revisions(self):
841
 
        backing = self.get_transport()
842
 
        request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
843
 
            backing)
844
 
        tree = self.make_branch_and_memory_tree('.')
845
 
        tree.lock_write()
846
 
        tree.add('')
847
 
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
848
 
        rev_id2_utf8 = u'\xc9'.encode('utf-8')
849
 
        tree.commit('1st commit', rev_id=rev_id1_utf8)
850
 
        tree.commit('2nd commit', rev_id=rev_id2_utf8)
851
 
        tree.unlock()
852
 
 
853
 
        response = request.execute(backing.local_abspath(''))
854
 
        self.assertEqual(None, response)
855
 
        response = request.do_body("%s\n%s\n1" % (rev_id2_utf8, rev_id1_utf8))
856
 
        self.assertEqual(('ok',), response.args)
857
 
        from cStringIO import StringIO
858
 
        parser = pack.ContainerPushParser()
859
 
        names = []
860
 
        for stream_bytes in response.body_stream:
861
 
            parser.accept_bytes(stream_bytes)
862
 
            for [name], record_bytes in parser.read_pending_records():
863
 
                names.append(name)
864
 
                # The bytes should be a valid bencoded string.
865
 
                bencode.bdecode(record_bytes)
866
 
                # XXX: assert that the bencoded knit records have the right
867
 
                # contents?
868
 
        
869
 
    def test_no_such_revision_error(self):
870
 
        backing = self.get_transport()
871
 
        request = smart.repository.SmartServerRepositoryStreamRevisionsChunked(
872
 
            backing)
873
 
        repo = self.make_repository('.')
874
 
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
875
 
        response = request.execute(backing.local_abspath(''))
876
 
        self.assertEqual(None, response)
877
 
        response = request.do_body("%s\n\n1" % (rev_id1_utf8,))
878
 
        self.assertEqual(
879
 
            FailedSmartServerResponse(('NoSuchRevision', )),
880
 
            response)
881
 
 
882
 
 
883
817
class TestSmartServerIsReadonly(tests.TestCaseWithTransport):
884
818
 
885
819
    def test_is_readonly_no(self):
933
867
            smart.request.request_handlers.get('Repository.gather_stats'),
934
868
            smart.repository.SmartServerRepositoryGatherStats)
935
869
        self.assertEqual(
936
 
            smart.request.request_handlers.get('Repository.get_parent_map'),
937
 
            smart.repository.SmartServerRepositoryGetParentMap)
938
 
        self.assertEqual(
939
870
            smart.request.request_handlers.get(
940
871
                'Repository.get_revision_graph'),
941
872
            smart.repository.SmartServerRepositoryGetRevisionGraph)
949
880
            smart.request.request_handlers.get('Repository.lock_write'),
950
881
            smart.repository.SmartServerRepositoryLockWrite)
951
882
        self.assertEqual(
 
883
            smart.request.request_handlers.get(
 
884
                'Repository.stream_knit_data_for_revisions'),
 
885
            smart.repository.SmartServerRepositoryStreamKnitDataForRevisions)
 
886
        self.assertEqual(
952
887
            smart.request.request_handlers.get('Repository.tarball'),
953
888
            smart.repository.SmartServerRepositoryTarball)
954
889
        self.assertEqual(