Rename "has_globalsettings" -> "has_settings"

This commit is contained in:
Oliver 2022-01-01 23:14:34 +11:00
parent 7cb029e7c3
commit 737467a1fd
2 changed files with 6 additions and 12 deletions

View File

@ -17,11 +17,11 @@ class SettingsMixin:
def __init__(self):
super().__init__()
self.add_mixin('settings', 'has_globalsettings', __class__)
self.add_mixin('settings', 'has_settings', __class__)
self.globalsettings = getattr(self, 'SETTINGS', None)
@property
def has_globalsettings(self):
def has_settings(self):
"""
Does this plugin use custom global settings
"""
@ -32,7 +32,7 @@ class SettingsMixin:
"""
Get patterns for InvenTreeSetting defintion
"""
if self.has_globalsettings:
if self.has_settings:
return {f'PLUGIN_{self.slug.upper()}_{key}': value for key, value in self.globalsettings.items()}
return None

View File

@ -23,7 +23,7 @@ class BaseMixinDefinition:
class SettingsMixinTest(BaseMixinDefinition, TestCase):
MIXIN_HUMAN_NAME = 'Settings'
MIXIN_NAME = 'settings'
MIXIN_ENABLE_CHECK = 'has_globalsettings'
MIXIN_ENABLE_CHECK = 'has_settings'
TEST_SETTINGS = {'SETTING1': {'default': '123', }}
@ -44,21 +44,15 @@ class SettingsMixinTest(BaseMixinDefinition, TestCase):
# settings variable
self.assertEqual(self.mixin.globalsettings, self.TEST_SETTINGS)
# settings pattern
target_pattern = {f'PLUGIN_{self.mixin.slug.upper()}_{key}': value for key, value in self.mixin.globalsettings.items()}
self.assertEqual(self.mixin.globalsettingspatterns, target_pattern)
# no settings
self.assertIsNone(self.mixin_nothing.globalsettings)
self.assertIsNone(self.mixin_nothing.globalsettingspatterns)
# calling settings
# not existing
self.assertEqual(self.mixin.get_globalsetting('ABCD'), '')
self.assertEqual(self.mixin_nothing.get_globalsetting('ABCD'), '')
# right setting
self.mixin.set_globalsetting('SETTING1', '12345', self.test_user)
self.assertEqual(self.mixin.get_globalsetting('SETTING1'), '12345')
# no setting
self.assertEqual(self.mixin_nothing.get_globalsetting(''), '')