Speeding up your django tests

Running tests can become troublesome, if your tests take too long to execute. Ideally, you want an instant feedback from them. Lets us discuss some ways through which we can speed up the run time for our tests. Move data creation to setUpTestData setUpTestData is pretty much like setUpClass in unittest. This method is run once before the test class runs. One of the main reasons, tests can be slow is if data creation in done in setUp method or inside individual tests....

March 1, 2021 · 4 min

Writing unit tests for migrations in django

Writing tests for migration can be a bit tricky because all of your migrations are generally run before any of your test. In case you want to test your code for a particular migration, you will have to revert the database to that particular state. Make sure you don’t forget to revert to the latest state after this test ends. In this post, we will see who we can do this....

March 1, 2021 · 3 min

Add tests to verify registry of models to django admin

In the last post, we learned how to automate registration of models to the django-admin. In this post, we will try to see how we can add tests to verify that all our models have been registered. Why do we need it? Even though the admin.py module is run internally when running the tests, it doesn’t actually verify whether all models have been registered or not. It is a very common thing to forget registering your model to the admin, especially when you aren’t really customizing them....

July 1, 2021 · 2 min

Separate development and production settings for a django project

When I first started working on Django, I used to edit the settings file every time I had to push the code to deployment. Change the value of DEBUG, read the values for SECURITY_KEY from a config file and many other settings. It used to be a really painful experience and I would curse myself every time I had to do that. Then, one fine day I decided that I have had enough and thought of finding ways through which I don’t need to make any changes when I push my code into deployment....

February 1, 2021 · 4 min

An awesome django filter for displaying numbers

Displaying large numbers like 1234, 1243423, etc. in their raw form can be less intuitive for viewers. Such large numbers make it difficult to calculate the actual value of the number. Hence I thought of making a filter inside my Django application(you may call it app), for displaying numbers in a more informative format(and awesome too, I guess). The file structure and format might be specific to Django, but the logic can be used in any other framework or language....

April 1, 2021 · 4 min

Automating registry of django models to the admin

Registering models to django-admin(in general) is not much of a task, but is mostly boring. Many times it might feel like doing a chore. In this post, we’ll try to see how we can automate this process. Registering models Normally, models are registered inside the admin.py module of the apps. To automatically register all of our models, we can directly add these lines of code to this file. from django.contrib import admin from django....

April 1, 2021 · 2 min