From 93a8c7ddf71817453b4e8f9517a1fa5033d8c4a3 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:43:58 +0200 Subject: [PATCH] Create test_equivalence_class_exercise --- backend/tests/test_equivalence_class_exercise | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 backend/tests/test_equivalence_class_exercise diff --git a/backend/tests/test_equivalence_class_exercise b/backend/tests/test_equivalence_class_exercise new file mode 100644 index 0000000..5a3004a --- /dev/null +++ b/backend/tests/test_equivalence_class_exercise @@ -0,0 +1,48 @@ +""" +TC_001 - Equivalence class test for the limit of sets in an exercise +""" +from django.test import TestCase +from workouts.models import ExerciseInstance + +# Test an exercise instance with the lowest equivalence class +def test_create_below_exercise_instance(self): + response = self.client.post("api/exercise-instances/", + "workout": "Full body toning", + "exercise": "Squats", + "sets": -10, # A negative number of sets is expected to raise an error + "number": 5 + }, format="json") + + print(f"Error response data: {response.data}") + print(f"Error response status code: {response.status_code}") + + assert response.status_code == 400 + +# Test an exercise instance with the mid and valid equivalence class +def test_create_valid_exercise_instance(self): + response = self.client.post("/api/exercise-instances/", { + "workout": "Full body toning", + "exercise": "Squats", + "sets": 50, # A number of sets between 0 and 100 is expected to be valid + "number": 5 + }, format="json") + + print(f"Response data: {response.data}") + print(f"Response status code: {response.status_code}") + + assert response.status_code == 201 + assert ExerciseInstance.objects.count() == 1 + +# Test an exercise instance with the highest equivalence class +def test_create_below_exercise_instance(self): + response = self.client.post("api/exercise-instances/", { + "workout": "Full body toning", + "exercise": "Squats", + "sets": 110, # A number of sets above 100 is expected to raise an error + "number": 5 + }, format="json") + + print(f"Error response data: {response.data}") + print(f"Error response status code: {response.status_code}") + + assert response.status_code == 400