Skip to content

Commit c69cd04

Browse files
author
Pedro Crespo
committed
Add tests to check free form objects unmarshall
1 parent 0e30b71 commit c69cd04

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

tests/unit/schema/test_schemas.py

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,24 @@ def test_schema_any(self):
328328
assert schema.unmarshal('string') == 'string'
329329

330330

331+
@pytest.mark.parametrize('value', [
332+
{'additional': 1},
333+
{'foo': 'bar', 'bar': 'foo'}, # Example in https://github.com/p1c2u/openapi-core/issues/67#issuecomment-463656001
334+
{'additional': {
335+
'bar': 1
336+
} }
337+
])
338+
def test_schema_free_form_object(self, value):
339+
schema = Schema('object', additional_properties=True)
340+
341+
# same as TestSchemaValidate::test_object_additional_properties
342+
obj = Model(value)
343+
schema.validate(obj)
344+
345+
result = schema.unmarshal(value)
346+
assert result.__dict__ == value
347+
348+
331349
class TestSchemaValidate(object):
332350

333351
@pytest.mark.parametrize('schema_type', [
@@ -887,24 +905,27 @@ def test_object_max_properties(self, value):
887905
assert result == value
888906

889907
@pytest.mark.parametrize('value', [Model({'additional': 1}), ])
890-
def test_object_additional_propetries(self, value):
908+
def test_object_additional_properties(self, value):
891909
schema = Schema('object')
892910

893-
schema.validate(value)
911+
result = schema.validate(value)
912+
assert result == value
894913

895914
@pytest.mark.parametrize('value', [Model({'additional': 1}), ])
896-
def test_object_additional_propetries_false(self, value):
915+
def test_object_additional_properties_false(self, value):
897916
schema = Schema('object', additional_properties=False)
898917

899918
with pytest.raises(UndefinedSchemaProperty):
900919
schema.validate(value)
901920

902921
@pytest.mark.parametrize('value', [Model({'additional': 1}), ])
903-
def test_object_additional_propetries_object(self, value):
922+
def test_object_additional_properties_object(self, value):
904923
additional_properties = Schema('integer')
905924
schema = Schema('object', additional_properties=additional_properties)
906925

907-
schema.validate(value)
926+
result = schema.validate(value)
927+
assert result == value
928+
908929

909930
@pytest.mark.parametrize('value', [[], ])
910931
def test_list_min_items_invalid_schema(self, value):

0 commit comments

Comments
 (0)