Permalink
Browse files

Merge 1144905 into f41dce5

  • Loading branch information...
elecay committed Mar 17, 2017
2 parents f41dce5 + 1144905 commit 371104953de17ec8d9a301985a49af67edbc0243
Showing with 20 additions and 3 deletions.
  1. +15 −0 cerberus/tests/test_normalization.py
  2. +1 −1 cerberus/tests/test_schema.py
  3. +4 −2 cerberus/validator.py
@@ -412,3 +412,18 @@ def test_allow_unknown_with_of_rules():
# check that allow_unknown is actually applied
document = {'test': {'known': 's', 'unknown': 'asd'}}
assert_success(document, schema)
+
+
+def test_271_normalising_tuples():
+ # https://github.com/pyeve/cerberus/issues/271
+ schema = {
+ 'my_field': {
+ 'type': 'list',
+ 'schema': {'type': 'string'}
+ }
+ }
+ document_success = {'my_field': ('foo', 'bar')}
+ assert_success(document_success, schema)
+
+ document_fail = {'my_field': (1, 2)}
+ assert_fail(document_fail, schema)
@@ -82,7 +82,7 @@ def test_validated_schema_cache():
v = Validator({'foozifix': {'coerce': int}})
assert len(v._valid_schemas) == cache_size
- max_cache_size = 126
+ max_cache_size = 127
assert cache_size <= max_cache_size, \
"There's an unexpected high amount (%s) of cached valid " \
"definition schemas. Unless you added further tests, " \
View
@@ -666,8 +666,10 @@ def __normalize_sequence(self, field, mapping, schema):
document_crumb=field, schema_crumb=(field, 'schema'),
schema=schema)
result = validator.normalized(document, always_return_document=True)
- for i in result:
- mapping[field][i] = result[i]
+ if type(mapping[field]) is tuple:
+ mapping[field] = tuple(result.values())
+ else:
+ mapping[field] = result.values()
if validator._errors:
self._drop_nodes_from_errorpaths(validator._errors, [], [2])
self._error(validator._errors)

0 comments on commit 3711049

Please sign in to comment.