Test-Driven Development with Django, Django REST Framework, and Docker

Learn how to build, test, and deploy a Django app with Docker, pytest, and Django REST Framework!

"Code without tests is broken by design." - Jacob Kaplan-Moss

Learning Objectives

By the end of this course, you will be able to:

  1. Develop a RESTful API with Python, Django, and Django REST Framework
  2. Practice Test-Driven Development
  3. Test a Django app with pytest
  4. Containerize Django and Postgres inside a Docker container
  5. Run unit and integration tests with code coverage inside a Docker container
  6. Create a custom User model in Django
  7. Implement an API with Django REST Framework Views and Serializers
  8. Check your code for any code quality issues via a linter
  9. Configure GitLab CI for continuous integration and deployment
  10. Speed up a Docker-based CI build with Docker Cache
  11. Deploy Django, Gunicorn, and Postgres to Heroku with Docker
  12. Manage static assets with WhiteNoise
  13. Create a production Dockerfile that uses multistage Docker builds
  14. Document a RESTful API with Swagger/OpenAPI and Core API
  15. Parameterize test functions and mock functionality in tests with pytest
  16. Run tests in parallel with pytest-xdist

Tools and Technologies


  1. Python
  2. Django
  3. Docker
  4. Postgres
  5. Django REST Framework
  6. Gunicorn
  7. WhiteNoise

Testing and Linting

  1. pytest
  2. Coverage.py
  3. Flake8
  4. Black
  5. isort
  6. HTTPie


  1. GitLab
  2. Heroku
  3. Swagger/OpenAPI

django tdd logo


This is not a beginner course. It's designed for the advanced-beginner -- someone with at least six months of web development experience. Before beginning, you should have some familiarity with the following topics. Refer to these resources for more info:

Topic Resource
Docker Get started with Docker
Docker Compose Get started with Docker Compose
Django Django Tutorial

Looking for a solid introduction to Django? Check out Django for Beginners. Highly recommended!



  • Current version: 3.1.0
  • Last updated: January 12th, 2021
  • AuthorMichael Herman

What will you learn?

Part 1

In this first part, you'll learn how to develop a RESTful API with Python, Django, Django REST Framework, and Postgres. You'll containerize Django and Postgres to run inside Docker containers and configure pytest in order to practice Test-Driven Development (TDD).

Part 2

In the second part, you'll start by deploying Django, Gunicorn, and Postgres to Heroku with Docker. You'll then continue to build out the RESTful API as you write unit and integration tests. Finally, we'll look at how to document the API with Swagger.

Table of Contents

Table of contents from Test-Driven Development with Django, Django REST Framework, and Docker:

Part 1
Part 2
  • Deployment
  • Code Coverage and Quality
  • Continuous Integration
  • Continuous Delivery
  • Remaining Routes
  • Pytest Monkeypatching
  • Advanced CI
  • API Documentation
  • Workflow
  • Structure
  • Next Steps

Get the full course:

Join our mailing list to be notified about course updates and new tutorials.