diff --git a/backend/tests/test_boundary_file_size.py b/backend/tests/test_boundary_file_size.py new file mode 100644 index 0000000..c8feffe --- /dev/null +++ b/backend/tests/test_boundary_file_size.py @@ -0,0 +1,33 @@ +""" +TC_002 - Boundary test for file size +""" +from django.test import TestCase + +def test_file_size_boundary(self): + # Create file with minimum valid size (1 byte) + min_file = SimpleUploadedFile("min_file.txt", b"x" * 1) + + # Create file with minimum valid size (2 bytes) + min_plus_file = SimpleUploadedFile("min_plus_file.txt", b"x" * 2) + + # Create file with maximum valid size (5MB - 1 byte) + max_minus_file = SimpleUploadedFile("max_minus_file.txt", b"x" * (max_size - 1)) + + # Create file with maximum valid size (5MB) + max_file = SimpleUploadedFile("max_file.txt", b"x" * max_size) + + # Create AthleteFile objects with both files + athlete_min_file = AthleteFile(athlete=self.user, owner=self.user, file=min_file) + athlete_min_plus_file = AthleteFile(athlete=self.user, owner=self.user, file=min_plus_file) + athlete_max_minus_file = AthleteFile(athlete=self.user, owner=self.user, file=max_minus_file) + athlete_max_file = AthleteFile(athlete=self.user, owner=self.user, file=max_file) + + try: + # Runs validation checks + athlete_min_file.full_clean() + athlete_min_plus_file.full_clean() + athlete_max_minus_file.full_clean() + athlete_max_file.full_clean() + except ValidationError as e: + # Fails if any validation errors are raised + self.fail(f"ValidationError raised: {e}") diff --git a/backend/tests/test_equivalence_class_exercise.py b/backend/tests/test_equivalence_class_exercise.py new file mode 100644 index 0000000..5a3004a --- /dev/null +++ b/backend/tests/test_equivalence_class_exercise.py @@ -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 diff --git a/backend/tests/test_robust_boundary_file_size.py b/backend/tests/test_robust_boundary_file_size.py new file mode 100644 index 0000000..325b4d1 --- /dev/null +++ b/backend/tests/test_robust_boundary_file_size.py @@ -0,0 +1,19 @@ +""" +TC_003 - Robust boundary test for file size above maximum size +""" +from django.test import TestCase + +def test_file_size_robust_boundary(self): + # Creates a file with invalid size + invalid_above_file = SimpleUploadedFile("test_above_max.txt", b"x" * (max_size + 1)) + # Creates AthleteFile object with the invalid file + athlete_above_file = AthleteFile(athlete=self.user, owner=self.user, file=invalid_above_file) + + try: + # Runs a validation check + athlete_above_file.full_clean() + # Fails if no validation errors are raised + self.fail("ValidationError not raised for file above maximum size.") + except ValidationError as e: + # Passes if validation error is raised. + self.assertIn('file', e.message_dict) diff --git a/backend/tests/test_special_value_file_format.py b/backend/tests/test_special_value_file_format.py new file mode 100644 index 0000000..9ecf204 --- /dev/null +++ b/backend/tests/test_special_value_file_format.py @@ -0,0 +1,29 @@ +""" +TC_004 - Special value test for uploading a valid and invalid file to a workout. +""" +from django.test import TestCase + +def test_file_upload_special_value(self): + # Creates a PDF-file + pdf_file = SimpleUploadedFile("pdf_file.pdf") + # Creates a DOCX-file + docx_file = SimpleUploadedFile("docx_file.docx") + # Creates AthleteFile object with the files + athlete_pdf_file = AthleteFile(athlete=self.user, owner=self.user, file=pdf_file) + athlete_docx_file = AthleteFile(athlete=self.user, owner=self.user, file=docx_file) + + try: + # Runs validation check for PDF-file + athlete_pdf_file.full_clean() + except ValidationError as e: + # Fails if any validation errors are raised + self.fail(f"ValidationError raised: {e}") + + try: + # Runs validation check for DOCX-file + athlete_pdf_file.full_clean() + # Fails if no validation errors are raised + self.fail("ValidationError not raised for file of format DOCX.") + except ValidationError as e: + # Passes if validation error is raised. + self.assertIn('file', e.message_dict) diff --git a/backend/tests/test_special_value_workout.py b/backend/tests/test_special_value_workout.py new file mode 100644 index 0000000..3c58a1c --- /dev/null +++ b/backend/tests/test_special_value_workout.py @@ -0,0 +1,35 @@ +""" +TC_005 - Special value test for the limit of sets in an exercise instance +""" +from django.test import TestCase + +def test_create_valid_workout(self): + response = self.client.post("/api/workouts/", { + "name": "Full body toning", + "date": now().isoformat(), + "notes": "Workout for women", + "visibility": "PU", + "owner": self.user.id, + "exercise_instances": [] + }, format="json") + + print(f"Response data: {response.data}") + print(f"Response status code: {response.status_code}") + + assert response.status_code == 201 + assert Workout.objects.count() == 1 + +def test_create_invalid_workout(self): + response = self.client.post("/api/workouts/", { + "name": "Full body toning", + "date": "today", # text instead of a date format + "notes": "Workout for women", + "visibility": "XO", # non-existent visibility + "owner": self.user.id, + "exercise_instances": [] + }, format="json") + + print(f"Error response data: {response.data}") + print(f"Error response status code: {response.status_code}") + + assert response.status_code == 400