예제 #1
0
 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, "")
예제 #2
0
 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")
예제 #3
0
 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, "")