Skip to content

Commit

Permalink
Added test_tc004.py
Browse files Browse the repository at this point in the history
  • 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.
71 changes: 71 additions & 0 deletions backend/tests/test_tc004.py
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

0 comments on commit 5b029ff

Please sign in to comment.