Tests
Setting Up
There are end-to-end tests in this solution, located in the _tests
directory. We use pytest
to run tests. Tests must use environment variables from _env/test.env
in the environment.
To simplify tests and ensure all business details of the solution are functioning, tests are written as a customer journey—ordered step-by-step usage of the system by customers, ensuring all functionalities work.
Testing Actors
To facilitate quick testing of endpoints, we have created test actors—special classes that allow making API requests as specific users, either anonymous or logged in.
Actors in tests are primarily responsible for sending requests and providing responses. To simplify future work, we recommend creating additional layers. For example, in Django with pytest, abstract the client into protected values in a class.
Test Helpers
We have also implemented a ResponseChecker
abstraction to consolidate rules and eliminate repetitive response checks. This approach uses predefined methods instead of repeating similar checks. Pagination is an excellent example: if your project requires a specific pagination structure, you can add it to ResponseChecker
to validate individual elements.
Additionally, with normalized errors transformed into responses, you can check their structure and content. In our project, an error class automatically generates a specific response via middleware that catches errors and builds responses. This ensures the API creates user-friendly responses during errors:
Coverage
The current coverage is 80%. To check the current test coverage, use the following pytest command: