Skip to content

Commit

Permalink
Add test for a bound serializer
Browse files Browse the repository at this point in the history
  • Loading branch information
Jared Deckard authored and Jared Deckard committed Jun 23, 2016
1 parent 14bdbfb commit 57b5339
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tests/test_schema.py
Expand Up @@ -1550,6 +1550,22 @@ class UserFunctionContextSchema(Schema):
msg = 'No context available for Function field {0!r}'.format('is_collab')
assert msg in str(excinfo)

def test_function_field_handles_bound_serializer(self):
class SerializeA(object):
def __call__(self, value):
return 'value'
serialize = SerializeA()
# only has a function field
class UserFunctionContextSchema(Schema):
is_collab = fields.Function(serialize)

owner = User('Joe')
serializer = UserFunctionContextSchema(strict=True)
# no context
serializer.context = None
data = serializer.dump(owner)[0]
assert data['is_collab'] is 'value'

def test_fields_context(self):
class CSchema(Schema):
name = fields.String()
Expand Down

0 comments on commit 57b5339

Please sign in to comment.