diff --git a/mayan/apps/smart_settings/classes.py b/mayan/apps/smart_settings/classes.py index ccedbd5083..9f35323608 100644 --- a/mayan/apps/smart_settings/classes.py +++ b/mayan/apps/smart_settings/classes.py @@ -17,7 +17,9 @@ except ImportError: from django.apps import apps from django.conf import settings from django.utils.functional import Promise -from django.utils.encoding import force_text, python_2_unicode_compatible +from django.utils.encoding import ( + force_bytes, force_text, python_2_unicode_compatible +) logger = logging.getLogger(__name__) @@ -141,7 +143,7 @@ class Setting(object): @classmethod def get_hash(cls): return force_text( - hashlib.sha256(cls.dump_data()).hexdigest() + hashlib.sha256(force_bytes(cls.dump_data())).hexdigest() ) @classmethod diff --git a/mayan/apps/smart_settings/tests/test_classes.py b/mayan/apps/smart_settings/tests/test_classes.py index e4c919acce..6e88607f7f 100644 --- a/mayan/apps/smart_settings/tests/test_classes.py +++ b/mayan/apps/smart_settings/tests/test_classes.py @@ -11,12 +11,13 @@ from mayan.apps.common.settings import setting_paginate_by from mayan.apps.common.tests import BaseTestCase from mayan.apps.storage.utils import fs_cleanup -from ..classes import Setting +from ..classes import Namespace, Setting from .literals import ENVIRONMENT_TEST_NAME, ENVIRONMENT_TEST_VALUE +from .mixins import SmartSettingTestMixin -class ClassesTestCase(BaseTestCase): +class ClassesTestCase(SmartSettingTestMixin, BaseTestCase): def test_environment_variable(self): os.environ[ 'MAYAN_{}'.format(ENVIRONMENT_TEST_NAME) @@ -39,3 +40,16 @@ class ClassesTestCase(BaseTestCase): with path_config_backup.open(mode='r') as file_object: self.assertFalse('!!python/' in file_object.read()) + + def test_setting_check_changed(self): + self._create_test_settings_namespace() + test_setting = self.test_settings_namespace.add_setting( + global_name='SMART_SETTINGS_TEST_SETTING', + default='test value' + ) + # Initialize hash cache + Setting.check_changed() + self.assertFalse(Setting.check_changed()) + test_setting.value = 'test value edited' + self.assertTrue(Setting.check_changed()) +