diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-11-26 06:55:58 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-11-26 06:55:58 +0000 |
commit | 47385a425b70fa4a3fcdd0fd13940378b135545a (patch) | |
tree | 08093b38e08cb98b13b3f5155be2927c7785c547 | |
parent | a667145471f0c315da9ce7c57d2eb7b0d5a0585f (diff) | |
parent | f20a9c24f50bbae4261a74fa117d826a2899dd98 (diff) | |
download | tempest-lib-47385a425b70fa4a3fcdd0fd13940378b135545a.tar.gz |
Merge "Add 410 error code handling to REST client"
-rw-r--r-- | tempest_lib/common/rest_client.py | 6 | ||||
-rw-r--r-- | tempest_lib/exceptions.py | 4 | ||||
-rw-r--r-- | tempest_lib/tests/test_rest_client.py | 22 |
3 files changed, 32 insertions, 0 deletions
diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py index f3fa839..d833d5f 100644 --- a/tempest_lib/common/rest_client.py +++ b/tempest_lib/common/rest_client.py @@ -592,6 +592,7 @@ class RestClient(object): :raises Forbidden: If a 403 response code is received :raises NotFound: If a 404 response code is received :raises BadRequest: If a 400 response code is received + :raises Gone: If a 410 response code is received :raises Conflict: If a 409 response code is received :raises OverLimit: If a 413 response code is received and over_limit is not in the response body @@ -696,6 +697,11 @@ class RestClient(object): resp_body = self._parse_resp(resp_body) raise exceptions.BadRequest(resp_body, resp=resp) + if resp.status == 410: + if parse_resp: + resp_body = self._parse_resp(resp_body) + raise exceptions.Gone(resp_body, resp=resp) + if resp.status == 409: if parse_resp: resp_body = self._parse_resp(resp_body) diff --git a/tempest_lib/exceptions.py b/tempest_lib/exceptions.py index 5873b4a..2bf7cdd 100644 --- a/tempest_lib/exceptions.py +++ b/tempest_lib/exceptions.py @@ -115,6 +115,10 @@ class Conflict(ClientRestClientException): message = "An object with that identifier already exists" +class Gone(ClientRestClientException): + message = "The requested resource is no longer available" + + class ResponseWithNonEmptyBody(OtherRestClientException): message = ("RFC Violation! Response with %(status)d HTTP Status Code " "MUST NOT have a body") diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py index f356ecd..0875092 100644 --- a/tempest_lib/tests/test_rest_client.py +++ b/tempest_lib/tests/test_rest_client.py @@ -330,6 +330,9 @@ class TestRestClientErrorCheckerJSON(base.TestCase): def test_response_409(self): self._test_error_checker(exceptions.Conflict, self.set_data("409")) + def test_response_410(self): + self._test_error_checker(exceptions.Gone, self.set_data("410")) + def test_response_413(self): self._test_error_checker(exceptions.OverLimit, self.set_data("413")) @@ -405,6 +408,25 @@ class TestRestClientErrorCheckerJSON(base.TestCase): expected = r_body self.assertEqual(expected, e.resp_body) + def test_response_410_with_dict(self): + r_body = '{"resp_body": {"err": "fake_resp_body"}}' + e = self._test_error_checker(exceptions.Gone, + self.set_data("410", r_body=r_body)) + + if self.c_type == 'application/json': + expected = {"err": "fake_resp_body"} + else: + expected = r_body + self.assertEqual(expected, e.resp_body) + + def test_response_410_with_invalid_dict(self): + r_body = '{"foo": "bar"]' + e = self._test_error_checker(exceptions.Gone, + self.set_data("410", r_body=r_body)) + + expected = r_body + self.assertEqual(expected, e.resp_body) + def test_response_409_with_dict(self): r_body = '{"resp_body": {"err": "fake_resp_body"}}' e = self._test_error_checker(exceptions.Conflict, |