Think Build Implement Repeat
London, UK +44 7367 067226
WhatsApp FOLLOW f in X
  1. Home
  2. Blog
  3. Confidence to Change Things
Python & Django

Confidence to Change Things

A practical testing approach for Django business applications: test the business rules, permissions and calculations, plus query-count checks on key pages.

Updated 2 min readBy SpiderHunts Technologies

Free estimateNo obligation

Get a free estimate

Tell us what you need. A senior engineer reads every enquiry.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →

Quick answer — TL;DR

Test the business rules, the permissions and the calculations. A handful of view tests covering the main journeys catches more real problems than exhaustive unit tests.

Test what would be expensive to get wrong

  1. Calculations — pricing, tax, anything with arithmetic
  2. Permissions — who can see and do what, including cross-user access
  3. Business rules — the conditions that govern the workflow
  4. Integrations — including what happens when they fail
  5. Anything that has broken before
Permission tests are the ones most often missing and the ones with the most serious consequences. Test that user A cannot reach user B's records, explicitly.

Different tests for different jobs

TypeCovers
Model testsBusiness rules and validation
View testsComplete request-response journeys
Permission testsWho can access what
Form testsValidation, including failure cases
Task testsBackground work, run synchronously

Use realistic data

  • Factories that produce plausible records, not minimal ones
  • The awkward cases that broke it before
  • Empty and boundary conditions
  • Volumes large enough to catch query problems

Assert query counts

A test that asserts a page issues no more than a set number of queries catches performance regressions before they reach production.

It is one of the highest-value test types in a Django application and it is rarely written.

Run them automatically

On every push, blocking a merge on failure. Tests that require someone to remember to run them stop being run within a month.

That is a day of setup and it is what turns a test suite into a safety net rather than an intention.

FAQ

Frequently asked questions

The questions readers ask us after this guide.

Still have a question?

Ask us directly — a senior engineer will get back to you.

Ask about your project

How much coverage is enough?

Enough to change the code confidently. Usually the business rules, permissions and calculations rather than every line.

Should tests use a real database?

Yes — Django's test runner creates one. Mocking the database tests your mocks rather than your queries.

Are view tests worth it?

Very. A small number covering the main journeys catches more real problems than a large number of unit tests.

How do we test legacy Django code?

Characterisation tests at the view level first, then narrow down as you refactor.

Keep reading

More on Python & Django

Python & Django

An API Other Systems Can Depend On

Designing a Python API service others can depend on: validation at the boundary, consistent errors and status codes, early versioning and documentation.

Python & Django

Moving and Transforming Data Reliably

Building data pipelines in Python that cope with malformed input: restartable stages, quarantining failures, reconciling counts and alerting on absence.

Start here

Afraid to change your own application?

Start with permissions and calculations. Those are where the expensive mistakes are.

  1. You tell us what you needTwo minutes on the form, or a message on WhatsApp.
  2. A senior engineer reviews itAnd comes back with questions, a realistic range and an honest view on fit.
  3. Free 30-minute scoping callWe talk through scope, options and a realistic estimate — with no obligation.
Free estimateNo obligation

Talk to someone who builds this

Send a short brief and we will come back with an honest view and a realistic range.

Takes under a minute. We never share your details.

  • Free consultation
  • No commitment
  • NDA on request

Prefer to talk? Book a free 30-minute call →