def test_request_attributes(self): # The resulting request includes the expected attributes. request = utils.clone_request(self.request, 'http://example.com/test') self.assertEqual('http://example.com/test', request.url) self.assertEqual('hello', request.body) self.assertEqual({'Content-Type': 'application/json'}, request.headers) self.assertEqual('POST', request.method) self.assertTrue(request.validate_cert)
def test_request_attributes(self): # The resulting request includes the expected attributes. request = utils.clone_request(self.request, "http://example.com/test") self.assertEqual("http://example.com/test", request.url) self.assertEqual("hello", request.body) self.assertEqual({"Content-Type": "application/json"}, request.headers) self.assertEqual("POST", request.method) self.assertTrue(request.validate_cert)
def send_request(self, url): """Send an asynchronous request to the given URL. Return the server response. If an error occurs in the communication, return None and call self._send_error with the given error. """ request = clone_request( self.request, url, validate_cert=self.validate_cert) client = httpclient.AsyncHTTPClient() try: response = yield client.fetch(request) except httpclient.HTTPError as err: response = getattr(err, 'response', None) if not response: self._send_error(url, err) raise gen.Return(response)
def test_request_body(self): # An empty body is set to None. original = httpserver.HTTPRequest('GET', '/test/', body='') request = utils.clone_request(original, 'http://example.com/test') self.assertEqual('http://example.com/test', request.url) self.assertIsNone(request.body)
def test_request_type(self): # The resulting request is a tornado.httpclient.HTTPRequest instance. request = utils.clone_request(self.request, 'http://example.com') self.assertIsInstance(request, httpclient.HTTPRequest)
def test_avoid_validating_certs(self): # It is possible to avoid TLS certificates validation. request = utils.clone_request( self.request, 'http://example.com/test', validate_cert=False) self.assertFalse(request.validate_cert)
def test_avoid_validating_certs(self): # It is possible to avoid TLS certificates validation. request = utils.clone_request(self.request, 'http://example.com/test', validate_cert=False) self.assertFalse(request.validate_cert)
def test_request_body(self): # An empty body is set to None. original = httpserver.HTTPRequest("GET", "/test/", body="") request = utils.clone_request(original, "http://example.com/test") self.assertEqual("http://example.com/test", request.url) self.assertIsNone(request.body)