Skip to content

Commit

Permalink
Merge pull request #588 from borgstrom/nested-model-dict-list
Browse files Browse the repository at this point in the history
Add test coverage for model validation inside Dict/List
  • Loading branch information
lkraider authored Aug 13, 2021
2 parents ce3b8bd + 4ef8731 commit cfd7176
Showing 1 changed file with 28 additions and 3 deletions.
31 changes: 28 additions & 3 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,36 @@ def validate_should_raise(self, data, value, context):

class MainModel(Model):
modelfield = ModelType(SubModel)
named_modelfield = DictType(ModelType(SubModel))
listed_modelfield = ListType(ModelType(SubModel))

with pytest.raises(DataError):
MainModel({'modelfield': {'should_raise': True}}).validate()

MainModel({'modelfield': {'should_raise': False}}).validate()
try:
MainModel({
'modelfield': {'should_raise': True},
'named_modelfield': {
'one': {'should_raise': True}
},
'listed_modelfield': [
{'should_raise': True},
]
}).validate()
except DataError as exc:
assert len(exc.errors) == 3
assert exc.errors['listed_modelfield'][0]['should_raise'][0].summary == 'message'
assert exc.errors['named_modelfield']['one']['should_raise'][0].summary == 'message'

raise

MainModel({
'modelfield': {'should_raise': False},
'named_modelfield': {
'one': {'should_raise': False}
},
'listed_modelfield': [
{'should_raise': False},
]
}).validate()


def test_multi_key_validation():
Expand Down

0 comments on commit cfd7176

Please sign in to comment.