diff --git a/tests/unit/test_http_errors.py b/tests/unit/test_http_errors.py index a4ec376..f2a7893 100644 --- a/tests/unit/test_http_errors.py +++ b/tests/unit/test_http_errors.py @@ -124,3 +124,15 @@ class TestHttpErrors(unittest.TestCase): response = GetOrPost(self.client, method).call(self.test_endpoint) self.assertEqual(response["code"], 202) + @httpretty.activate + @data(GET, POST) + def test_http_error_with_no_response_processing(self, method): + """ + Check that get/post methods work with response processing disabled + when an HTTP error code is returned. + """ + httpretty.register_uri(method, self.test_uri, status=500) + with self.assertRaises(trovebox.TroveboxError): + response = GetOrPost(self.client, method).call(self.test_endpoint, + process_response=False) + diff --git a/trovebox/http.py b/trovebox/http.py index dd33917..ffeb487 100644 --- a/trovebox/http.py +++ b/trovebox/http.py @@ -113,7 +113,11 @@ class Http(object): if process_response: return self._process_response(response) else: - return response.text + if 200 <= response.status_code < 300: + return response.text + else: + raise TroveboxError("HTTP Error %d: %s" % + (response.status_code, response.reason)) def post(self, endpoint, process_response=True, files=None, **params): """ @@ -163,7 +167,11 @@ class Http(object): if process_response: return self._process_response(response) else: - return response.text + if 200 <= response.status_code < 300: + return response.text + else: + raise TroveboxError("HTTP Error %d: %s" % + (response.status_code, response.reason)) def _construct_url(self, endpoint): """Return the full URL to the specified endpoint"""