diff options
-rw-r--r-- | tempest_lib/common/rest_client.py | 9 | ||||
-rw-r--r-- | tempest_lib/tests/test_rest_client.py | 11 |
2 files changed, 15 insertions, 5 deletions
diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py index 8aa1325..2a319ee 100644 --- a/tempest_lib/common/rest_client.py +++ b/tempest_lib/common/rest_client.py @@ -34,6 +34,9 @@ MAX_RECURSION_DEPTH = 2 # All the successful HTTP status codes from RFC 7231 & 4918 HTTP_SUCCESS = (200, 201, 202, 203, 204, 205, 206, 207) +# All the redirection HTTP status codes from RFC 7231 & 4918 +HTTP_REDIRECTION = (300, 301, 302, 303, 304, 305, 306, 307) + # JSON Schema validator and format checker used for JSON Schema validation JSONSCHEMA_VALIDATOR = jsonschema.Draft4Validator FORMAT_CHECKER = jsonschema.draft4_format_checker @@ -223,9 +226,9 @@ class RestClient(object): ).format(expected_code) if isinstance(expected_code, list): for code in expected_code: - assert code in HTTP_SUCCESS, assert_msg + assert code in HTTP_SUCCESS + HTTP_REDIRECTION, assert_msg else: - assert expected_code in HTTP_SUCCESS, assert_msg + assert expected_code in HTTP_SUCCESS + HTTP_REDIRECTION, assert_msg # NOTE(afazekas): the http status code above 400 is processed by # the _error_checker method @@ -813,7 +816,7 @@ class RestClient(object): # code if it exists is something that we expect. This is explicitly # declared in the V3 API and so we should be able to export this in # the response schema. For now we'll ignore it. - if resp.status in HTTP_SUCCESS: + if resp.status in HTTP_SUCCESS + HTTP_REDIRECTION: cls.expected_success(schema['status_code'], resp.status) # Check the body of a response diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py index 25bf161..f356ecd 100644 --- a/tempest_lib/tests/test_rest_client.py +++ b/tempest_lib/tests/test_rest_client.py @@ -12,6 +12,7 @@ # License for the specific language governing permissions and limitations # under the License. +import copy import json import httplib2 @@ -671,9 +672,15 @@ class TestRestClientJSONSchemaValidation(TestJSONSchemaValidationBase): } } - def test_validate_pass(self): + def test_validate_pass_with_http_success_code(self): body = {'foo': 12} - self._test_validate_pass(self.schema, body) + self._test_validate_pass(self.schema, body, status=200) + + def test_validate_pass_with_http_redirect_code(self): + body = {'foo': 12} + schema = copy.deepcopy(self.schema) + schema['status_code'] = 300 + self._test_validate_pass(schema, body, status=300) def test_validate_not_http_success_code(self): schema = { |