Self hosted FLOSS fitness/workout, nutrition and weight tracker
Improve test suite speed and remove unused code
Roland Geiderdd4336f9c4e7
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex bd76473ab..f538d6a8b 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -50,7 +50,9 @@ jobs:uv sync --group devmkdir /tmp/wger-test- # Only run the tests with coverage for one version of python+ # Only run the tests with coverage for one version of python.+ # Coverage is not parallelised because `coverage run` doesn't combine the+ # per-process subprocess data files automatically with Django's runner.- name: Test the application with coverageif: matrix.python-version == 3.13run: |@@ -60,7 +62,7 @@ jobs:- name: Test the applicationif: matrix.python-version != 3.13run: |- uv run ./manage.py test+ uv run ./manage.py test --parallel auto- name: Coverallsif: matrix.python-version == 3.13diff --git a/settings/ci.py b/settings/ci.pyindex ce32c8e3e..e47b26ea1 100644--- a/settings/ci.py+++ b/settings/ci.py@@ -22,7 +22,23 @@ from .settings_global import *env = environ.Env()-DEBUG = True+DEBUG = False++"""+Settings for CI:++The basic changes are++* skip migrations+* use a faster password hasher+* use plain (un-hashed) static file storage+* use an in-memory backend for media files+"""++PASSWORD_HASHERS = [+ 'django.contrib.auth.hashers.MD5PasswordHasher',+ 'django.contrib.auth.hashers.PBKDF2PasswordHasher',+]# Application settingsWGER_SETTINGS['EMAIL_FROM'] = 'wger Workout Manager <[email protected]>'@@ -36,6 +52,9 @@ DATABASES = {'default': {'ENGINE': 'django.db.backends.sqlite3','NAME': 'database.sqlite',+ 'TEST': {+ 'MIGRATE': False,+ },}}@@ -62,3 +81,13 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'DEFAULT_FROM_EMAIL = WGER_SETTINGS['EMAIL_FROM']EMAIL_PAGE_DOMAIN = SITE_URLAXES_ENABLED = False++STORAGES = {+ # In-memory storage avoids disk writes for media uploads during tests.+ 'default': {+ 'BACKEND': 'django.core.files.storage.InMemoryStorage',+ },+ 'staticfiles': {+ 'BACKEND': 'django.contrib.staticfiles.storage.StaticFilesStorage',+ },+}diff --git a/wger/core/tests/base_testcase.py b/wger/core/tests/base_testcase.pyindex a970e89d2..28a5c18a3 100644--- a/wger/core/tests/base_testcase.py+++ b/wger/core/tests/base_testcase.py@@ -17,8 +17,6 @@ import decimalimport loggingimport osimport pathlib-import shutil-import tempfile# Djangofrom django.conf import settings@@ -100,13 +98,12 @@ class BaseTestCase:REST API tests"""- media_root = None-fixtures = ('gym_config','groups','setting_repetition_units','setting_weight_units',+ 'initial_trophies','test-languages','test-licenses','test-gyms',@@ -167,44 +164,6 @@ class BaseTestCase:# del os.environ['RECAPTCHA_TESTING']cache.clear()- # Clear MEDIA_ROOT folder- if self.media_root:- self.media_root.cleanup()-- def init_media_root(self):- """- Init the media root and copy the used images to it-- This is error-prone and ugly, but it's probably ok for the time being- """- self.media_root = tempfile.TemporaryDirectory()- settings.MEDIA_ROOT = self.media_root.name-- pathlib.Path(self.media_root.name, 'exercise-images', '1').mkdir(- parents=True, exist_ok=True- )- pathlib.Path(self.media_root.name, 'exercise-images', '2').mkdir(- parents=True, exist_ok=True- )-- pathlib.Path(- self.media_root.name, 'exercise-images', '1', 'protestschwein.jpg'- ).write_bytes(- pathlib.Path('wger/exercises/tests/protestschwein.jpg').read_bytes(),- )- pathlib.Path(- self.media_root.name,- 'exercise-images',- '1',- 'wildschwein.jpg',- ).write_bytes(pathlib.Path('wger/exercises/tests/wildschwein.jpg').read_bytes())- pathlib.Path(- self.media_root.name,- 'exercise-images',- '2',- 'wildschwein.jpg',- ).write_bytes(pathlib.Path('wger/exercises/tests/wildschwein.jpg').read_bytes())-class WgerTestCase(BaseTestCase, TestCase):"""diff --git a/wger/exercises/tests/api/test_exercise_info_search_api.py b/wger/exercises/tests/api/test_exercise_info_search_api.pyindex 9f8f20089..d77990fd9 100644--- a/wger/exercises/tests/api/test_exercise_info_search_api.py+++ b/wger/exercises/tests/api/test_exercise_info_search_api.py@@ -27,10 +27,6 @@ from wger.core.tests.base_testcase import BaseTestCaseclass ExerciseInfoFilterApiTestCase(BaseTestCase, ApiBaseTestCase):url = '/api/v2/exerciseinfo/'- def setUp(self):- super().setUp()- self.init_media_root()-def _results(self, response):if isinstance(response.data, dict) and 'results' in response.data:return response.data['results']