def test_get_body(self): req = http.Request('http://foo') req.buffer = BytesIO() req.buffer.write(b'hello') rn = http.Response(req, 200, buffer=None) assert rn.body is None r = http.Response(req, 200, buffer=req.buffer) assert r._body is None assert r.body == b'hello' assert r._body == b'hello' assert r.body == b'hello'
def test_getresponse__real_response(self): client = Mock(name='client') client.add_request = passthrough(name='client.add_request') callback = PromiseMock(name='callback') x = AsyncHTTPSConnection(http_client=client) request = x.getresponse(callback) x.http_client.add_request.assert_called_with(request) buf = StringIO() buf.write('The quick brown fox jumps') headers = http.Headers({'X-Foo': 'Hello', 'X-Bar': 'World'}) response = http.Response(request, 200, headers, buf) request.on_ready(response) callback.assert_called() wresponse = callback.call_args[0][0] assert wresponse.read() == 'The quick brown fox jumps' assert wresponse.status == 200 assert wresponse.getheader('X-Foo') == 'Hello' headers_dict = wresponse.getheaders() assert dict(headers_dict) == headers assert wresponse.msg assert repr(wresponse)
def test_init(self): req = http.Request('http://foo') r = http.Response(req, 200) assert r.status == 'OK' assert r.effective_url == 'http://foo' r.raise_for_error()
def test_raise_for_error(self): req = http.Request('http://foo') r = http.Response(req, 404) assert r.status == 'Not Found' assert r.error with pytest.raises(HttpError): r.raise_for_error()