I could use pytest for testing models and views in my django project. Is it possible to use pytest for DRF serializers as well, appreciate pointers to samples.
The following works:
def test_foo_serializer():
from app.models import Model
from app.serializers import ModelSerializer
serializer = ModelSerializer()
f = serializer.fields['field_name']
obj = Model()
assert f.to_representation(obj) == '0.00'
obj.prop = 123
assert f.to_representation(obj) == '1.23'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With