def test_to_representation(media_resource_factory, serializer_context):
"""
``.to_representation()`` should return the serialized version of the
provided media resource.
"""
resource = media_resource_factory()
serializer = MediaResourceSerializer(resource, context=serializer_context)
with mock.patch(
'know_me.serializers.fields.MediaResourceField.context',
new_callable=mock.PropertyMock) as mock_context:
mock_context.return_value = serializer_context
field = fields.MediaResourceField()
assert field.to_representation(resource) == serializer.data
评论列表
文章目录