Status code mismatches are actually quite common.

Rather than raise an exception, just ensure we return the JSON code.
This commit is contained in:
sneakypete81 2013-06-30 18:04:36 +01:00
parent 413cf297a3
commit 971bab4f7b
2 changed files with 12 additions and 14 deletions

View file

@ -166,22 +166,24 @@ class TestHttpErrors(unittest.TestCase):
@httpretty.activate
def test_get_with_status_code_mismatch(self):
"""
Check that an exception is raised if a get returns a
status code that doesn't match the JSON code
Check that a mismatched HTTP status code still returns the
JSON status code for get requests.
"""
data = {"message": "Test Message", "code": 200}
self._register_uri(httpretty.GET, data=data, status=202)
with self.assertRaises(openphoto.OpenPhotoError):
self.client.get(self.test_endpoint)
data = {"message": "Test Message", "code": 202}
self._register_uri(httpretty.GET, data=data, status=200)
response = self.client.get(self.test_endpoint)
self.assertEqual(response["code"], 202)
# TODO: Status code mismatch should raise an exception
@unittest.expectedFailure
@httpretty.activate
def test_post_with_status_code_mismatch(self):
"""
Check that an exception is raised if a post returns a
status code that doesn't match the JSON code
Check that a mismatched HTTP status code still returns the
JSON status code for post requests.
"""
data = {"message": "Test Message", "code": 200}
self._register_uri(httpretty.POST, data=data, status=202)
with self.assertRaises(openphoto.OpenPhotoError):
self.client.post(self.test_endpoint)
response = self.client.post(self.test_endpoint)
self.assertEqual(response["code"], 202)