Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'} |