Skip to content

Commit

Permalink
Fixes pyeve#251
Browse files Browse the repository at this point in the history
- add test
  • Loading branch information
Davis Kirkendall committed Aug 26, 2016
1 parent b8359ed commit 7c8b3c3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
30 changes: 30 additions & 0 deletions cerberus/tests/tests.py
Expand Up @@ -1580,6 +1580,36 @@ def test_coerce_non_digit_in_sequence(self):
always_return_document=True),
document)

def test_allow_unknown_with_of_rules(self):
# https://github.com/nicolaiarocci/cerberus/issues/251
schema = {
'test': {
'oneof': [
{
'type': 'dict',
'allow_unknown': True,
'schema': {'known': {'type': 'string'}}
},
{
'type': 'dict',
'schema': {'known': {'type': 'string'}}
},
]
}
}
# check regression and that allow unknown does not cause any different
# than expected behaviour for one-of.
document = {'test': {'known': 's'}}
self.validator(document, schema)
_errors = self.validator._errors
self.assertEqual(len(_errors), 1)
self.assertError('test', ('test', 'oneof'),
errors.ONEOF, schema['test']['oneof'],
v_errors=_errors)
# check that allow_unknown is actually applied
document = {'test': {'known': 's', 'unknown': 'asd'}}
self.assertNormalized(document, document, schema)


class TestDefinitionSchema(TestBase):
def test_empty_schema(self):
Expand Down
2 changes: 1 addition & 1 deletion cerberus/validator.py
Expand Up @@ -931,7 +931,7 @@ def __validate_logical(self, operator, definitions, field, value):
for rule in ('allow_unknown', 'type'):
if rule not in schema[field] and rule in self.schema[field]:
schema[field][rule] = self.schema[field][rule]
if 'allow_unknown' not in schema:
if 'allow_unknown' not in schema[field]:
schema[field]['allow_unknown'] = self.allow_unknown

validator = self._get_child_validator(
Expand Down

0 comments on commit 7c8b3c3

Please sign in to comment.