diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-03-06 15:00:55 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-03-06 15:00:55 +0000 |
commit | 8225127393e6301049f7e5c17adf83c2e429a0f4 (patch) | |
tree | 8d678c06cb62692c72fa1e29eaa652c053332793 /tests | |
parent | 9b4cfc04bf6ff51eee59823b0f77ff0a847fc628 (diff) | |
parent | cd977a740dc43f63fadb622dae19520a3668c0ee (diff) | |
download | oslo-incubator-8225127393e6301049f7e5c17adf83c2e429a0f4.tar.gz |
Merge "Handle non-json http exceptions better"
Diffstat (limited to 'tests')
-rw-r--r-- | tests/unit/apiclient/test_exceptions.py | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/unit/apiclient/test_exceptions.py b/tests/unit/apiclient/test_exceptions.py index 42021e0e..ead088e0 100644 --- a/tests/unit/apiclient/test_exceptions.py +++ b/tests/unit/apiclient/test_exceptions.py @@ -101,3 +101,37 @@ class ExceptionsArgsTest(test_base.BaseTestCase): self.assert_exception( exceptions.BadRequest, method, url, status_code, json_data2, message, details) + + def test_from_response_with_text_response_format(self): + method = "GET" + url = "/fake-wsme" + status_code = 400 + text_data1 = "error_message: fake message" + + ex = exceptions.from_response( + FakeResponse(status_code=status_code, + headers={"Content-Type": "text/html"}, + text=text_data1), + method, + url) + self.assertTrue(isinstance(ex, exceptions.BadRequest)) + self.assertEqual(ex.details, text_data1) + self.assertEqual(ex.method, method) + self.assertEqual(ex.url, url) + self.assertEqual(ex.http_status, status_code) + + def test_from_response_with_text_response_format_with_no_body(self): + method = "GET" + url = "/fake-wsme" + status_code = 401 + + ex = exceptions.from_response( + FakeResponse(status_code=status_code, + headers={"Content-Type": "text/html"}), + method, + url) + self.assertTrue(isinstance(ex, exceptions.Unauthorized)) + self.assertEqual(ex.details, '') + self.assertEqual(ex.method, method) + self.assertEqual(ex.url, url) + self.assertEqual(ex.http_status, status_code) |