Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

Add tests for the exercise base

Roland Geiderc66260150c2b
diff --git a/wger/exercises/api/views.py b/wger/exercises/api/views.py
index e5f1d4905..554981021 100644
--- a/wger/exercises/api/views.py
+++ b/wger/exercises/api/views.py
@@ -56,7 +56,7 @@ from wger.utils.language import (
from wger.utils.permissions import CreateOnlyPermission
-class ExerciseBaseViewSet(viewsets.ModelViewSet):
+class ExerciseBaseViewSet(viewsets.ReadOnlyModelViewSet):
"""
API endpoint for exercise base objects. For a read-only endpoint with all
the information of an exercise, see /api/v2/exerciseinfo/
@@ -71,7 +71,7 @@ class ExerciseBaseViewSet(viewsets.ModelViewSet):
'equipment')
-class ExerciseViewSet(viewsets.ModelViewSet):
+class ExerciseViewSet(viewsets.ReadOnlyModelViewSet):
"""
API endpoint for exercise objects. For a read-only endpoint with all
the information of an exercise, see /api/v2/exerciseinfo/
diff --git a/wger/exercises/fixtures/test-exercises.json b/wger/exercises/fixtures/test-exercises.json
index b1ce2f1cc..7f0dd1b6e 100644
--- a/wger/exercises/fixtures/test-exercises.json
+++ b/wger/exercises/fixtures/test-exercises.json
@@ -75,6 +75,18 @@
"name": "I will be deleted"
}
},
+ {
+ "pk": 1,
+ "model": "exercises.variation",
+ "fields": {
+ }
+ },
+ {
+ "pk": 2,
+ "model": "exercises.variation",
+ "fields": {
+ }
+ },
{
"pk": 1,
"model": "exercises.exercisebase",
@@ -87,7 +99,8 @@
],
"muscles_secondary": [
3
- ]
+ ],
+ "variations": 1
}
},
{
@@ -102,7 +115,8 @@
"muscles_secondary": [
1,
3
- ]
+ ],
+ "variations": 1
}
},
{
@@ -113,7 +127,8 @@
"status": "2",
"muscles": [
1
- ]
+ ],
+ "variations": 2
}
},
{
@@ -125,7 +140,8 @@
"muscles": [
1
],
- "muscles_secondary":[]
+ "muscles_secondary":[],
+ "variations": 2
}
},
{
@@ -134,7 +150,8 @@
"fields": {
"category": 1,
"status": "2",
- "muscles": []
+ "muscles": [],
+ "variations": null
}
},
{
diff --git a/wger/exercises/tests/test_exercise_base.py b/wger/exercises/tests/test_exercise_base.py
new file mode 100644
index 000000000..c6a0a68cc
--- /dev/null
+++ b/wger/exercises/tests/test_exercise_base.py
@@ -0,0 +1,57 @@
+# This file is part of wger Workout Manager.
+#
+# wger Workout Manager is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# wger Workout Manager is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+
+# wger
+from wger.core.tests.base_testcase import WgerTestCase
+from wger.exercises.models import Exercise
+
+
+class ExerciseBaseTestCase(WgerTestCase):
+ """
+ Test the different features of an exercise and its base
+ """
+
+ @staticmethod
+ def get_ids(queryset):
+ """Helper to return the IDs of the objects in a queryset"""
+ return [i.id for i in queryset.all()]
+
+ def test_base(self):
+ """
+ Test that the properties return the correct data
+ """
+ exercise = Exercise.objects.get(pk=1)
+ base = exercise.exercise_base
+ self. assertEqual(base.category, exercise.category)
+ self. assertEqual(self.get_ids(base.equipment), self.get_ids(exercise.equipment))
+ self. assertEqual(self.get_ids(base.muscles), self.get_ids(exercise.muscles))
+ self. assertEqual(self.get_ids(base.muscles_secondary),
+ self.get_ids(exercise.muscles_secondary))
+
+ def test_variations(self):
+ """Test that the variations are correctly returned"""
+
+ # Even if these exercises have the same base, only the variations for
+ # their respective languages are returned.
+ exercise = Exercise.objects.get(pk=81)
+ self.assertEqual([i.id for i in exercise.variations], [3, 35, 81])
+
+ exercise2 = Exercise.objects.get(pk=84)
+ self.assertEqual([i.id for i in exercise2.variations], [84, 91, 111, 126])
+
+ def test_images(self):
+ """Test that the correct images are returned for the exercises"""
+ exercise = Exercise.objects.get(pk=1)
+ base = exercise.exercise_base
+ self.assertEqual(self.get_ids(exercise.images), self.get_ids(base.exerciseimage_set))