diff --git a/backend/tests/test_special_value_workout.py b/backend/tests/test_special_value_workout.py index 81f889c..db3a324 100644 --- a/backend/tests/test_special_value_workout.py +++ b/backend/tests/test_special_value_workout.py @@ -1,37 +1,49 @@ """ -TC_005 - Special value test for the limit of sets in an exercise instance +TC_005 - Special value test for creating a valid and invalid workout """ -from django.test import TestCase + +import pytest +from django.test import TestCase # +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 -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}") +@pytest.mark.django_db - 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": [] +class User(TestCase): + def setUp(self): + self.client = APIClient() + self.user = get_user_model().objects.create_user(username="testuser", password="password") + self.client.force_authenticate(self.user) + + 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"Error response data: {response.data}") - print(f"Error response status code: {response.status_code}") + print(f"Response data: {response.data}") + print(f"Response status code: {response.status_code}") - assert response.status_code == 400 + 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