forked from malenelu/secfit-group15
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update test_equivalence_class_exercise.py
- Loading branch information
Showing
1 changed file
with
53 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,48 +1,58 @@ | ||
| """ | ||
| TC_001 - Equivalence class test for the limit of sets in an exercise | ||
| """ | ||
| from django.test import TestCase | ||
| from workouts.models import ExerciseInstance | ||
| import pytest | ||
| from rest_framework.test import APIClient | ||
| from django.utils.timezone import now | ||
| from workouts.models import Workout | ||
| from django.contrib.auth import get_user_model | ||
|
|
||
| # 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") | ||
| @pytest.mark.django_db | ||
| class TestWorkoutAPI: | ||
| def setUp(self): | ||
| self.client = APIClient() | ||
| self.user = get_user_model().objects.create_user(username="testuser", password="password") | ||
| self.client.force_authenticate(self.user) | ||
|
|
||
| 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 | ||
| # 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 |