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:
- Develop a RESTful API with Python, Django, and Django REST Framework
- Practice Test-Driven Development
- Test a Django app with pytest
- Containerize Django and Postgres inside a Docker container
- Run unit and integration tests with code coverage inside a Docker container
- Create a custom User model in Django
- Implement an API with Django REST Framework Views and Serializers
- Check your code for any code quality issues via a linter
- Configure GitLab CI for continuous integration and deployment
- Speed up a Docker-based CI build with Docker Cache
- Deploy Django, Gunicorn, and Postgres to Heroku with Docker
- Manage static assets with WhiteNoise
- Create a production Dockerfile that uses multistage Docker builds
- Document a RESTful API with Swagger/OpenAPI and Core API
- Parameterize test functions and mock functionality in tests with pytest
- Run tests in parallel with pytest-xdist
Tools and Technologies
Core
- Python
- Django
- Docker
- Postgres
- Django REST Framework
- Gunicorn
- WhiteNoise
Testing and Linting
- pytest
- Coverage.py
- Flake8
- Black
- isort
- HTTPie
Services
- GitLab
- Heroku
- Swagger/OpenAPI
Prerequisites
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!
Demo
Info
- Current version: 3.1.0
- Last updated: January 12th, 2021
- Author: Michael 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
- Introduction
- Changelog
- Getting Started
- Docker Config
- Postgres Setup
- Pytest Setup
- Django REST Framework
- RESTful Routes
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.