def test_proxy_target_http_get_error_404(self): bad_url = self.url + 'notfound/' proxy_target = ProxyTarget(self.name, bad_url, self.request_timeout) proxy_target.remote_get('notfound') assert_equal(proxy_target.status_code, 404) assert_in('Not Found', proxy_target.error_string)
def test_proxy_target_other_error(self): bad_url = 'http://127.0.0.1:{}'.format(self.port + 1) proxy_target = ProxyTarget(self.name, bad_url, self.request_timeout) proxy_target.remote_get() assert_equal(proxy_target.status_code, 502) assert_in('Connection refused', proxy_target.error_string)
def test_proxy_target_io_error(self, test_proxy_target): """Test that a proxy target GET request to a non-existing server returns a 502 error.""" bad_url = 'http://127.0.0.1:{}'.format(test_proxy_target.port + 1) proxy_target = ProxyTarget(test_proxy_target.name, bad_url, test_proxy_target.request_timeout) proxy_target.remote_get() assert proxy_target.status_code == 502 assert 'Connection refused' in proxy_target.error_string
def test_proxy_target_http_get_error_404(self, test_proxy_target): """Test that a proxy target GET to a bad URL returns a 404 not found error.""" bad_url = test_proxy_target.url + 'notfound/' proxy_target = ProxyTarget(test_proxy_target.name, bad_url, test_proxy_target.request_timeout) proxy_target.remote_get('notfound') assert proxy_target.status_code == 404 assert 'Not Found' in proxy_target.error_string
def test_proxy_target_timeout_error(self, test_proxy_target): """Test that a porxy target GET request that times out is handled correctly""" mock_fetch = Mock() mock_fetch.side_effect = tornado.ioloop.TimeoutError('timeout') proxy_target = ProxyTarget(test_proxy_target.name, test_proxy_target.url, test_proxy_target.request_timeout) proxy_target.http_client.fetch = mock_fetch proxy_target.remote_get() assert proxy_target.status_code == 408 assert 'timeout' in proxy_target.error_string
def test_proxy_target_unknown_error(self, test_proxy_target): """Test that a proxy target GET request handles an unknown exception returning a 500 error.""" mock_fetch = Mock() mock_fetch.side_effect = ValueError('value error') proxy_target = ProxyTarget(test_proxy_target.name, test_proxy_target.url, test_proxy_target.request_timeout) proxy_target.http_client.fetch = mock_fetch proxy_target.remote_get() assert proxy_target.status_code == 500 assert 'value error' in proxy_target.error_string
def test_proxy_target_traps_decode_error(self, test_proxy_target): """Test that a proxy target correctly traps errors decoding a non-JSON response body.""" mock_fetch = Mock() mock_fetch.return_value = HTTPResponse(Mock(), 200, buffer=StringIO(u"wibble")) proxy_target = ProxyTarget(test_proxy_target.name, test_proxy_target.url, test_proxy_target.request_timeout) proxy_target.http_client.fetch = mock_fetch proxy_target.remote_get() print(proxy_target.status_code, proxy_target.error_string) assert proxy_target.status_code == 415 assert "Failed to decode response body" in proxy_target.error_string
def __init__(self): """Initialise the fixture, starting the test server and defining a target.""" self.test_server = ProxyTestServer() self.port = self.test_server.port self.name = 'test_target' self.url = 'http://127.0.0.1:{}/'.format(self.port) self.request_timeout = 0.1 self.proxy_target = ProxyTarget(self.name, self.url, self.request_timeout)
def setup_class(cls): cls.test_server = ProxyTestServer() cls.test_server.start() cls.port = cls.test_server.port cls.name = 'test_target' cls.url = 'http://127.0.0.1:{}/'.format(cls.port) cls.request_timeout = 0.1 cls.proxy_target = ProxyTarget(cls.name, cls.url, cls.request_timeout)