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

  • Updated July 24th, 2024
  • v3.2.1
Michael Herman Michael Herman

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


In this course, you'll learn how to set up a development environment with Docker in order to build and deploy a microservice powered by Python, Django, and Django REST Framework. You'll also apply the practices of Test-Driven Development with pytest as you develop a RESTful API.

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

Various logos sitting around an Octopus

What will you learn?

Select a Part

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).

Learning Objectives

  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
  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

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.

Learning Objectives

  1. Configure GitLab CI for continuous integration and deployment
  2. Speed up a Docker-based CI build with Docker Cache
  3. Deploy Django, Gunicorn, and Postgres to Heroku with Docker
  4. Manage static assets with WhiteNoise
  5. Create a production Dockerfile that uses multistage Docker builds
  6. Parameterize test functions and mock functionality in tests with pytest
  7. Run tests in parallel with pytest-xdist

What do you need to know?

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:

Django

Meet the Author

Michael Herman

Michael Herman

Michael is a software engineer and educator who lives and works in the Denver/Boulder area. He is the co-founder/author of Real Python. Besides development, he enjoys building financial models, tech writing, content marketing, and teaching.

What developers are saying

I struggled for a long time figuring out the best way to use Docker in development. The Docker workflow presented in the Test-Driven Development with Django, Django REST Framework, and Docker course is by far the best I've come across.

The Test-Driven Development with Django, Django REST Framework, and Docker course gave me the clear explanations and focus I needed! As a junior developer I often get stuck, overwhelmed, and lost in so many details. Completing this course gave me the overview and knowledge needed to start my own projects with confidence. The code examples are a good foundation for future projects. This is quality content!

After taking the Test-Driven Development with Django, Django REST Framework, and Docker course, I feel much more confident in developing production-ready code. There are a lot of helpful details covered, like setting up dev and prod environment configurations, CI/CD deployment processes, testing and documentation, and so on, that I haven't seen in other courses. You can scour the internet looking on Youtube or other learning platforms but I have yet to come across material that covers end-to-end development for the Python web stack with such clarity and quality of information!

The TestDriven.io courses are second to none. I've taken the Test-Driven Development with Django, Django REST Framework, and Docker course and have found it to be the perfect concentrate. The author, Michael Herman, manages to cover a really broad range of technologies and conveys the information in such way that each snippet gives me something new to learn while keeping momentum. I'm now confident in my deployment strategy and am looking forward to doing the next course. Keep up the good work!

I am very much into buying and purchasing any course by you and your team. I've never felt like a better programmer ready to show my coding chops to the world.

Frequently Asked Questions

What tools and technologies are used in this course?

This course covers a variety of technologies and services:

Core

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

Testing and Linting

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

Services

  1. GitLab
  2. Heroku

What support does TestDriven.io offer?

Since the courses mimic real-world development, support is provided via Stack Overflow. Helpful users, including the developers of the courses, read and respond to messages on Stack Overflow. If you get stuck and you can't find an answer via Stack Overflow, feel free to reach out via email directly. Just be sure to detail what you've tried. For more, review Support and Consulting.

How long does it take to complete the course?

It's dependent on your current skill level. On average, it takes approximately 10 hours to complete.