Skip to content

Testing

Pieter-Jan De Smijter edited this page Mar 11, 2024 · 19 revisions

Backend testing

Django Testing

To run all backend Unit and Integration tests, you can use:

docker exec -it pigeonhole-backend python manage.py test backend/

Django coverage

To get an overview of the code's coverage, use:

docker exec -it pigeonhole-backend coverage run manage.py test backend/

docker exec -it pigeonhole-backend coverage report

Fill database with testdata

To quickly fill the database with dummy data to test the application:

docker exec -it pigeonhole-backend python manage.py loaddata backend/fixtures.json

Model testing guidelines

TODO

API testing guidelines

4 Django TestCase classes for every view, each in a seperate file:

  • Admin Teacher
  • Teacher
  • Student
  • Unauthorised

A Testcase is a closed test that creates a mock database in RAM. Tests are executed sequentially, so note that tests in one TestCase influence each other.

For every class we test:

  • Every route
  • Every route with invalid id's (when multiple id's verify for all)
  • Relations between fields (example: are dates correct?)

We use different response status codes in the API, as is illustrated for every authentication level below:

  • Admin Teacher: the admin is allowed to perform every valid action, every invalid action should throw a HTTP_404_NOT_FOUND
  • Teacher
  • Student:
  • Unauthorised: every response should return HTTP_403_FORBIDDEN

Sucessful action response codes: status.HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT

Clone this wiki locally