Rename schema validate to obj_validate

This commit is contained in:
p1c2u 2019-09-02 23:36:30 +01:00
parent f414b182c8
commit c4c51637d2
4 changed files with 78 additions and 78 deletions

View file

@ -47,7 +47,7 @@ class MediaType(object):
raise InvalidMediaTypeValue(exc)
try:
return self.schema.validate(
return self.schema.obj_validate(
unmarshalled, custom_formatters=custom_formatters)
except OpenAPISchemaError as exc:
raise InvalidMediaTypeValue(exc)

View file

@ -123,7 +123,7 @@ class Parameter(object):
raise InvalidParameterValue(self.name, exc)
try:
return self.schema.validate(
return self.schema.obj_validate(
unmarshalled, custom_formatters=custom_formatters)
except OpenAPISchemaError as exc:
raise InvalidParameterValue(self.name, exc)

View file

@ -406,7 +406,7 @@ class Schema(object):
return defaultdict(lambda: default, mapping)
def validate(self, value, custom_formatters=None):
def obj_validate(self, value, custom_formatters=None):
if value is None:
if not self.nullable:
raise InvalidSchemaValue("Null value for non-nullable schema of type {type}", value, self.type)
@ -453,7 +453,7 @@ class Schema(object):
if self.unique_items and len(set(value)) != len(value):
raise OpenAPISchemaError("Value may not contain duplicate items")
f = functools.partial(self.items.validate,
f = functools.partial(self.items.obj_validate,
custom_formatters=custom_formatters)
return list(map(f, value))
@ -602,7 +602,7 @@ class Schema(object):
if self.additional_properties is not True:
for prop_name in extra_props:
prop_value = value[prop_name]
self.additional_properties.validate(
self.additional_properties.obj_validate(
prop_value, custom_formatters=custom_formatters)
for prop_name, prop in iteritems(all_props):
@ -615,7 +615,7 @@ class Schema(object):
continue
prop_value = prop.default
try:
prop.validate(prop_value, custom_formatters=custom_formatters)
prop.obj_validate(prop_value, custom_formatters=custom_formatters)
except OpenAPISchemaError as exc:
raise InvalidSchemaProperty(prop_name, original_exception=exc)

View file

@ -328,7 +328,7 @@ class TestSchemaUnmarshal(object):
assert schema.unmarshal('string') == 'string'
class TestSchemaValidate(object):
class TestSchemaObjValidate(object):
@pytest.mark.parametrize('schema_type', [
'boolean', 'array', 'integer', 'number', 'string',
@ -338,7 +338,7 @@ class TestSchemaValidate(object):
value = None
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('schema_type', [
'boolean', 'array', 'integer', 'number', 'string',
@ -347,7 +347,7 @@ class TestSchemaValidate(object):
schema = Schema(schema_type, nullable=True)
value = None
result = schema.validate(value)
result = schema.obj_validate(value)
assert result is None
@ -355,7 +355,7 @@ class TestSchemaValidate(object):
def test_boolean(self, value):
schema = Schema('boolean')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -364,20 +364,20 @@ class TestSchemaValidate(object):
schema = Schema('boolean')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [[1, 2], (3, 4)])
def test_array_no_schema(self, value):
schema = Schema('array')
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [[1, 2], (3, 4)])
def test_array(self, value):
schema = Schema('array', items=Schema('integer'))
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -386,13 +386,13 @@ class TestSchemaValidate(object):
schema = Schema('array')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [1, 3])
def test_integer(self, value):
schema = Schema('integer')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -401,20 +401,20 @@ class TestSchemaValidate(object):
schema = Schema('integer')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [0, 1, 2])
def test_integer_minimum_invalid(self, value):
schema = Schema('integer', minimum=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [4, 5, 6])
def test_integer_minimum(self, value):
schema = Schema('integer', minimum=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -423,13 +423,13 @@ class TestSchemaValidate(object):
schema = Schema('integer', maximum=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [0, 1, 2])
def test_integer_maximum(self, value):
schema = Schema('integer', maximum=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -438,13 +438,13 @@ class TestSchemaValidate(object):
schema = Schema('integer', multiple_of=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [3, 6, 18])
def test_integer_multiple_of(self, value):
schema = Schema('integer', multiple_of=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -452,7 +452,7 @@ class TestSchemaValidate(object):
def test_number(self, value):
schema = Schema('number')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -461,20 +461,20 @@ class TestSchemaValidate(object):
schema = Schema('number')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [0, 1, 2])
def test_number_minimum_invalid(self, value):
schema = Schema('number', minimum=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [3, 4, 5])
def test_number_minimum(self, value):
schema = Schema('number', minimum=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -483,13 +483,13 @@ class TestSchemaValidate(object):
schema = Schema('number', minimum=3, exclusive_minimum=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [4, 5, 6])
def test_number_exclusive_minimum(self, value):
schema = Schema('number', minimum=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -498,13 +498,13 @@ class TestSchemaValidate(object):
schema = Schema('number', maximum=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [1, 2, 3])
def test_number_maximum(self, value):
schema = Schema('number', maximum=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -513,13 +513,13 @@ class TestSchemaValidate(object):
schema = Schema('number', maximum=3, exclusive_maximum=True)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [0, 1, 2])
def test_number_exclusive_maximum(self, value):
schema = Schema('number', maximum=3, exclusive_maximum=True)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -528,13 +528,13 @@ class TestSchemaValidate(object):
schema = Schema('number', multiple_of=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [3, 6, 18])
def test_number_multiple_of(self, value):
schema = Schema('number', multiple_of=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -542,7 +542,7 @@ class TestSchemaValidate(object):
def test_string(self, value):
schema = Schema('string')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -551,7 +551,7 @@ class TestSchemaValidate(object):
schema = Schema('string')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
b('true'), u('test'), False, 1, 3.14, [1, 3],
@ -561,7 +561,7 @@ class TestSchemaValidate(object):
schema = Schema('string', schema_format='date')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
datetime.date(1989, 1, 2), datetime.date(2018, 1, 2),
@ -569,7 +569,7 @@ class TestSchemaValidate(object):
def test_string_format_date(self, value):
schema = Schema('string', schema_format='date')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -579,7 +579,7 @@ class TestSchemaValidate(object):
def test_string_format_uuid(self, value):
schema = Schema('string', schema_format='uuid')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -591,7 +591,7 @@ class TestSchemaValidate(object):
schema = Schema('string', schema_format='uuid')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
b('true'), u('true'), False, 1, 3.14, [1, 3],
@ -601,7 +601,7 @@ class TestSchemaValidate(object):
schema = Schema('string', schema_format='date-time')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
datetime.datetime(1989, 1, 2, 0, 0, 0),
@ -610,7 +610,7 @@ class TestSchemaValidate(object):
def test_string_format_datetime(self, value):
schema = Schema('string', schema_format='date-time')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -622,7 +622,7 @@ class TestSchemaValidate(object):
schema = Schema('string', schema_format='binary')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
b('stream'), b('text'),
@ -630,7 +630,7 @@ class TestSchemaValidate(object):
def test_string_format_binary(self, value):
schema = Schema('string', schema_format='binary')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -641,7 +641,7 @@ class TestSchemaValidate(object):
schema = Schema('string', schema_format='byte')
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
u('tsssst'), u('dGVzdA=='),
@ -649,7 +649,7 @@ class TestSchemaValidate(object):
def test_string_format_byte(self, value):
schema = Schema('string', schema_format='byte')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -662,27 +662,27 @@ class TestSchemaValidate(object):
schema = Schema('string', schema_format=unknown_format)
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [u(""), ])
def test_string_min_length_invalid_schema(self, value):
schema = Schema('string', min_length=-1)
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [u(""), u("a"), u("ab")])
def test_string_min_length_invalid(self, value):
schema = Schema('string', min_length=3)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [u("abc"), u("abcd")])
def test_string_min_length(self, value):
schema = Schema('string', min_length=3)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -691,20 +691,20 @@ class TestSchemaValidate(object):
schema = Schema('string', max_length=-1)
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [u("ab"), u("abc")])
def test_string_max_length_invalid(self, value):
schema = Schema('string', max_length=1)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [u(""), u("a")])
def test_string_max_length(self, value):
schema = Schema('string', max_length=1)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -713,13 +713,13 @@ class TestSchemaValidate(object):
schema = Schema('string', pattern='baz')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [u("bar"), u("foobar")])
def test_string_pattern(self, value):
schema = Schema('string', pattern='bar')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -728,7 +728,7 @@ class TestSchemaValidate(object):
schema = Schema('object')
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [Model(), ])
def test_object_multiple_one_of(self, value):
@ -738,7 +738,7 @@ class TestSchemaValidate(object):
schema = Schema('object', one_of=one_of)
with pytest.raises(MultipleOneOfSchema):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [Model(), ])
def test_object_defferent_type_one_of(self, value):
@ -748,7 +748,7 @@ class TestSchemaValidate(object):
schema = Schema('object', one_of=one_of)
with pytest.raises(MultipleOneOfSchema):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [Model(), ])
def test_object_no_one_of(self, value):
@ -767,7 +767,7 @@ class TestSchemaValidate(object):
schema = Schema('object', one_of=one_of)
with pytest.raises(NoOneOfSchema):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
Model({
@ -800,13 +800,13 @@ class TestSchemaValidate(object):
]
schema = Schema('object', one_of=one_of)
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [Model(), ])
def test_object_default_property(self, value):
schema = Schema('object', default='value1')
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -815,7 +815,7 @@ class TestSchemaValidate(object):
schema = Schema('object', min_properties=-1)
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
Model({'a': 1}),
@ -830,7 +830,7 @@ class TestSchemaValidate(object):
)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
Model({'a': 1}),
@ -844,7 +844,7 @@ class TestSchemaValidate(object):
min_properties=1,
)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -853,7 +853,7 @@ class TestSchemaValidate(object):
schema = Schema('object', max_properties=-1)
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
Model({'a': 1}),
@ -868,7 +868,7 @@ class TestSchemaValidate(object):
)
with pytest.raises(InvalidSchemaValue):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
Model({'a': 1}),
@ -882,7 +882,7 @@ class TestSchemaValidate(object):
max_properties=3,
)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -890,21 +890,21 @@ class TestSchemaValidate(object):
def test_object_additional_propetries(self, value):
schema = Schema('object')
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [Model({'additional': 1}), ])
def test_object_additional_propetries_false(self, value):
schema = Schema('object', additional_properties=False)
with pytest.raises(UndefinedSchemaProperty):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [Model({'additional': 1}), ])
def test_object_additional_propetries_object(self, value):
additional_properties = Schema('integer')
schema = Schema('object', additional_properties=additional_properties)
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [[], ])
def test_list_min_items_invalid_schema(self, value):
@ -915,7 +915,7 @@ class TestSchemaValidate(object):
)
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [[], [1], [1, 2]])
def test_list_min_items_invalid(self, value):
@ -926,7 +926,7 @@ class TestSchemaValidate(object):
)
with pytest.raises(Exception):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [[], [1], [1, 2]])
def test_list_min_items(self, value):
@ -936,7 +936,7 @@ class TestSchemaValidate(object):
min_items=0,
)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -949,7 +949,7 @@ class TestSchemaValidate(object):
)
with pytest.raises(OpenAPISchemaError):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [[1, 2], [2, 3, 4]])
def test_list_max_items_invalid(self, value):
@ -960,7 +960,7 @@ class TestSchemaValidate(object):
)
with pytest.raises(Exception):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [[1, 2, 1], [2, 2]])
def test_list_unique_items_invalid(self, value):
@ -971,7 +971,7 @@ class TestSchemaValidate(object):
)
with pytest.raises(Exception):
schema.validate(value)
schema.obj_validate(value)
@pytest.mark.parametrize('value', [
Model({
@ -994,7 +994,7 @@ class TestSchemaValidate(object):
},
)
result = schema.validate(value)
result = schema.obj_validate(value)
assert result == value
@ -1034,4 +1034,4 @@ class TestSchemaValidate(object):
)
with pytest.raises(Exception):
schema.validate(value)
schema.obj_validate(value)