Any unmarshaller validate fix

This commit is contained in:
p1c2u 2021-02-15 11:58:16 +00:00
parent 4e7d8edbb2
commit abfd0c67be
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(),