/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_remote.py

  • Committer: Andrew Bennetts
  • Date: 2008-01-14 22:45:15 UTC
  • mfrom: (3179 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3180.
  • Revision ID: andrew.bennetts@canonical.com-20080114224515-izp51fxci3hhopap
Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
108
108
    """Lookalike SmartClientRequestProtocolOne allowing body reading tests."""
109
109
 
110
110
    def __init__(self, body, fake_client):
111
 
        self._body_buffer = StringIO(body)
 
111
        self.body = body
 
112
        self._body_buffer = None
112
113
        self._fake_client = fake_client
113
114
 
114
115
    def read_body_bytes(self, count=-1):
 
116
        if self._body_buffer is None:
 
117
            self._body_buffer = StringIO(self.body)
115
118
        bytes = self._body_buffer.read(count)
116
119
        if self._body_buffer.tell() == len(self._body_buffer.getvalue()):
117
120
            self._fake_client.expecting_body = False
120
123
    def cancel_read_body(self):
121
124
        self._fake_client.expecting_body = False
122
125
 
 
126
    def read_streamed_body(self):
 
127
        return self.body
 
128
 
123
129
 
124
130
class FakeClient(_SmartClient):
125
131
    """Lookalike for _SmartClient allowing testing."""
711
717
            responses, transport_path)
712
718
 
713
719
        # The null revision is always there, so has_revision(None) == True.
714
 
        self.assertEqual(True, repo.has_revision(None))
 
720
        self.assertEqual(True, repo.has_revision(NULL_REVISION))
715
721
 
716
722
        # The remote repo shouldn't be accessed.
717
723
        self.assertEqual([], client._calls)
785
791
        pack_file.seek(0)
786
792
        return pack_file
787
793
 
 
794
    def make_pack_stream(self, records):
 
795
        pack_serialiser = pack.ContainerSerialiser()
 
796
        yield pack_serialiser.begin()
 
797
        for bytes, names in records:
 
798
            yield pack_serialiser.bytes_record(bytes, names)
 
799
        yield pack_serialiser.end()
 
800
 
788
801
    def test_bad_pack_from_server(self):
789
802
        """A response with invalid data (e.g. it has a record with multiple
790
803
        names) triggers an exception.
793
806
        malformed data should be.
794
807
        """
795
808
        record = ('bytes', [('name1',), ('name2',)])
796
 
        pack_file = self.make_pack_file([record])
797
 
        responses = [(('ok',), pack_file.getvalue()), ]
 
809
        pack_stream = self.make_pack_stream([record])
 
810
        responses = [(('ok',), pack_stream), ]
798
811
        transport_path = 'quack'
799
812
        repo, client = self.setup_fake_client_and_repository(
800
813
            responses, transport_path)
805
818
        """If the server doesn't recognise this request, fallback to VFS."""
806
819
        error_msg = (
807
820
            "Generic bzr smart protocol error: "
808
 
            "bad request 'Repository.stream_knit_data_for_revisions'")
 
821
            "bad request 'Repository.stream_revisions_chunked'")
809
822
        responses = [
810
823
            (('error', error_msg), '')]
811
824
        repo, client = self.setup_fake_client_and_repository(