From 93a8c7ddf71817453b4e8f9517a1fa5033d8c4a3 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:43:58 +0200 Subject: [PATCH 01/10] 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 From 8ce0c3049a949551fcb74b9675eb19f035a7ea4b Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:44:27 +0200 Subject: [PATCH 02/10] Update and rename test_equivalence_class_exercise to test_equivalence_class_exercise.py --- ...ivalence_class_exercise => test_equivalence_class_exercise.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename backend/tests/{test_equivalence_class_exercise => test_equivalence_class_exercise.py} (100%) diff --git a/backend/tests/test_equivalence_class_exercise b/backend/tests/test_equivalence_class_exercise.py similarity index 100% rename from backend/tests/test_equivalence_class_exercise rename to backend/tests/test_equivalence_class_exercise.py From f9883e319f356c40b02004c935474f5d96cee65e Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:46:23 +0200 Subject: [PATCH 03/10] Create test_boundary_file_size.py --- backend/tests/test_boundary_file_size.py | 31 ++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 backend/tests/test_boundary_file_size.py diff --git a/backend/tests/test_boundary_file_size.py b/backend/tests/test_boundary_file_size.py new file mode 100644 index 0000000..5984cdf --- /dev/null +++ b/backend/tests/test_boundary_file_size.py @@ -0,0 +1,31 @@ +""" +TC_002 - Boundary test for file size +""" +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}") From ce0fa1927f91e90b534f0ccaf35b68a095000037 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:48:02 +0200 Subject: [PATCH 04/10] Create test_robust_boundary_file_size.py --- backend/tests/test_robust_boundary_file_size.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 backend/tests/test_robust_boundary_file_size.py 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..263f31c --- /dev/null +++ b/backend/tests/test_robust_boundary_file_size.py @@ -0,0 +1,17 @@ +""" +TC_003 - Robust boundary test for file size above maximum size +""" +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) From 6d83caeb2b2ee693759c20c8f78bbc1bd51fcd4b Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:49:44 +0200 Subject: [PATCH 05/10] Create test_special_value_file_format.py --- .../tests/test_special_value_file_format.py | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 backend/tests/test_special_value_file_format.py 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..749202b --- /dev/null +++ b/backend/tests/test_special_value_file_format.py @@ -0,0 +1,27 @@ +""" +TC_004 - Special value test for uploading a valid and invalid file to a workout. +""" +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) From 6570ca7ac69573cbffaf52fc6981c557a550e7c3 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:51:55 +0200 Subject: [PATCH 06/10] Create test_special_value_workout.py --- backend/tests/test_special_value_workout.py | 33 +++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 backend/tests/test_special_value_workout.py diff --git a/backend/tests/test_special_value_workout.py b/backend/tests/test_special_value_workout.py new file mode 100644 index 0000000..9c09b45 --- /dev/null +++ b/backend/tests/test_special_value_workout.py @@ -0,0 +1,33 @@ +""" +TC_005 - Special value test for the limit of sets in an exercise instance +""" +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 From 0f911b361e3cee6e0042f9ecad62220d62e6d878 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:52:29 +0200 Subject: [PATCH 07/10] Update test_boundary_file_size.py --- backend/tests/test_boundary_file_size.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/tests/test_boundary_file_size.py b/backend/tests/test_boundary_file_size.py index 5984cdf..c8feffe 100644 --- a/backend/tests/test_boundary_file_size.py +++ b/backend/tests/test_boundary_file_size.py @@ -1,6 +1,8 @@ """ 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) From 549be02ca21c67c33dee5aae8833800c489cffa1 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:52:42 +0200 Subject: [PATCH 08/10] Update test_robust_boundary_file_size.py --- backend/tests/test_robust_boundary_file_size.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/tests/test_robust_boundary_file_size.py b/backend/tests/test_robust_boundary_file_size.py index 263f31c..325b4d1 100644 --- a/backend/tests/test_robust_boundary_file_size.py +++ b/backend/tests/test_robust_boundary_file_size.py @@ -1,6 +1,8 @@ """ 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)) From b4de57be327a480da0e651d6539cd1f181e24d23 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:52:52 +0200 Subject: [PATCH 09/10] Update test_special_value_file_format.py --- backend/tests/test_special_value_file_format.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/tests/test_special_value_file_format.py b/backend/tests/test_special_value_file_format.py index 749202b..9ecf204 100644 --- a/backend/tests/test_special_value_file_format.py +++ b/backend/tests/test_special_value_file_format.py @@ -1,6 +1,8 @@ """ 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") From 38dcb985ffd441f1e82da7e456b5ac7d321f2a03 Mon Sep 17 00:00:00 2001 From: Malene Lundemo Date: Tue, 1 Apr 2025 14:53:02 +0200 Subject: [PATCH 10/10] Update test_special_value_workout.py --- backend/tests/test_special_value_workout.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/backend/tests/test_special_value_workout.py b/backend/tests/test_special_value_workout.py index 9c09b45..3c58a1c 100644 --- a/backend/tests/test_special_value_workout.py +++ b/backend/tests/test_special_value_workout.py @@ -1,6 +1,8 @@ """ 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",