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

Implement interrupting body streams with an error.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2313
2313
#            body)
2314
2314
 
2315
2315
 
 
2316
class TestConventionalResponseHandler(tests.TestCase):
 
2317
 
 
2318
    def test_interrupted_body_stream(self):
 
2319
        interrupted_body_stream = (
 
2320
            'oS' # successful response
 
2321
            's\0\0\0\x02le' # empty args
 
2322
            'b\0\0\0\x09chunk one' # first chunk
 
2323
            'b\0\0\0\x09chunk two' # second chunk
 
2324
            'oE' # error flag
 
2325
            's\0\0\0\x0el5:error3:abce' # bencoded error
 
2326
            'e' # message end
 
2327
            )
 
2328
        from bzrlib.smart.message import ConventionalResponseHandler
 
2329
        response_handler = ConventionalResponseHandler()
 
2330
        protocol_decoder = protocol._ProtocolThreeBase(response_handler)
 
2331
        # put decoder in desired state (waiting for message parts)
 
2332
        protocol_decoder.state_accept = protocol_decoder._state_accept_expecting_message_part
 
2333
        output = StringIO()
 
2334
        client_medium = medium.SmartSimplePipesClientMedium(
 
2335
            StringIO(interrupted_body_stream), output)
 
2336
        medium_request = client_medium.get_request()
 
2337
        medium_request.finished_writing()
 
2338
        response_handler.setProtoAndMedium(protocol_decoder, medium_request)
 
2339
        stream = response_handler.read_streamed_body()
 
2340
        self.assertEqual('chunk one', stream.next())
 
2341
        self.assertEqual('chunk two', stream.next())
 
2342
        exc = self.assertRaises(errors.ErrorFromSmartServer, stream.next)
 
2343
        self.assertEqual(('error', 'abc'), exc.error_tuple)
 
2344
 
 
2345
 
2316
2346
class InstrumentedRequestHandler(object):
2317
2347
    """Test Double of SmartServerRequestHandler."""
2318
2348