diff --git a/backend/media/users/2/file_a_0NHVzHH.png b/backend/media/users/2/file_a_0NHVzHH.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_0NHVzHH.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_1wrH3vY.png b/backend/media/users/2/file_a_1wrH3vY.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_1wrH3vY.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_67CtuBp.png b/backend/media/users/2/file_a_67CtuBp.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_67CtuBp.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_94cIg3T.png b/backend/media/users/2/file_a_94cIg3T.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_94cIg3T.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_CHepTi2.png b/backend/media/users/2/file_a_CHepTi2.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_CHepTi2.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_FGN1pdv.png b/backend/media/users/2/file_a_FGN1pdv.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_FGN1pdv.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_GyNvAlP.png b/backend/media/users/2/file_a_GyNvAlP.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_GyNvAlP.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_TbgaYSG.png b/backend/media/users/2/file_a_TbgaYSG.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_TbgaYSG.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_UASK90p.png b/backend/media/users/2/file_a_UASK90p.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_UASK90p.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_tgxosyw.png b/backend/media/users/2/file_a_tgxosyw.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_tgxosyw.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_vskAVv6.png b/backend/media/users/2/file_a_vskAVv6.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_vskAVv6.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/media/users/2/file_a_wasCFXR.png b/backend/media/users/2/file_a_wasCFXR.png new file mode 100644 index 0000000..f4dbe63 --- /dev/null +++ b/backend/media/users/2/file_a_wasCFXR.png @@ -0,0 +1 @@ +dummy content \ No newline at end of file diff --git a/backend/tests/test_004.py b/backend/tests/test_004.py index 088f4f0..a85a8fd 100644 --- a/backend/tests/test_004.py +++ b/backend/tests/test_004.py @@ -19,29 +19,16 @@ class TestSpecialCharacterFileName(TestCase): def setUp(self): # Create a test user (coach) User = get_user_model() - self.coach = User.objects.create_user( - username="test_coach", - password="password123", - isCoach=True - ) + self.coach = User.objects.create_user( username="test_coach", password="password123", isCoach=True) # Create an athlete and assign the coach - self.athlete = User.objects.create_user( - username="test_athlete", - password="password123", - isCoach=False, # Ensure the user is an athlete - coach=self.coach # Assign the coach - ) + self.athlete = User.objects.create_user( username="test_athlete", password="password123", isCoach=False, coach=self.coach) # Generate a JWT token for the coach self.token = str(AccessToken.for_user(self.coach)) # Create a workout for the athlete - self.workout = Workout.objects.create( - owner=self.athlete, - name="Test Workout", - date=now() - ) + self.workout = Workout.objects.create(owner=self.athlete, name="Test Workout", date=now()) def test_upload_file_with_special_characters_in_name(self): """ @@ -59,9 +46,7 @@ def test_upload_file_with_special_characters_in_name(self): 5. Verify the file is associated with the correct owner and athlete. """ # Create a file with special characters in its name - special_char_file = SimpleUploadedFile( - "file@#$ %&()a.png", b"dummy content", content_type="image/png" - ) + special_char_file = SimpleUploadedFile("file@#$ %&()a.png", b"dummy content", content_type="image/png") #Upload file response = self.client.post( diff --git a/backend/tests/test_005.py b/backend/tests/test_005.py new file mode 100644 index 0000000..444f02f --- /dev/null +++ b/backend/tests/test_005.py @@ -0,0 +1,75 @@ +''' +# This is for coverage testing independent of manage.py +import os +import django +import sys +sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) +os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'secfit.settings') +django.setup() +''' + +from django.test import TestCase +from django.contrib.auth import get_user_model +from workouts.models import Workout +from django.utils.timezone import now +from rest_framework_simplejwt.tokens import AccessToken + +User = get_user_model() + +class TestCoachViewAthleteWorkouts(TestCase): + def setUp(self): + # Create coach and athlete + self.coach = User.objects.create_user(username="test_coach", password="password123", isCoach=True) + self.athlete = User.objects.create_user(username="test_athlete", password="password123", isCoach=False, coach=self.coach) + + # Create workouts for the athlete + self.workout1 = Workout.objects.create(name="Workout 1", owner=self.athlete, date=now()) + self.workout2 = Workout.objects.create(name="Workout 2", owner=self.athlete, date=now()) + + # Create another athlete not assigned to the coach + self.other_athlete = User.objects.create_user(username="other_athlete", password="password123", isCoach=False) + + # Create workouts for the other athlete + self.other_workout1 = Workout.objects.create(name="Other Workout 1", owner=self.other_athlete, date=now()) + self.other_workout2 = Workout.objects.create(name="Other Workout 2", owner=self.other_athlete, date=now()) + + # Generate a JWT token for the coach + self.token = str(AccessToken.for_user(self.coach)) + + def test_coach_can_view_assigned_athlete_workouts(self): + ''' + Test that the coach can view workouts assigned to their athlete. + Expected behavior: + 1. The coach should be able to view all workouts assigned to their athlete. + 2. The workouts should be filtered based on the coach's ID. + 3. The response should include the correct workout details. + Steps: + 1. Create a coach and an athlete. + 2. Assign workouts to the athlete. + 3. Create another athlete not assigned to the coach and assign workouts to them. + 4. Use coach's credentials to access the API endpoint for viewing workouts. + 5. Verify the response status code is 200. + 6. Check that the response contains only the workouts assigned to the coach's athlete. + ''' + # 4 + response = self.client.get("/api/workouts/", HTTP_AUTHORIZATION=f"Bearer {self.token}") + + # 5 + self.assertEqual(response.status_code, 200, "The response status code is not 200") + + # Check that the response contains the correct workout details + response_data = response.json() + workout_names = [workout["name"] for workout in response_data] + + # Coach can see their athlete's workouts? + self.assertIn("Workout 1", workout_names, "Workout 1 is not in the response") + self.assertIn("Workout 2", workout_names, "Workout 2 is not in the response") + + # Coach cannot see workouts of other athletes? + self.assertNotIn("Other Workout 1", workout_names, "Other Workout 1 should not be in the response") + self.assertNotIn("Other Workout 2", workout_names, "Other Workout 2 should not be in the response") + + # Workouts are filtered based on the coach's ID? + for workout in response_data: + owner_id = int(workout["owner"].split("/")[-2]) + self.assertEqual(owner_id, self.athlete.id, "The workout is not associated with the correct athlete")