Skip to content

Commit

Permalink
tests: added test for nestedattr
Browse files Browse the repository at this point in the history
  • Loading branch information
cenouralm committed Oct 21, 2020
1 parent 1f43dae commit 7b4ef06
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions tests/test_nestedattr.py
@@ -0,0 +1,44 @@
from datetime import date
from pprint import pprint

from marshmallow import Schema, fields

from marshmallow_utils.fields import nestedattr


class ArtistSchema(Schema):
"""Artist Schema."""

name = fields.Str()


class AlbumSchema(Schema):
"""Album Schema."""

artist = nestedattr.NestedAttribute(ArtistSchema())


class MyAlbum(dict):

@property
def artist(self):
return {'name': 'property'}


album = MyAlbum(
artist={'name': 'david'}, # this shouldn't be used by the schema
title="Hunky Dory",
release_date=date(1971, 12, 17)
)


def test_test_schema():
album = MyAlbum(
title="Hunky Dory",
release_date=date(1971, 12, 17)
)

schema = AlbumSchema()
result = schema.dump(album)

assert result['artist'] == {'name': 'property'}

0 comments on commit 7b4ef06

Please sign in to comment.