I want to load fixtures into django. The data has some date
fields - is it possible to create these data so they will always be e.g. yesterday or tomorrow? I want to make sure certain data is always fresh, but also so I can easily test edge cases (e.g. whether an object is enabled if the publishing date is today, etc).
Fixtures just load text data files (in JSON/XML/YAML) so, there's no real way to insert dynamically generated data by just loading a fixture. On the other hand, you can get around this using other methods.
One option is the package django-fixture-generator where you can write python/django code to create data and it will be inserted before your tests are called.
Another option is a previous SO question: How to load sql fixture in Django for User model?. This has some code on using SQL files for fixtures, where you can use a SQL expression for your date requirements (e.g. GETDATE()+1 or similar in your SQL dialect).
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