In this lesson, we will explore testing complex API functionalities in the Django REST Framework, specifically filtering, sorting, and pagination. Testing these features ensures that our API behaves as expected when handling various user queries. By the end of this lesson, you will have the knowledge to write comprehensive test cases for these operations and combine them to test more complex scenarios effectively.
Note: In this lesson, we will consider only the basic setup for such tests. If you want to learn more about testing in the Django REST API and how to build stable tests that cover all the required behavior, check out the Advanced Testing for Django REST FRAMEWORKS app course path (coming soon).
Before we start with the new tests, let's briefly recap the setup of our Django project. In previous course, we covered filtering, sorting and pagination for your views. Here's a quick summary of the core components we'll use in this lesson:
We use a fixture stored in myapp/fixtures/todos.json
to ensure consistent test data:
We will use a custom filter:
