From 0f6551d70f4dccd970d409b2d0008d488ad75896 Mon Sep 17 00:00:00 2001 From: Matthias Mair Date: Mon, 22 Jul 2024 01:53:16 +0200 Subject: [PATCH] cI: Test color theme again (#7700) * Adjust caching key to be numeric for user * Add strong usermodel to colortheme * switch to using user model everywhere for colortheme * re-enable ColorTheme tests * fix call * remove old migratin * fix directory discovery --- src/backend/InvenTree/common/models.py | 14 +++++++++++--- src/backend/InvenTree/common/tests.py | 10 ---------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/backend/InvenTree/common/models.py b/src/backend/InvenTree/common/models.py index a55e829cc8..4dd125d5a5 100644 --- a/src/backend/InvenTree/common/models.py +++ b/src/backend/InvenTree/common/models.py @@ -2589,14 +2589,22 @@ class ColorTheme(models.Model): @classmethod def get_color_themes_choices(cls): """Get all color themes from static folder.""" - if not django_settings.STATIC_COLOR_THEMES_DIR.exists(): - logger.error('Theme directory does not exist') + color_theme_dir = ( + django_settings.STATIC_COLOR_THEMES_DIR + if django_settings.STATIC_COLOR_THEMES_DIR.exists() + else django_settings.BASE_DIR.joinpath( + 'InvenTree', 'static', 'css', 'color-themes' + ) + ) + + if not color_theme_dir.exists(): + logger.error(f'Theme directory "{color_theme_dir}" does not exist') return [] # Get files list from css/color-themes/ folder files_list = [] - for file in django_settings.STATIC_COLOR_THEMES_DIR.iterdir(): + for file in color_theme_dir.iterdir(): files_list.append([file.stem, file.suffix]) # Get color themes choices (CSS sheets) diff --git a/src/backend/InvenTree/common/tests.py b/src/backend/InvenTree/common/tests.py index 9c3dea87d7..b08ab0b5f2 100644 --- a/src/backend/InvenTree/common/tests.py +++ b/src/backend/InvenTree/common/tests.py @@ -1199,20 +1199,10 @@ class ColorThemeTest(TestCase): def test_choices(self): """Test that default choices are returned.""" result = ColorTheme.get_color_themes_choices() - - # skip due to directories not being set up - if not result: - return # pragma: no cover self.assertIn(('default', 'Default'), result) def test_valid_choice(self): """Check that is_valid_choice works correctly.""" - result = ColorTheme.get_color_themes_choices() - - # skip due to directories not being set up - if not result: - return # pragma: no cover - # check wrong reference self.assertFalse(ColorTheme.is_valid_choice('abcdd'))