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
This commit is contained in:
Matthias Mair 2024-07-22 01:53:16 +02:00 committed by GitHub
parent 0effb44402
commit 0f6551d70f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 11 additions and 13 deletions

View File

@ -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)

View File

@ -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'))