summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2015-06-18 01:16:51 +0000
committerGerrit Code Review <review@openstack.org>2015-06-18 01:16:51 +0000
commit1718afee081379c1364fe53e0a78ea3b5541d3d4 (patch)
tree2cca5a2ddc4c439113272ddb3f7e38f6040b8c1f
parent70671ebbd7f9786ae8bc72273ba6be02dab83e82 (diff)
parent7c2ad79c30f67656daae206a5caaa828b445f33f (diff)
downloadtempest-lib-1718afee081379c1364fe53e0a78ea3b5541d3d4.tar.gz
Merge "Explicitly add json schema validator for schema validation"
-rw-r--r--tempest_lib/common/rest_client.py5
-rw-r--r--tempest_lib/tests/test_rest_client.py22
2 files changed, 26 insertions, 1 deletions
diff --git a/tempest_lib/common/rest_client.py b/tempest_lib/common/rest_client.py
index 2206ca1..062cc8e 100644
--- a/tempest_lib/common/rest_client.py
+++ b/tempest_lib/common/rest_client.py
@@ -34,7 +34,8 @@ MAX_RECURSION_DEPTH = 2
# All the successful HTTP status codes from RFC 7231 & 4918
HTTP_SUCCESS = (200, 201, 202, 203, 204, 205, 206, 207)
-# JSON Schema format checker used for JSON Schema validation
+# JSON Schema validator and format checker used for JSON Schema validation
+JSONSCHEMA_VALIDATOR = jsonschema.Draft4Validator
FORMAT_CHECKER = jsonschema.draft4_format_checker
@@ -809,6 +810,7 @@ class RestClient(object):
if body_schema:
try:
jsonschema.validate(body, body_schema,
+ cls=JSONSCHEMA_VALIDATOR,
format_checker=FORMAT_CHECKER)
except jsonschema.ValidationError as ex:
msg = ("HTTP response body is invalid (%s)") % ex
@@ -823,6 +825,7 @@ class RestClient(object):
if header_schema:
try:
jsonschema.validate(resp, header_schema,
+ cls=JSONSCHEMA_VALIDATOR,
format_checker=FORMAT_CHECKER)
except jsonschema.ValidationError as ex:
msg = ("HTTP response header is invalid (%s)") % ex
diff --git a/tempest_lib/tests/test_rest_client.py b/tempest_lib/tests/test_rest_client.py
index 21b0eda..5deee3f 100644
--- a/tempest_lib/tests/test_rest_client.py
+++ b/tempest_lib/tests/test_rest_client.py
@@ -15,6 +15,7 @@
import json
import httplib2
+import jsonschema
from oslotest import mockpatch
import six
@@ -1027,3 +1028,24 @@ class TestRestClientJSONSchemaFormatValidation(TestJSONSchemaValidationBase):
}
body = {'foo': 'example@example.com'}
self._test_validate_pass(schema, body)
+
+
+class TestRestClientJSONSchemaValidatorVersion(TestJSONSchemaValidationBase):
+
+ schema = {
+ 'status_code': [200],
+ 'response_body': {
+ 'type': 'object',
+ 'properties': {
+ 'foo': {'type': 'string'}
+ }
+ }
+ }
+
+ def test_current_json_schema_validator_version(self):
+ with mockpatch.PatchObject(jsonschema.Draft4Validator,
+ "check_schema") as chk_schema:
+ body = {'foo': 'test'}
+ self._test_validate_pass(self.schema, body)
+ chk_schema.mock.assert_called_once_with(
+ self.schema['response_body'])