def test_getresponse__real_response(self): client = Mock(name='client') client.add_request = passthrough(name='client.add_request') callback = PromiseMock(name='callback') x = AsyncHTTPConnection('aws.vandelay.com', http_client=client) request = x.getresponse(callback) x.http_client.add_request.assert_called_with(request) buf = WhateverIO() 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] self.assertEqual(wresponse.read(), 'The quick brown fox jumps') self.assertEqual(wresponse.status, 200) self.assertEqual(wresponse.getheader('X-Foo'), 'Hello') self.assertDictEqual(dict(wresponse.getheaders()), headers) self.assertTrue(wresponse.msg) self.assertTrue(wresponse.msg) self.assertTrue(repr(wresponse))
def test_header_parser(self): c = BaseClient(Mock(name='hub')) parser = c._header_parser headers = http.Headers() c.on_header(headers, 'HTTP/1.1') c.on_header(headers, 'x-foo-bar: 123') c.on_header(headers, 'People: George Costanza') self.assertEqual(headers._prev_key, 'People') c.on_header(headers, ' Jerry Seinfeld') c.on_header(headers, ' Elaine Benes') c.on_header(headers, ' Cosmo Kramer') self.assertFalse(headers.complete) c.on_header(headers, '') self.assertTrue(headers.complete) with self.assertRaises(KeyError): parser.throw(KeyError('foo')) c.on_header(headers, '') self.assertEqual(headers['X-Foo-Bar'], '123') self.assertEqual( headers['People'], 'George Costanza Jerry Seinfeld Elaine Benes Cosmo Kramer', )
def assert_request_created_with(self, url, conn): conn.Request.assert_called_with( url, method=conn.method, headers=http.Headers(conn.headers), body=conn.body, connect_timeout=conn.timeout, request_timeout=conn.timeout, validate_cert=VALIDATES_CERT, )
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 = WhateverIO() 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): x = http.Request('http://foo', method='POST') self.assertEqual(x.url, 'http://foo') self.assertEqual(x.method, 'POST') x = http.Request('x', max_redirects=100) self.assertEqual(x.max_redirects, 100) self.assertIsInstance(x.headers, http.Headers) h = http.Headers() x = http.Request('x', headers=h) self.assertIs(x.headers, h) self.assertIsInstance(x.on_ready, promise)
def test_init(self): x = http.Request('http://foo', method='POST') assert x.url == 'http://foo' assert x.method == 'POST' x = http.Request('x', max_redirects=100) assert x.max_redirects == 100 assert isinstance(x.headers, http.Headers) h = http.Headers() x = http.Request('x', headers=h) assert x.headers is h assert isinstance(x.on_ready, promise)
def test_header_parser(self): c = BaseClient(Mock(name='hub')) parser = c._header_parser headers = http.Headers() c.on_header(headers, 'HTTP/1.1') c.on_header(headers, 'x-foo-bar: 123') c.on_header(headers, 'People: George Costanza') assert headers._prev_key == 'People' c.on_header(headers, ' Jerry Seinfeld') c.on_header(headers, ' Elaine Benes') c.on_header(headers, ' Cosmo Kramer') assert not headers.complete c.on_header(headers, '') assert headers.complete with pytest.raises(KeyError): parser.throw(KeyError('foo')) c.on_header(headers, '') assert headers['X-Foo-Bar'] == '123' assert (headers['People'] == 'George Costanza Jerry Seinfeld Elaine Benes Cosmo Kramer')