From 829f2bac6a2de6409b8d19c6fd995cf95934f9fa Mon Sep 17 00:00:00 2001 From: Jamie Lennox Date: Fri, 4 Apr 2014 11:17:24 +1000 Subject: [PATCH] Add new error for invalid response There are a number of places where we expect a certain format of response. If it's not found we often end up raising a KeyError when accessing data. Create a new Exception type that is raised when a HTTP response is not appropriate for parsing and use it within authentication calls. Closes-Bug: #1307306 Change-Id: I3cf2db07a8e76ee17702130e9efb0edf640d293a --- auth/test_identity_v2.py | 22 ++++++++++++++++++++++ auth/test_identity_v3.py | 22 ++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/auth/test_identity_v2.py b/auth/test_identity_v2.py index 2372911..3f1c45e 100644 --- a/auth/test_identity_v2.py +++ b/auth/test_identity_v2.py @@ -211,3 +211,25 @@ class V2IdentityPlugin(utils.TestCase): endpoint_filter={'service_type': 'compute'}) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.text, 'SUCCESS') + + @httpretty.activate + def test_invalid_auth_response_dict(self): + self.stub_auth(json={'hello': 'world'}) + + a = v2.Password(self.TEST_URL, username=self.TEST_USER, + password=self.TEST_PASS) + s = session.Session(auth=a) + + self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any', + authenticated=True) + + @httpretty.activate + def test_invalid_auth_response_type(self): + self.stub_url(httpretty.POST, ['tokens'], body='testdata') + + a = v2.Password(self.TEST_URL, username=self.TEST_USER, + password=self.TEST_PASS) + s = session.Session(auth=a) + + self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any', + authenticated=True) diff --git a/auth/test_identity_v3.py b/auth/test_identity_v3.py index ca51ef7..e29c353 100644 --- a/auth/test_identity_v3.py +++ b/auth/test_identity_v3.py @@ -366,3 +366,25 @@ class V3IdentityPlugin(utils.TestCase): endpoint_filter={'service_type': 'compute'}) self.assertEqual(resp.status_code, 200) self.assertEqual(resp.text, 'SUCCESS') + + @httpretty.activate + def test_invalid_auth_response_dict(self): + self.stub_auth(json={'hello': 'world'}) + + a = v3.Password(self.TEST_URL, username=self.TEST_USER, + password=self.TEST_PASS) + s = session.Session(auth=a) + + self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any', + authenticated=True) + + @httpretty.activate + def test_invalid_auth_response_type(self): + self.stub_url(httpretty.POST, ['auth', 'tokens'], body='testdata') + + a = v3.Password(self.TEST_URL, username=self.TEST_USER, + password=self.TEST_PASS) + s = session.Session(auth=a) + + self.assertRaises(exceptions.InvalidResponse, s.get, 'http://any', + authenticated=True)