Self hosted FLOSS fitness/workout, nutrition and weight tracker
Fix some more tests
Roland Geider9502fc70e819
diff --git a/wger/exercises/fixtures/test-exercises.json b/wger/exercises/fixtures/test-exercises.jsonindex abe06b725..93d3ffdd7 100644--- a/wger/exercises/fixtures/test-exercises.json+++ b/wger/exercises/fixtures/test-exercises.json@@ -153,7 +153,7 @@}},{- "pk": 6,+ "pk": 5,"model": "exercises.exercisebase","fields": {"uuid": "e9e35f0c45b14d64b00db707a94c6fb8",@@ -210,7 +210,7 @@"uuid": "37b5813c76bd4658820a572d9dd93f31","language": 1,"description": "",- "exercise_base": 3,+ "exercise_base": 4,"license_author": "test","name": "Pending exercise","creation_date": "2022-01-10",@@ -222,7 +222,7 @@"model": "exercises.exercise","fields": {"uuid": "37b5813c76bd4658820a572d9dd93f31",- "language": 2,+ "language": 3,"description": "","exercise_base": 1,"license_author": "test",@@ -264,7 +264,7 @@"fields": {"uuid": "885c1110aa324235af361164347a4465","language": 1,- "exercise_base": 4,+ "exercise_base": 5,"description": "","name": "Needed for demo user","creation_date": "2022-01-10",diff --git a/wger/exercises/models/base.py b/wger/exercises/models/base.pyindex c66e7de8c..3fa2e2fa4 100644--- a/wger/exercises/models/base.py+++ b/wger/exercises/models/base.py@@ -24,6 +24,7 @@ from typing import (# Djangofrom django.core.checks import translationfrom django.db import models+from django.db.models import Qfrom django.utils.translation import (get_language,gettext_lazy as _,@@ -125,6 +126,15 @@ class ExerciseBase(AbstractLicenseModel, models.Model):"""return [exercise.language for exercise in self.exercises.all()]+ @property+ def base_variations(self):+ """+ Returns the variations of this exercise base, excluding itself+ """+ if not self.variations:+ return []+ return self.variations.exercisebase_set.filter(~Q(id=self.id))+def get_exercise(self, language: Optional[str] = None):"""Returns the exercise for the given language. If the language is notdiff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.pyindex ffaf19971..acd536240 100644--- a/wger/exercises/tests/test_exercise.py+++ b/wger/exercises/tests/test_exercise.py@@ -92,24 +92,21 @@ class ExerciseIndexTestCase(WgerTestCase):# Correct categories are showncategory_1 = response.context['bases'][0].category- self.assertEqual(category_1.id, 2)- self.assertEqual(category_1.name, "Another category")+ self.assertEqual(category_1.id, 1)+ self.assertEqual(category_1.name, "Category")category_2 = response.context['bases'][1].category- self.assertEqual(category_2.id, 3)- self.assertEqual(category_2.name, "Yet another category")+ self.assertEqual(category_2.id, 2)+ self.assertEqual(category_2.name, "Another category")# Correct exercises in the categories- exercise_bases_1 = category_1.exercisebase_set.all()- exercises_1 = exercise_bases_1[0].exercises.all()- exercises_2 = exercise_bases_1[1].exercises.all()- exercise_1 = exercises_1[0]- exercise_2 = exercises_2[0]- self.assertEqual(exercise_1.id, 1)- self.assertEqual(exercise_1.name, "An exercise")+ exercise_1 = response.context['bases'][0].get_exercise()+ exercise_2 = response.context['bases'][1].get_exercise()+ self.assertEqual(exercise_1.id, 81)+ self.assertEqual(exercise_1.name, "Needed for demo user")- self.assertEqual(exercise_2.id, 2)- self.assertEqual(exercise_2.name, "Very cool exercise")+ self.assertEqual(exercise_2.id, 1)+ self.assertEqual(exercise_2.name, "An exercise")self.assertContains(response, 'Add new exercise')diff --git a/wger/exercises/tests/test_exercise_base.py b/wger/exercises/tests/test_exercise_base.pyindex 3ced3348c..3cedf674f 100644--- a/wger/exercises/tests/test_exercise_base.py+++ b/wger/exercises/tests/test_exercise_base.py@@ -73,11 +73,11 @@ class ExerciseBaseTestCase(WgerTestCase):# Even if these exercises have the same base, only the variations for# their respective languages are returned.- exercise = Exercise.objects.get(pk=81)- self.assertListEqual(sorted([i.id for i in exercise.variations]), sorted([3, 4, 35, 81]))+ base = ExerciseBase.objects.get(pk=1)+ self.assertListEqual(sorted([i.id for i in base.base_variations]), [2])- exercise2 = Exercise.objects.get(pk=84)- self.assertEqual(sorted([i.id for i in exercise2.variations]), sorted([84, 91, 111, 126]))+ base2 = ExerciseBase.objects.get(pk=3)+ self.assertEqual(sorted([i.id for i in base2.base_variations]), [4])def test_images(self):"""Test that the correct images are returned for the exercises"""