Skip to content

Commit

Permalink
initialize test files
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilOrv committed Apr 1, 2025
1 parent a561f63 commit 3f94011
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 1 deletion.
41 changes: 41 additions & 0 deletions backend/tests/TestExerciseNumber.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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

from django.test import TestCase

@pytest.mark.django_db
class TestExerciseNumber(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_workout_valid(self): #
response = self.client.post("/api/workouts/", {
"name": "Morning Run",
"date": now().isoformat(),
"notes": "5km run",
"visibility": "PU", # Adding visibility field which is required
"owner": self.user.id, # Adding owner field which seems to be required
"exercise_instances": [] # Adding exercise_instances field which is required
}, format="json")


assert response.status_code == 201
assert Workout.objects.count() == 1

def test_create_workout_invalid_date(self): #
response = self.client.post("/api/workouts/", {
"name": "Invalid Run",
"date": "invalid_date",
"notes": "Wrong format",
"visibility": "PU", # Adding required field
"owner": self.user.id, # Adding required field
"exercise_instances": [] # Adding required field
}, format="json")

assert response.status_code == 400 # Should return validation error

41 changes: 41 additions & 0 deletions backend/tests/TestExerciseSet.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
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

from django.test import TestCase

@pytest.mark.django_db
class TestExerciseSet(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_workout_valid(self): #
response = self.client.post("/api/workouts/", {
"name": "Morning Run",
"date": now().isoformat(),
"notes": "5km run",
"visibility": "PU", # Adding visibility field which is required
"owner": self.user.id, # Adding owner field which seems to be required
"exercise_instances": [] # Adding exercise_instances field which is required
}, format="json")


assert response.status_code == 201
assert Workout.objects.count() == 1

def test_create_workout_invalid_date(self): #
response = self.client.post("/api/workouts/", {
"name": "Invalid Run",
"date": "invalid_date",
"notes": "Wrong format",
"visibility": "PU", # Adding required field
"owner": self.user.id, # Adding required field
"exercise_instances": [] # Adding required field
}, format="json")

assert response.status_code == 400 # Should return validation error

2 changes: 1 addition & 1 deletion backend/tests/test.py → backend/tests/TestUser.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
from django.test import TestCase

@pytest.mark.django_db
class TestWorkoutAPI(TestCase):
class TestUser(TestCase):
def setUp(self):
self.client = APIClient()
self.user = get_user_model().objects.create_user(username="testuser", password="password")
Expand Down

0 comments on commit 3f94011

Please sign in to comment.