Add HTTP30X checks for validate_response()
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
This commit is contained in:
@@ -34,6 +34,9 @@ MAX_RECURSION_DEPTH = 2
|
|||||||
# All the successful HTTP status codes from RFC 7231 & 4918
|
# All the successful HTTP status codes from RFC 7231 & 4918
|
||||||
HTTP_SUCCESS = (200, 201, 202, 203, 204, 205, 206, 207)
|
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
|
# JSON Schema validator and format checker used for JSON Schema validation
|
||||||
JSONSCHEMA_VALIDATOR = jsonschema.Draft4Validator
|
JSONSCHEMA_VALIDATOR = jsonschema.Draft4Validator
|
||||||
FORMAT_CHECKER = jsonschema.draft4_format_checker
|
FORMAT_CHECKER = jsonschema.draft4_format_checker
|
||||||
@@ -223,9 +226,9 @@ class RestClient(object):
|
|||||||
).format(expected_code)
|
).format(expected_code)
|
||||||
if isinstance(expected_code, list):
|
if isinstance(expected_code, list):
|
||||||
for code in expected_code:
|
for code in expected_code:
|
||||||
assert code in HTTP_SUCCESS, assert_msg
|
assert code in HTTP_SUCCESS + HTTP_REDIRECTION, assert_msg
|
||||||
else:
|
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
|
# NOTE(afazekas): the http status code above 400 is processed by
|
||||||
# the _error_checker method
|
# the _error_checker method
|
||||||
@@ -813,7 +816,7 @@ class RestClient(object):
|
|||||||
# code if it exists is something that we expect. This is explicitly
|
# 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
|
# declared in the V3 API and so we should be able to export this in
|
||||||
# the response schema. For now we'll ignore it.
|
# 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)
|
cls.expected_success(schema['status_code'], resp.status)
|
||||||
|
|
||||||
# Check the body of a response
|
# Check the body of a response
|
||||||
|
@@ -12,6 +12,7 @@
|
|||||||
# License for the specific language governing permissions and limitations
|
# License for the specific language governing permissions and limitations
|
||||||
# under the License.
|
# under the License.
|
||||||
|
|
||||||
|
import copy
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import httplib2
|
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}
|
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):
|
def test_validate_not_http_success_code(self):
|
||||||
schema = {
|
schema = {
|
||||||
|
Reference in New Issue
Block a user