Merge pull request #295 from p1c2u/fix/any-unmarshaller-validation-fix

Any unmarshaller validate fix
This commit is contained in:
A 2021-02-15 12:14:02 +00:00 committed by GitHub
commit 49720894c8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 1 deletions

View file

@ -248,7 +248,7 @@ class AnyUnmarshaller(ComplexUnmarshaller):
SchemaType.INTEGER, SchemaType.NUMBER, SchemaType.STRING,
]
def __call__(self, value=NoValue):
def unmarshal(self, value=NoValue):
one_of_schema = self._get_one_of_schema(value)
if one_of_schema:
return self.unmarshallers_factory.create(one_of_schema)(value)

View file

@ -476,6 +476,52 @@ class TestSchemaUnmarshallerCall(object):
])
assert unmarshaller_factory(schema)(['hello']) == ['hello']
@pytest.mark.parametrize('value', [
{
'somestr': {},
'someint': 123,
},
{
'somestr': [
'content1', 'content2'
],
'someint': 123,
},
{
'somestr': 123,
'someint': 123,
},
{
'somestr': 'content',
'someint': 123,
'not_in_scheme_prop': 123,
},
])
def test_schema_any_all_of_invalid_properties(
self, value, unmarshaller_factory):
schema = Schema(
all_of=[
Schema(
'object',
required=['somestr'],
properties={
'somestr': Schema('string'),
},
),
Schema(
'object',
required=['someint'],
properties={
'someint': Schema('integer'),
},
),
],
additional_properties=False,
)
with pytest.raises(InvalidSchemaValue):
unmarshaller_factory(schema)(value)
def test_schema_any_all_of_any(self, unmarshaller_factory):
schema = Schema(all_of=[
Schema(),