Testing the admin

Series: Admin Testing

  1. Testing the admin
  2. Testing the admin - part 2

When using a framework like Django, there is a trap you can fall into of writing tests that the framework will have already covered. A good example of this is form rendering, if you have the following form:

class MyForm(forms.Form):
  title = forms.CharField()
  description = forms.CharField()

that gets rendered in a template with {{ form }} or {{ form.as_p }}. Now it would seem logical to have a test that checks that the form has rendered correctly, but this would just be a duplicate of a test somewhere in Django that already exists. This is the trap!

Testing any custom logic within the form would be suitable, but not the default rendering.

I have found one exception to this in a few codebases I have worked on over the years. It can be sensible to test all the admin views from your codebase. Yes, Django will have some tests, but the admin can easily break with some misconfiguration which some view tests can catch.

Tomorrow I will provide those tests for you to dump into your own project if you so desire!