-
Notifications
You must be signed in to change notification settings - Fork 0
Testing
To run all backend Unit and Integration tests, you can use:
docker exec -it pigeonhole-backend python manage.py test backend/
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
To quickly fill the database with dummy data to test the application:
docker exec -it pigeonhole-backend python manage.py loaddata backend/fixtures.json
Following should be tested in the modeltests:
- Creating, updating, deleting every object
- Validating model fields
- Relations between models
- Content of the database
- Later: file structure
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. Setup will be re-executed for every test.
For every class we test:
- Every route with valid id's
- Every route with invalid id's (when multiple id's verify for all)
- Relations between fields (example: are dates correct?)
- Every action should be tested performed by every actor, because most actions differ between different authentication levels
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: the teacher is allowed to acces all his objects and create all objects, when accessing actions of another teacher the response should return HTTP_403_FORBIDDEN
- Student: a student is only allowed to manage his own submissions and view the objects to which it has acces, otherwise return HTTP_403_FORBIDDEN
- Unauthorised: every response should return HTTP_403_FORBIDDEN
When an action is both invalid and forbidden, the forbidden response code should be returned or else non authorised user could get knowledge of the information in the database. Successful action response codes: status.HTTP_200_OK, HTTP_201_CREATED, HTTP_204_NO_CONTENT
To run the component tests in the docker container you can run this command, before running this command make sure your docker container is running:
make componenttest
Or:
docker exec -it pigeonhole-frontend npx jest
To run the end-to-end tests you first need to make sure you have all packages installed in the correct directory:
cd frontend/
npm i
After installing all the packages, you need to make sure the database is filled with the correct mockdata. You can do this by executing this command:
make mockdata
After making sure all the packages are installed and the databse is filled with the mockdata, you can start the docker container. Now you can run the end-to-end tests by executing this command in the frontend directory:
npx cypress open
Here you select E2E Testing, after this you can select any browser, this step does not matter. When you arrive on the homescreen you can select the specific tests you want to run, or you can run all of the tests.