Skip to content

Commit

Permalink
push example code
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilOrv committed Apr 1, 2025
1 parent 754ab85 commit a561f63
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions backend/tests/test.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 TestWorkoutAPI(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

0 comments on commit a561f63

Please sign in to comment.