Skip to content

Commit

Permalink
test: add example with parse of nested models
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 52ca25a
Showing 1 changed file with 13 additions and 0 deletions.
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 52ca25a

Please sign in to comment.