Skip to content

armgit / wger

Public Imported from GitHub
0

Self hosted FLOSS fitness/workout, nutrition and weight tracker

add comments, authors, tests

Lydia Xingb3aa445f7b96
diff --git a/AUTHORS.rst b/AUTHORS.rst
index 17fdf9afa..19dac7303 100644
--- a/AUTHORS.rst
+++ b/AUTHORS.rst
@@ -33,6 +33,9 @@ Developers
* Rashmi Kamath - https://github.com/Rkamath2
* Anthony (Ryo) Wright - https://github.com/ryowright
* Austin Leung - https://github.com/austin-leung
+* Lydia Xing - https://github.com/lydiaxing
+* Ellie Qiu - https://github.com/eq8913
+* Hita Kambhamettu - https://github.com/Hita-K
Translators
-----------
diff --git a/wger/exercises/tests/test_exercise.py b/wger/exercises/tests/test_exercise.py
index a97f37948..961ab983d 100644
--- a/wger/exercises/tests/test_exercise.py
+++ b/wger/exercises/tests/test_exercise.py
@@ -268,6 +268,23 @@ class ExercisesTestCase(WgerTestCase):
self.add_exercise_user_fail()
self.user_logout()
+ def test_add_exercise_name_too_similar_fail(self):
+ """
+ Tests that adding an exercise with a name that is too similar
+ to an existing exercise fails
+ """
+ count_before = Exercise.objects.count()
+ response = self.client.post(reverse('exercise:exercise:add'),
+ {'category': 2,
+ 'name_original': 'Squats',
+ 'license': 1,
+ 'muscles': [1, 2]})
+ count_after = Exercise.objects.count()
+ self.assertIn(response.status_code, STATUS_CODES_FAIL)
+
+ # Exercise was not added
+ self.assertEqual(count_before, count_after)
+
def add_exercise_success(self, admin=False):
"""
Tests adding/editing an exercise with a user with enough rights to do this
diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.py
index db2297b65..d879b799d 100644
--- a/wger/exercises/views/exercises.py
+++ b/wger/exercises/views/exercises.py
@@ -194,6 +194,10 @@ class ExerciseForm(ModelForm):
js = (settings.STATIC_URL + 'yarn/tinymce/tinymce.min.js',)
def clean_name_original(self):
+ """
+ Throws a validation error if the submitted name is too similar to an existing
+ exercise's name
+ """
name_original = self.cleaned_data['name_original']
languages = load_item_languages(LanguageConfig.SHOW_ITEM_EXERCISES)
exercises = Exercise.objects.accepted() \