~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: 2007-10-12 08:57:26 UTC
  • mfrom: (2535.3.73 repo-refactor)
  • Revision ID: pqm@pqm.ubuntu.com-20071012085726-lyq36i8bo7ew28ba
(Andrew Bennetts) Add a smart method method that can pull a set of revisions in a single request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
import tempfile
21
21
import tarfile
22
22
 
23
 
from bzrlib import bzrdir, errors, smart, tests
 
23
from bzrlib import bzrdir, errors, pack, smart, tests
24
24
from bzrlib.smart.request import SmartServerResponse
25
25
import bzrlib.smart.bzrdir
26
26
import bzrlib.smart.branch
27
27
import bzrlib.smart.repository
 
28
from bzrlib.util import bencode
28
29
 
29
30
 
30
31
class TestCaseWithSmartMedium(tests.TestCaseWithTransport):
767
768
            "extraneous file present in tar file")
768
769
 
769
770
 
 
771
class TestSmartServerRepositoryStreamKnitData(tests.TestCaseWithTransport):
 
772
 
 
773
    def test_fetch_revisions(self):
 
774
        backing = self.get_transport()
 
775
        request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
 
776
        tree = self.make_branch_and_memory_tree('.')
 
777
        tree.lock_write()
 
778
        tree.add('')
 
779
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
 
780
        rev_id2_utf8 = u'\xc9'.encode('utf-8')
 
781
        r1 = tree.commit('1st commit', rev_id=rev_id1_utf8)
 
782
        r1 = tree.commit('2nd commit', rev_id=rev_id2_utf8)
 
783
        tree.unlock()
 
784
 
 
785
        response = request.execute(backing.local_abspath(''), rev_id2_utf8)
 
786
        self.assertEqual(('ok',), response.args)
 
787
        from cStringIO import StringIO
 
788
        unpacker = pack.ContainerReader(StringIO(response.body))
 
789
        names = []
 
790
        for [name], read_bytes in unpacker.iter_records():
 
791
            names.append(name)
 
792
            bytes = read_bytes(None)
 
793
            # The bytes should be a valid bencoded string.
 
794
            bencode.bdecode(bytes)
 
795
            # XXX: assert that the bencoded knit records have the right
 
796
            # contents?
 
797
        
 
798
    def test_no_such_revision_error(self):
 
799
        backing = self.get_transport()
 
800
        request = smart.repository.SmartServerRepositoryStreamKnitDataForRevisions(backing)
 
801
        repo = self.make_repository('.')
 
802
        rev_id1_utf8 = u'\xc8'.encode('utf-8')
 
803
        response = request.execute(backing.local_abspath(''), rev_id1_utf8)
 
804
        self.assertEqual(
 
805
            SmartServerResponse(('NoSuchRevision', rev_id1_utf8)),
 
806
            response)
 
807
 
 
808
 
770
809
class TestSmartServerIsReadonly(tests.TestCaseWithTransport):
771
810
 
772
811
    def test_is_readonly_no(self):
820
859
            smart.request.request_handlers.get('Repository.gather_stats'),
821
860
            smart.repository.SmartServerRepositoryGatherStats)
822
861
        self.assertEqual(
823
 
            smart.request.request_handlers.get('Repository.get_revision_graph'),
 
862
            smart.request.request_handlers.get(
 
863
                'Repository.get_revision_graph'),
824
864
            smart.repository.SmartServerRepositoryGetRevisionGraph)
825
865
        self.assertEqual(
826
866
            smart.request.request_handlers.get('Repository.has_revision'),
832
872
            smart.request.request_handlers.get('Repository.lock_write'),
833
873
            smart.repository.SmartServerRepositoryLockWrite)
834
874
        self.assertEqual(
 
875
            smart.request.request_handlers.get(
 
876
                'Repository.stream_knit_data_for_revisions'),
 
877
            smart.repository.SmartServerRepositoryStreamKnitDataForRevisions)
 
878
        self.assertEqual(
 
879
            smart.request.request_handlers.get('Repository.tarball'),
 
880
            smart.repository.SmartServerRepositoryTarball)
 
881
        self.assertEqual(
835
882
            smart.request.request_handlers.get('Repository.unlock'),
836
883
            smart.repository.SmartServerRepositoryUnlock)
837
884
        self.assertEqual(
838
 
            smart.request.request_handlers.get('Repository.tarball'),
839
 
            smart.repository.SmartServerRepositoryTarball)
840
 
        self.assertEqual(
841
885
            smart.request.request_handlers.get('Transport.is_readonly'),
842
886
            smart.request.SmartServerIsReadonly)