Skip to content

Commit

Permalink
test: add example of nested models parsing with default_factory
Browse files Browse the repository at this point in the history
closes #1717
  • Loading branch information
PrettyWood committed Jul 13, 2020
1 parent 458dc13 commit 16e489b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion changes/1710-PrettyWood.md
@@ -1 +1 @@
fix validation of nested models with `default_factory`
fix validation and parsing of nested models with `default_factory`
13 changes: 13 additions & 0 deletions tests/test_main.py
Expand Up @@ -1186,6 +1186,19 @@ class Parent(BaseModel):
Parent(children=[{'x': 1}, {'y': 2}])


def test_default_factory_parse():
class Inner(BaseModel):
val: int = Field(0)

class Outer(BaseModel):
inner_1: Inner = Field(default_factory=Inner)
inner_2: Inner = Field(Inner())

default = Outer().dict()
parsed = Outer.parse_obj(default)
assert repr(parsed) == 'Outer(inner_1=Inner(val=0), inner_2=Inner(val=0))'


@pytest.mark.skipif(sys.version_info < (3, 7), reason='field constraints are set but not enforced with python 3.6')
def test_none_min_max_items():
# None default
Expand Down

0 comments on commit 16e489b

Please sign in to comment.