Self hosted FLOSS fitness/workout, nutrition and weight tracker
Some changes to the exercise translation serializer
Roland Geider873046847235
diff --git a/wger/exercises/api/serializers.py b/wger/exercises/api/serializers.pyindex 95b7a5021..b0a96bc2f 100644--- a/wger/exercises/api/serializers.py+++ b/wger/exercises/api/serializers.py@@ -219,27 +219,23 @@ class ExerciseTranslationSerializer(serializers.ModelSerializer):"""Exercise translation serializer"""-id = serializers.IntegerField(required=False, read_only=True)uuid = serializers.UUIDField(required=False, read_only=True)- aliases = ExerciseInfoAliasSerializer(source='alias_set', many=True, read_only=True)- notes = ExerciseCommentSerializer(source='exercisecomment_set', many=True, read_only=True)+ exercise_base = serializers.PrimaryKeyRelatedField(+ queryset=ExerciseBase.objects.all(),+ required=True,+ )class Meta:model = Exercisefields = ("id","uuid",- "aliases","name","exercise_base","description",- "notes","creation_date","language",- "license",- "license_author",- "author_history",)diff --git a/wger/exercises/api/views.py b/wger/exercises/api/views.pyindex e96b635e6..158439c3d 100644--- a/wger/exercises/api/views.py+++ b/wger/exercises/api/views.py@@ -179,7 +179,7 @@ class ExerciseTranslationViewSet(CreateUpdateModelViewSet):strip=True)- super().perform_create(serializer)+ super().perform_update(serializer)actstream_action.send(self.request.user,verb=StreamVerbs.UPDATED.value,diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.pyindex 11b169b7e..fc86a3e13 100644--- a/wger/exercises/tests/test_exercise.py+++ b/wger/exercises/tests/test_exercise.py@@ -16,7 +16,6 @@import json# Django-from django.core import mailfrom django.core.cache import cachefrom django.core.cache.utils import make_template_fragment_keyfrom django.template import (@@ -30,12 +29,8 @@ from rest_framework import status# wgerfrom wger.core.tests import api_base_test-from wger.core.tests.api_base_test import (- ApiBaseTestCase,- ExerciseCrudApiTestCase,-)+from wger.core.tests.api_base_test import ExerciseCrudApiTestCasefrom wger.core.tests.base_testcase import (- STATUS_CODES_FAIL,WgerDeleteTestCase,WgerTestCase,)@@ -45,8 +40,10 @@ from wger.exercises.models import (Muscle,)from wger.utils.cache import cache_mapper-from wger.utils.constants import WORKOUT_TAB-from wger.utils.helpers import random_string+from wger.utils.constants import (+ DEFAULT_LICENSE_ID,+ WORKOUT_TAB,+)class ExerciseRepresentationTestCase(WgerTestCase):@@ -610,6 +607,35 @@ class ExerciseCustomApiTestCase(ExerciseCrudApiTestCase):exercise = Exercise.objects.get(pk=self.pk)self.assertEqual(exercise.exercise_base_id, 1)+ def test_cant_change_license(self):+ """+ Test that it is not possible to change the license of an existing+ exercise translation.+ """+ exercise = Exercise.objects.get(pk=self.pk)+ self.assertEqual(exercise.license_id, 2)++ self.get_credentials('trainer1')+ response = self.client.patch(self.url_detail, data={'license': 3})+ self.assertEqual(response.status_code, status.HTTP_200_OK)++ exercise = Exercise.objects.get(pk=self.pk)+ self.assertEqual(exercise.license_id, 2)++ def test_cant_set_license(self):+ """+ Test that it is not possible to set the license for a newly created+ exercise translation (the license is always set to the default)+ """+ self.data['license'] = 3++ self.get_credentials('trainer1')+ response = self.client.post(self.url, data=self.data)+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)++ exercise = Exercise.objects.get(pk=self.pk)+ self.assertEqual(exercise.license_id, DEFAULT_LICENSE_ID)+def test_patch_clean_html(self):"""Test that the description field has its HTML stripped before savingdiff --git a/wger/exercises/tests/test_exercise_base.py b/wger/exercises/tests/test_exercise_base.pyindex 743d4f262..080204eef 100644--- a/wger/exercises/tests/test_exercise_base.py+++ b/wger/exercises/tests/test_exercise_base.py@@ -12,6 +12,9 @@## You should have received a copy of the GNU Affero General Public License+# Third Party+from rest_framework import status+# wgerfrom wger.core.tests.api_base_test import ExerciseCrudApiTestCasefrom wger.core.tests.base_testcase import WgerTestCase@@ -19,6 +22,7 @@ from wger.exercises.models import (Exercise,ExerciseBase,)+from wger.utils.constants import DEFAULT_LICENSE_IDclass ExerciseBaseTestCase(WgerTestCase):@@ -100,3 +104,32 @@ class ExerciseCustomApiTestCase(ExerciseCrudApiTestCase):def get_resource_name(self):return 'exercise-base'++ def test_cant_change_license(self):+ """+ Test that it is not possible to change the license of an existing+ exercise base+ """+ exercise = ExerciseBase.objects.get(pk=self.pk)+ self.assertEqual(exercise.license_id, 2)++ self.get_credentials('trainer1')+ response = self.client.patch(self.url_detail, data={'license': 3})+ self.assertEqual(response.status_code, status.HTTP_200_OK)++ exercise = ExerciseBase.objects.get(pk=self.pk)+ self.assertEqual(exercise.license_id, 2)++ def test_cant_set_license(self):+ """+ Test that it is not possible to set the license for a newly created+ exercise base (the license is always set to the default)+ """+ self.data['license'] = 3++ self.get_credentials('trainer1')+ response = self.client.post(self.url, data=self.data)+ self.assertEqual(response.status_code, status.HTTP_201_CREATED)++ exercise = ExerciseBase.objects.get(pk=self.pk)+ self.assertEqual(exercise.license_id, DEFAULT_LICENSE_ID)diff --git a/wger/utils/models.py b/wger/utils/models.pyindex 2e7492092..be51b0483 100644--- a/wger/utils/models.py+++ b/wger/utils/models.py@@ -20,6 +20,7 @@ from django.utils.translation import gettext_lazy as _# wgerfrom wger.core.models import License+from wger.utils.constants import DEFAULT_LICENSE_ID"""@@ -38,7 +39,7 @@ class AbstractLicenseModel(models.Model):license = models.ForeignKey(License,verbose_name=_('License'),- default=2,+ default=DEFAULT_LICENSE_ID,on_delete=models.CASCADE,)"""The item's license"""