From 13854998ea1a297cdc7da3b49e013bca436c17e3 Mon Sep 17 00:00:00 2001 From: Matthias Date: Sat, 7 May 2022 23:12:15 +0200 Subject: [PATCH] Add test for ColorTheme --- InvenTree/common/tests.py | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/InvenTree/common/tests.py b/InvenTree/common/tests.py index dee776f7d9..13f89d57bf 100644 --- a/InvenTree/common/tests.py +++ b/InvenTree/common/tests.py @@ -12,7 +12,7 @@ from InvenTree.api_tester import InvenTreeAPITestCase from InvenTree.helpers import str2bool from plugin.models import NotificationUserSetting -from .models import InvenTreeSetting, InvenTreeUserSetting, WebhookEndpoint, WebhookMessage, NotificationEntry +from .models import InvenTreeSetting, InvenTreeUserSetting, WebhookEndpoint, WebhookMessage, NotificationEntry, ColorTheme from .api import WebhookView CONTENT_TYPE_JSON = 'application/json' @@ -561,3 +561,24 @@ class LoadingTest(TestCase): # now it should be false again self.assertFalse(common.models.InvenTreeSetting.get_setting('SERVER_RESTART_REQUIRED')) + + +class ColorThemeTest(TestCase): + """Tests for ColorTheme""" + + def test_choices(self): + result = ColorTheme.get_color_themes_choices() + + self.assertIn(('default', 'Default'), result) + + def test_valid_choice(self): + # check wrong reference + self.assertFalse(ColorTheme.is_valid_choice('abcdd')) + + # create themes + aa = ColorTheme.objects.create(user='aa', name='testname') + ab = ColorTheme.objects.create(user='ab', name='darker') + + # check valid theme + self.assertFalse(ColorTheme.is_valid_choice(aa)) + self.assertTrue(ColorTheme.is_valid_choice(ab))