forked from mathialm/secfit
-
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.
- Loading branch information
Niklas Ziemer
committed
Mar 26, 2025
1 parent
6dfaf93
commit 4f320d0
Showing
1 changed file
with
46 additions
and
0 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 |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| from rest_framework.test import APITestCase | ||
| from django.test import TestCase | ||
| from django.contrib.auth import get_user_model | ||
| from workouts.models import Workout | ||
|
|
||
| class TestWorkoutAPI(APITestCase): | ||
| def setUp(self): | ||
| self.user = get_user_model().objects.create_user( | ||
| username="testuser", | ||
| password="testpassword" | ||
| ) | ||
| self.client.force_authenticate(self.user) | ||
|
|
||
| def test_create_workout_leap_year(self): | ||
| response = self.client.post( | ||
| "/api/workouts/", | ||
| { | ||
| "name": "Test workout leap year", | ||
| "date": "2024-02-29", | ||
| "notes": "Test notes", | ||
| "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" | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 201) | ||
| self.assertEqual(Workout.objects.count(), 1) | ||
|
|
||
| def test_create_workout_non_leap_year(self): | ||
| response = self.client.post( | ||
| "/api/workouts/", | ||
| { | ||
| "name": "Test workout leap year", | ||
| "date": "2023-02-29", | ||
| "notes": "Test notes", | ||
| "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" | ||
| ) | ||
|
|
||
| self.assertEqual(response.status_code, 400) | ||
| self.assertEqual(Workout.objects.count(), 0) |