예제 #1
0
 def test_proxy_readbodyprotocol(self):
     original = Response(('HTTP', 1, 1), 200, 'OK', Headers(),
                         AbortableStringTransport())
     original._bodyDataReceived(LOREM_IPSUM)
     original._bodyDataFinished()
     proxy = RecordingResponse(original)
     body = yield readBody(proxy)
     self.assertEqual(body, LOREM_IPSUM)
     self.assertEqual(proxy.value(), LOREM_IPSUM)
예제 #2
0
 def assert_delivery(self, data, expected):
     finished = Deferred()
     finished.addCallback(self.assertEqual, expected)
     response = Response(('HTTP', 1, 1), 200, 'OK', Headers(),
                         AbortableStringTransport())
     protocol = TruncatingReadBodyProtocol(
         response.code, response.phrase, finished, max_bytes=8)
     response.deliverBody(protocol)
     response._bodyDataReceived(data)
     response._bodyDataFinished()
     return finished
예제 #3
0
 def test_simple(self):
     data = [{'foo': 'bar', 'index': i} for i in xrange(10000)]
     json_str = json.dumps(data)
     response = Response(('HTTP', 1, 1), 200, 'OK', Headers(),
                         StringTransport())
     finished = read_json_body(response)
     finished.addCallback(self.assertEqual, data)
     chunk_length = 1000
     for start in xrange(0, len(json_str), chunk_length):
         response._bodyDataReceived(json_str[start:start + chunk_length])
     response._bodyDataFinished()
     return finished
예제 #4
0
 def assert_delivery(self, data, expected):
     finished = Deferred()
     finished.addCallback(self.assertEqual, expected)
     response = Response(('HTTP', 1, 1), 200, 'OK', Headers(),
                         AbortableStringTransport())
     protocol = TruncatingReadBodyProtocol(response.code,
                                           response.phrase,
                                           finished,
                                           max_bytes=8)
     response.deliverBody(protocol)
     response._bodyDataReceived(data)
     response._bodyDataFinished()
     return finished