forked from mathialm/secfit
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jonas Säuberlich
authored and
GitHub Enterprise
committed
Mar 27, 2025
1 parent
bb1d943
commit 5b029ff
Showing
1 changed file
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| from rest_framework.test import APITestCase | ||
| from django.contrib.auth import get_user_model | ||
|
|
||
| class TestTC004(APITestCase): | ||
| """ | ||
| TestTC004 is a test case class designed to validate the behavior of the API when creating offers between users. | ||
| This test case includes: | ||
| - Validation of error handling when the recipient user does not exist (`test_non_existing_user`). | ||
| - Validation of error handling when the recipient is not a coach (`test_non_coach_user`). | ||
| - Validation of successfully creating a valid offer to a coach (`test_valid_offer`). | ||
| The tests ensure that the API correctly handles offer creation, including proper validation of recipient users and their roles. | ||
| """ | ||
| def setUp(self): | ||
| self.athlete = get_user_model().objects.create_user( | ||
| username="athlete", | ||
| email='athlete@example.com', | ||
| password="athletetest" | ||
| ) | ||
|
|
||
| self.coach = get_user_model().objects.create_user( | ||
| username="coach", | ||
| email='coach@example.com', | ||
| password="coachtest", | ||
| isCoach=True, | ||
| specialism="specialism" | ||
| ) | ||
|
|
||
| self.client.force_authenticate(self.athlete) | ||
|
|
||
|
|
||
| def test_non_existing_user(self): | ||
| response = self.client.post( | ||
| "/api/offers/", | ||
| { | ||
| "recipient": "/api/users/999999/", | ||
| "status": "p", | ||
| }, | ||
| format="json" | ||
| ) | ||
| print(f"Response data: {response.data}") | ||
| print(f"Response status code: {response.status_code}") | ||
| assert response.status_code == 400 | ||
|
|
||
| def test_non_coach_user(self): | ||
| response = self.client.post( | ||
| "/api/offers/", | ||
| { | ||
| "recipient": f"/api/users/{self.athlete.id}/", | ||
| "status": "p", | ||
| }, | ||
| format="json" | ||
| ) | ||
| print(f"Response data: {response.data}") | ||
| print(f"Response status code: {response.status_code}") | ||
| assert response.status_code == 400 | ||
|
|
||
| def test_valid_offer(self): | ||
| # Add the coach as coach and store offer url to accept the offer | ||
| response = self.client.post( | ||
| "/api/offers/", | ||
| { | ||
| "recipient": f"/api/users/{self.coach.id}/", | ||
| "status": "p", | ||
| }, | ||
| format="json" | ||
| ) | ||
| print(f"Response data: {response.data}") | ||
| print(f"Response status code: {response.status_code}") | ||
| assert response.status_code == 201 |