How to properly document and test models with natural keys

15 views
Skip to first unread message

Olivier

unread,
Mar 29, 2021, 9:59:12 AM3/29/21
to Django users
Hello,

I'm thinking about adding natural keys to a lot of existing models (Djano 3.1.7) to help initializing dev or prod database.

1. How best to unit test  models using natural keys ?
I was thinking of separately testing  both serialization and deserialization but would be very curious to learn about examples or alternatives, specifically when Foerign key relations existe between models.

2. For any unit test, you may have to hand write a YAML sample.
How is it best to write this sample ?

3. Suggestions. Recommendations. Pointers ?

Best regards

Anusheel Bhushan

unread,
Apr 11, 2021, 3:37:40 PM4/11/21
to Django users
HI Olivier - 
Django typically has separate settings files for each environment. You can also use different environment variables to use when starting the app.
RE: models, here's an example of serialization that could be helpful to show how to serialize/deserialize models with foreign keys : https://github.com/imagineai/create-django-app/blob/master/todoapp/serializers.py

re: unit tests, see some examples of serializers here: https://github.com/imagineai/create-django-app/tree/master/todoapp/tests

Both the serializers and the tests above are generated (from a yaml type config).

Happy to answer more specific qs...
Reply all
Reply to author
Forward
0 new messages