Test-Driven API Development with Django REST Framework

By Kevin Harvey

Elevator Pitch

The tools available in Django REST Framework allow rapid development of web APIs, and it’s easy-to-use wrappers around Django and Python’s testing toolkit make it easy to include a comprehensive test suite in any application. This is for folks new to DRF & testing in general.


Test-driven development (TDD) allows developers to begin with the end in mind. In this talk, we’ll cover the basics of using TDD to develop a web API with the popular Django REST Framework. Attendees will receive a quick overview of both TDD and DRF from which they can continue to explore.

We’ll begin with an outside-in integration test that describes an entire application endpoint. Then we’ll use test-first principles to fill in the missing functionality by writing unit tests that fail before writing URLs, views, serializers, and models. We’ll end with a refactor to make the code more readable, safely improving the code while our test suite ensures the features stay intact.


I was slated to gave this talk at PyTN 2018, but unfortunately had to cancel. Subsequently, I gave this talk at PyNash in February 2018. I’ve written a book on TDD with Django, and use DRF and TDD every day in my professional life.