Update migrations to accept migrated settings

- Unify all conditional YAML load under utils.smart_yaml_load.
- Update all setting migrations to use the smart setting test
  mixin to create the test config file.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-12-10 19:57:14 -04:00
parent 9e9db800ad
commit a7cf6b5664
17 changed files with 179 additions and 226 deletions

View File

@@ -1,35 +1,30 @@
from __future__ import unicode_literals
from django.conf import settings
from django.utils.encoding import force_bytes
from mayan.apps.common.tests.base import BaseTestCase
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
from mayan.apps.smart_settings.classes import Setting
from mayan.apps.storage.utils import NamedTemporaryFile
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
from ..settings import setting_shared_storage_arguments
class CommonSettingMigrationTestCase(EnvironmentTestCaseMixin, BaseTestCase):
class CommonSettingMigrationTestCase(SmartSettingTestMixin, BaseTestCase):
def test_common_shared_storage_arguments_0001_migration(self):
test_value = {'location': 'test value'}
self.test_setting = setting_shared_storage_arguments
self.test_config_value = '{}'.format(test_value)
self._create_test_config_file()
with NamedTemporaryFile() as file_object:
settings.CONFIGURATION_FILEPATH = file_object.name
file_object.write(
force_bytes(
'{}: {}'.format(
'COMMON_SHARED_STORAGE_ARGUMENTS',
'"{}"'.format(Setting.serialize_value(value=test_value))
)
)
)
file_object.seek(0)
Setting._config_file_cache = None
self.assertEqual(
setting_shared_storage_arguments.value,
test_value
)
self.assertEqual(
setting_shared_storage_arguments.value,
test_value
)
def test_common_shared_storage_arguments_0001_migration_with_dict(self):
test_value = {'location': 'test value'}
self.test_setting = setting_shared_storage_arguments
self.test_config_value = test_value
self._create_test_config_file()
self.assertEqual(
setting_shared_storage_arguments.value,
test_value
)