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. Pytest
  6. Django REST Framework
  7. Gunicorn
  8. Coverage.py
  9. flake8
  10. Black
  11. isort
  12. HTTPie
  13. GitLab
  14. Heroku
  15. WhiteNoise
  16. 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: 1.0.0
  • Last updated: January 22nd, 2020
  • AuthorMichael Herman

Table of Contents

  • Introduction
  • Changelog
  • Getting Started
  • Docker Config
  • Postgres Setup
  • Pytest Setup
  • Django REST Framework
  • RESTful Routes
  • Deployment
  • Code Coverage and Quality
  • Continuous Integration
  • Continuous Delivery
  • Remaining Routes
  • Pytest Monkeypatching
  • Advanced CI
  • API Documentation
  • Workflow
  • Structure

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