~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/test_smart_transport.py

  • Committer: Andrew Bennetts
  • Date: 2006-10-13 06:07:17 UTC
  • mto: (2018.2.34 smart server unicode)
  • mto: This revision was merged to the branch mainline in revision 2144.
  • Revision ID: andrew.bennetts@canonical.com-20061013060717-ccf711d3149c0a17
Ensure that a request's next_read_size() is 0 once an error response is sent.

This is done by setting the finished flag in _send_response, and removing
sync_with_request entirely.

Also s/_finished_reading/_finished/ in SmartServerRequestProtocolOne.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1110
1110
        self.assertOffsetSerialisation([(1,2), (3,4), (100, 200)],
1111
1111
            '1,2\n3,4\n100,200', self.client_protocol, self.smart_server_request)
1112
1112
 
1113
 
    def test_accept_bytes_to_protocol(self):
 
1113
    def test_accept_bytes_of_bad_request_to_protocol(self):
1114
1114
        out_stream = StringIO()
1115
1115
        protocol = smart.SmartServerRequestProtocolOne(None, out_stream.write)
1116
1116
        protocol.accept_bytes('abc')
1119
1119
        self.assertEqual("error\x01Generic bzr smart protocol error: bad request"
1120
1120
            " u'abc'\n", out_stream.getvalue())
1121
1121
        self.assertTrue(protocol.has_dispatched)
1122
 
        self.assertEqual(1, protocol.next_read_size())
 
1122
        self.assertEqual(0, protocol.next_read_size())
1123
1123
 
1124
1124
    def test_accept_bytes_with_invalid_utf8_to_protocol(self):
1125
1125
        out_stream = StringIO()
1131
1131
            "one or more arguments of request '\\xdd\\n' are not valid UTF-8\n",
1132
1132
            out_stream.getvalue())
1133
1133
        self.assertTrue(protocol.has_dispatched)
1134
 
        self.assertEqual(1, protocol.next_read_size())
 
1134
        self.assertEqual(0, protocol.next_read_size())
1135
1135
 
1136
1136
    def test_accept_body_bytes_to_protocol(self):
1137
1137
        protocol = self.build_protocol_waiting_for_body()
1184
1184
        self.assertEqual("hello\n", protocol.excess_buffer)
1185
1185
        self.assertEqual("", protocol.in_buffer)
1186
1186
 
1187
 
    def test_sync_with_request_sets_finished_reading(self):
1188
 
        protocol = smart.SmartServerRequestProtocolOne(None, None)
1189
 
        request = smart.SmartServerRequestHandler(None)
1190
 
        protocol.sync_with_request(request)
 
1187
    def test__send_response_sets_finished_reading(self):
 
1188
        protocol = smart.SmartServerRequestProtocolOne(None, lambda x: None)
1191
1189
        self.assertEqual(1, protocol.next_read_size())
1192
 
        request.finished_reading = True
1193
 
        protocol.sync_with_request(request)
 
1190
        protocol._send_response(('x',))
1194
1191
        self.assertEqual(0, protocol.next_read_size())
1195
1192
 
1196
1193
    def test_query_version(self):