def test_fetch_head(self): client = HTTPClient("http://example.com", method="HEAD") client.agent = Mock() _response = Mock() _response.headers.getAllRawHeaders.return_value = {} _response.deliverBody = lambda x: x.connectionLost(None) client.agent.request.return_value = succeed(_response) response = yield client.fetch() self.assertEqual(response.body, "")
def test_ensure_contenttype_set_properly(self): client = HTTPClient(self.URL, postdata="something") self.assertEqual( client.headers, {'Content-Type': ['application/x-www-form-urlencoded']} ) client = HTTPClient(self.URL, postdata="something", headers={ "Content-Type": "nothing" }) self.assertEqual(client.headers, {"Content-Type": "nothing"})
def test_fetch_basic(self): client = HTTPClient("http://example.com") client.agent = Mock() _response = Mock() _response.code = 200 _response.headers.getAllRawHeaders.return_value = {} _response.deliverBody = lambda x: x.dataReceived("done") \ or x.connectionLost(None) client.agent.request.return_value = succeed(_response) response = yield client.fetch() self.assertEqual(response.body, "done")
def test_slightly_ambiguous_things(self): """ Test some broken things. This is to make sure we dont break backwards compat if they are ever fixed. """ client = HTTPClient(self.URL, postdata="") self.assertEqual(client.method, "GET")
def test_fetch_redirect_empty(self): client = HTTPClient("http://example.com") client.agent = Mock() client.followRedirect = True client.maxRedirects = 1 _response1 = Mock() _response1.code = 302 _response1.headers.getAllRawHeaders.return_value = {} _response1.deliverBody = lambda x: x.connectionLost(None) _response2 = Mock() _response2.code = 200 _response2.headers.getAllRawHeaders.return_value = {} _response2.deliverBody = lambda x: x.connectionLost(None) client.agent.request.side_effect = [ succeed(_response1), succeed(_response2) ] response = yield client.fetch() self.assertEqual(response.body, "")
def test_ensure_method_set_properly(self): client = HTTPClient(self.URL, postdata="something") self.assertEqual(client.method, "POST") client = HTTPClient(self.URL) self.assertEqual(client.method, "GET")
def test_create_client_with_proxy(self): client = HTTPClient(self.URL, proxy=("example.com", 8080)) self.assertEqual(client.proxyConfig, ("example.com", 8080)) self.assertEqual(client.agent._proxyEndpoint._port, 8080) self.assertEqual(client.agent._proxyEndpoint._host, "example.com")
def test_create_client(self): client = HTTPClient(self.URL) self.assertEqual(client._args, ())