Self hosted FLOSS fitness/workout, nutrition and weight tracker
Add simple tests for some exercise management commands
Roland Geiderafb72b2eaec2
diff --git a/wger/core/tests/base_testcase.py b/wger/core/tests/base_testcase.pyindex 25f83b271..b76b5ba59 100644--- a/wger/core/tests/base_testcase.py+++ b/wger/core/tests/base_testcase.py@@ -33,6 +33,7 @@ from django.utils.translation import activate# wgerfrom wger.utils.constants import TWOPLACES+STATUS_CODES_FAIL = (302, 403, 404)@@ -75,6 +76,7 @@ def delete_testcase_add_methods(cls):"""for user in get_user_list(cls.user_fail):+def test_unauthorized(self):self.user_login(user)self.delete_object(fail=False)@@ -82,6 +84,7 @@ def delete_testcase_add_methods(cls):setattr(cls, f'test_unauthorized_{user}', test_unauthorized)for user in get_user_list(cls.user_success):+def test_authorized(self):self.user_login(user)self.delete_object(fail=False)diff --git a/wger/exercises/management/commands/download-exercise-images.py b/wger/exercises/management/commands/download-exercise-images.pyindex bc6f59001..43a3d9134 100644--- a/wger/exercises/management/commands/download-exercise-images.py+++ b/wger/exercises/management/commands/download-exercise-images.py@@ -52,7 +52,7 @@ class Command(BaseCommand):dest='remote_url',default=settings.WGER_SETTINGS['WGER_INSTANCE'],help=f'Remote URL to fetch the images from (default: WGER_SETTINGS'- f'["WGER_INSTANCE"] - {settings.WGER_SETTINGS["WGER_INSTANCE"]})'+ f'["WGER_INSTANCE"] - {settings.WGER_SETTINGS["WGER_INSTANCE"]})')def handle(self, **options):diff --git a/wger/exercises/management/commands/download-exercise-videos.py b/wger/exercises/management/commands/download-exercise-videos.pyindex 4bd8edd57..3aa5bc4a8 100644--- a/wger/exercises/management/commands/download-exercise-videos.py+++ b/wger/exercises/management/commands/download-exercise-videos.py@@ -45,7 +45,7 @@ class Command(BaseCommand):dest='remote_url',default='https://wger.de',help='Remote URL to fetch the exercises from (default: '- 'https://wger.de)'+ 'https://wger.de)')def handle(self, **options):diff --git a/wger/exercises/management/commands/read-exercise-cleanup.py b/wger/exercises/management/commands/read-exercise-cleanup.pyindex 1c1b4a5be..3ed64499b 100644--- a/wger/exercises/management/commands/read-exercise-cleanup.py+++ b/wger/exercises/management/commands/read-exercise-cleanup.py@@ -37,6 +37,7 @@ from wger.exercises.models import ()from wger.utils.constants import DEFAULT_LICENSE_ID+UUID_NEW = 'NEW'VIDEO_AUTHOR = 'Goulart'VIDEO_PATH = pathlib.Path('videos-tmp')diff --git a/wger/exercises/tests/test_management_commands.py b/wger/exercises/tests/test_management_commands.pynew file mode 100644index 000000000..8addb407f--- /dev/null+++ b/wger/exercises/tests/test_management_commands.py@@ -0,0 +1,59 @@+# 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++# Standard Library+from unittest.mock import patch++# Django+from django.core.management import call_command+from django.test import SimpleTestCase+++class TestManagementCommands(SimpleTestCase):++ @patch('wger.exercises.sync.delete_entries')+ @patch('wger.exercises.sync.sync_muscles')+ @patch('wger.exercises.sync.sync_languages')+ @patch('wger.exercises.sync.sync_exercises')+ @patch('wger.exercises.sync.sync_equipment')+ @patch('wger.exercises.sync.sync_categories')+ def test_sync_exercises(+ self,+ mock_sync_categories,+ mock_sync_equipment,+ mock_sync_exercises,+ mock_sync_languages,+ mock_sync_muscles,+ mock_delete_entries,+ ):+ call_command('sync-exercises')++ mock_sync_categories.assert_called()+ mock_sync_equipment.assert_called()+ mock_sync_exercises.assert_called()+ mock_sync_languages.assert_called()+ mock_sync_muscles.assert_called()+ mock_delete_entries.assert_called()++ @patch('wger.exercises.sync.download_exercise_images')+ def test_download_exercise_images(self, mock_download_exercise_images):+ call_command('download-exercise-images')++ mock_download_exercise_images.assert_called()++ @patch('wger.exercises.sync.download_exercise_videos')+ def test_download_exercise_videos(self, mock_download_exercise_videos):+ call_command('download-exercise-videos')++ mock_download_exercise_videos.assert_called()diff --git a/wger/exercises/views/exercises.py b/wger/exercises/views/exercises.pyindex f98b5ab8f..1fdfd5934 100644--- a/wger/exercises/views/exercises.py+++ b/wger/exercises/views/exercises.py@@ -21,9 +21,7 @@ from django.contrib.auth.mixins import (LoginRequiredMixin,PermissionRequiredMixin,)-from django.http import HttpResponsePermanentRedirect-from django.shortcuts import get_object_or_404from django.urls import (reverse,@@ -42,6 +40,7 @@ from django.views.generic import (from wger.exercises.models import Exercisefrom wger.utils.generic_views import WgerDeleteMixin+logger = logging.getLogger(__name__)diff --git a/wger/nutrition/management/commands/download-ingredient-images.py b/wger/nutrition/management/commands/download-ingredient-images.pyindex 9a62b13db..f3b16201e 100644--- a/wger/nutrition/management/commands/download-ingredient-images.py+++ b/wger/nutrition/management/commands/download-ingredient-images.py@@ -52,7 +52,7 @@ class Command(BaseCommand):dest='remote_url',default=settings.WGER_SETTINGS['WGER_INSTANCE'],help=f'Remote URL to fetch the ingredients from (default: WGER_SETTINGS'- f'["WGER_INSTANCE"] - {settings.WGER_SETTINGS["WGER_INSTANCE"]})'+ f'["WGER_INSTANCE"] - {settings.WGER_SETTINGS["WGER_INSTANCE"]})')def handle(self, **options):diff --git a/wger/nutrition/sync.py b/wger/nutrition/sync.pyindex f301a0596..97e22584d 100644--- a/wger/nutrition/sync.py+++ b/wger/nutrition/sync.py@@ -37,6 +37,7 @@ from wger.utils.constants import ()from wger.utils.requests import wger_headers+logger = logging.getLogger(__name__)diff --git a/wger/utils/helpers.py b/wger/utils/helpers.pyindex 2396b7f95..c72aa65eb 100644--- a/wger/utils/helpers.py+++ b/wger/utils/helpers.py@@ -37,6 +37,7 @@ from django.utils.http import (urlsafe_base64_encode,)+logger = logging.getLogger(__name__)@@ -214,7 +215,7 @@ def normalize_decimal(d):normalized = d.normalize()sign, digits, exponent = normalized.as_tuple()if exponent > 0:- return decimal.Decimal((sign, digits + (0,) * exponent, 0))+ return decimal.Decimal((sign, digits + (0, ) * exponent, 0))else:return normalizeddiff --git a/wger/weight/views.py b/wger/weight/views.pyindex 9a1eae118..a6154f049 100644--- a/wger/weight/views.py+++ b/wger/weight/views.py@@ -51,6 +51,7 @@ from wger.weight import helpersfrom wger.weight.forms import WeightFormfrom wger.weight.models import WeightEntry+logger = logging.getLogger(__name__)