In the unit test, I am testing a patch method.
In the patch method, I need to provide a model object.
1) Use production database
I can have a model object from the production database as follow.
- Fetch a record from database: place=Place.objects.filter()[:1]
with open('praticeapp/fixtures/test_data.json', 'w') as f: serializers.serialize('json', place, indent=4, stream=f)
Load fixture in test database
management.call_command(loaddata.Command(), 'praticeapp/fixtures/test_data', verbosity=0)
2) Create model object
In the second option, I can create place object directly.
I am considering first option becaues in real model i have many models with many fields.
If any of the field will be change in future, testing will stop working. I have also found first option from django official documentation but in first option i have to write more code compare to second one.
I am not able to decide which option is better.
Thank you in advance.