diff options
author | Ken'ichi Ohmichi <ken-oomichi@wx.jp.nec.com> | 2015-09-04 03:53:52 +0000 |
---|---|---|
committer | Ken'ichi Ohmichi <ken-oomichi@wx.jp.nec.com> | 2015-09-04 08:47:10 +0000 |
commit | 9a58df8abe691ff999471682db3739a868ffd9e9 (patch) | |
tree | 1eeb78c7bf4e8cb196d98265ce37b517cdfa6c34 | |
parent | 2ed10d21738d705132390f6a821d7452940577a3 (diff) | |
download | tempest-lib-0.8.0.tar.gz |
Add HTTP30X checks for validate_response()0.8.0
We are trying to add "get API version" test for Nova API on Temepst
side, but validate_response() doesn't work at all for the API because
the API returns HTTP300.
This patch makes validate_response() work for HTTP30X for the test.
Change-Id: If2ce6c9c9e2fde554b4e44dc99ec70d087c3f682
-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 = { |