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:
@@ -7,6 +7,8 @@
|
|||||||
Rob de Canha-Knight (@rssfed23) for the report and the research.
|
Rob de Canha-Knight (@rssfed23) for the report and the research.
|
||||||
- Update instances of the word "weblink" to "web link".
|
- Update instances of the word "weblink" to "web link".
|
||||||
- Unify the creation of the temporary config file used in tests.
|
- Unify the creation of the temporary config file used in tests.
|
||||||
|
- Update all 0001 setting migrations to not accept manually migrated
|
||||||
|
settings.
|
||||||
|
|
||||||
3.3.4 (2019-12-09)
|
3.3.4 (2019-12-09)
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mayan.apps.smart_settings.classes import NamespaceMigration
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
from mayan.apps.smart_settings.utils import smart_yaml_load
|
||||||
from .serialization import yaml_load
|
|
||||||
|
|
||||||
|
|
||||||
class CommonSettingMigration(NamespaceMigration):
|
class CommonSettingMigration(NamespaceMigration):
|
||||||
@@ -11,6 +10,4 @@ class CommonSettingMigration(NamespaceMigration):
|
|||||||
but YAML valid too. Changed in version 3.3.
|
but YAML valid too. Changed in version 3.3.
|
||||||
"""
|
"""
|
||||||
def common_shared_storage_arguments_0001(self, value):
|
def common_shared_storage_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,35 +1,30 @@
|
|||||||
from __future__ import unicode_literals
|
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.base import BaseTestCase
|
||||||
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
|
||||||
from mayan.apps.smart_settings.classes import Setting
|
|
||||||
from mayan.apps.storage.utils import NamedTemporaryFile
|
|
||||||
|
|
||||||
from ..settings import setting_shared_storage_arguments
|
from ..settings import setting_shared_storage_arguments
|
||||||
|
|
||||||
|
|
||||||
class CommonSettingMigrationTestCase(EnvironmentTestCaseMixin, BaseTestCase):
|
class CommonSettingMigrationTestCase(SmartSettingTestMixin, BaseTestCase):
|
||||||
def test_common_shared_storage_arguments_0001_migration(self):
|
def test_common_shared_storage_arguments_0001_migration(self):
|
||||||
|
|
||||||
test_value = {'location': 'test value'}
|
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:
|
self.assertEqual(
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
setting_shared_storage_arguments.value,
|
||||||
file_object.write(
|
test_value
|
||||||
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(
|
def test_common_shared_storage_arguments_0001_migration_with_dict(self):
|
||||||
setting_shared_storage_arguments.value,
|
test_value = {'location': 'test value'}
|
||||||
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
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mayan.apps.common.serialization import yaml_load
|
|
||||||
from mayan.apps.smart_settings.classes import NamespaceMigration
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
from mayan.apps.smart_settings.utils import smart_yaml_load
|
||||||
|
|
||||||
|
|
||||||
class ConvertSettingMigration(NamespaceMigration):
|
class ConvertSettingMigration(NamespaceMigration):
|
||||||
@@ -10,6 +10,4 @@ class ConvertSettingMigration(NamespaceMigration):
|
|||||||
but YAML valid too. Changed in version 3.3.
|
but YAML valid too. Changed in version 3.3.
|
||||||
"""
|
"""
|
||||||
def converter_graphics_backend_arguments_0001(self, value):
|
def converter_graphics_backend_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,39 +1,32 @@
|
|||||||
from __future__ import unicode_literals
|
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.base import BaseTestCase
|
||||||
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
|
||||||
from mayan.apps.smart_settings.classes import Setting
|
|
||||||
from mayan.apps.storage.utils import NamedTemporaryFile
|
|
||||||
|
|
||||||
from ..settings import setting_graphics_backend_arguments
|
from ..settings import setting_graphics_backend_arguments
|
||||||
|
|
||||||
|
|
||||||
class ConverterSettingMigrationTestCase(
|
class ConverterSettingMigrationTestCase(
|
||||||
EnvironmentTestCaseMixin, BaseTestCase
|
SmartSettingTestMixin, BaseTestCase
|
||||||
):
|
):
|
||||||
def test_converter_graphics_backend_arguments_0001_migration(self):
|
def test_converter_graphics_backend_arguments_0001_migration(self):
|
||||||
|
|
||||||
test_value = {'location': 'test value'}
|
test_value = {'location': 'test value'}
|
||||||
|
self.test_setting = setting_graphics_backend_arguments
|
||||||
|
self.test_config_value = '{}'.format(test_value)
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
with NamedTemporaryFile() as file_object:
|
self.assertEqual(
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
setting_graphics_backend_arguments.value,
|
||||||
file_object.write(
|
test_value
|
||||||
force_bytes(
|
)
|
||||||
'{}: {}'.format(
|
|
||||||
'CONVERTER_GRAPHICS_BACKEND_ARGUMENTS',
|
|
||||||
'"{}"'.format(
|
|
||||||
Setting.serialize_value(value=test_value)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
file_object.seek(0)
|
|
||||||
Setting._config_file_cache = None
|
|
||||||
|
|
||||||
self.assertEqual(
|
def test_converter_graphics_backend_arguments_0001_migration_with_dict(self):
|
||||||
setting_graphics_backend_arguments.value,
|
test_value = {'location': 'test value'}
|
||||||
test_value
|
self.test_setting = setting_graphics_backend_arguments
|
||||||
)
|
self.test_config_value = test_value
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
setting_graphics_backend_arguments.value,
|
||||||
|
test_value
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mayan.apps.common.serialization import yaml_load
|
|
||||||
from mayan.apps.smart_settings.classes import NamespaceMigration
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
from mayan.apps.smart_settings.utils import smart_yaml_load
|
||||||
|
|
||||||
|
|
||||||
class DocumentSignaturesSettingMigration(NamespaceMigration):
|
class DocumentSignaturesSettingMigration(NamespaceMigration):
|
||||||
@@ -10,6 +10,4 @@ class DocumentSignaturesSettingMigration(NamespaceMigration):
|
|||||||
but YAML valid too. Changed in version 3.3.
|
but YAML valid too. Changed in version 3.3.
|
||||||
"""
|
"""
|
||||||
def signatures_storage_backend_arguments_0001(self, value):
|
def signatures_storage_backend_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,39 +1,32 @@
|
|||||||
from __future__ import unicode_literals
|
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.base import BaseTestCase
|
||||||
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
|
||||||
from mayan.apps.smart_settings.classes import Setting
|
|
||||||
from mayan.apps.storage.utils import NamedTemporaryFile
|
|
||||||
|
|
||||||
from ..settings import setting_storage_backend_arguments
|
from ..settings import setting_storage_backend_arguments
|
||||||
|
|
||||||
|
|
||||||
class DocumentSignaturesSettingMigrationTestCase(
|
class DocumentSignaturesSettingMigrationTestCase(
|
||||||
EnvironmentTestCaseMixin, BaseTestCase
|
SmartSettingTestMixin, BaseTestCase
|
||||||
):
|
):
|
||||||
def test_signatures_storage_backend_arguments_0001_migration(self):
|
def test_signatures_storage_backend_arguments_0001_migration(self):
|
||||||
|
|
||||||
test_value = {'location': 'test value'}
|
test_value = {'location': 'test value'}
|
||||||
|
self.test_setting = setting_storage_backend_arguments
|
||||||
|
self.test_config_value = '{}'.format(test_value)
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
with NamedTemporaryFile() as file_object:
|
self.assertEqual(
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
setting_storage_backend_arguments.value,
|
||||||
file_object.write(
|
test_value
|
||||||
force_bytes(
|
)
|
||||||
'{}: {}'.format(
|
|
||||||
'SIGNATURES_STORAGE_BACKEND_ARGUMENTS',
|
|
||||||
'"{}"'.format(
|
|
||||||
Setting.serialize_value(value=test_value)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
file_object.seek(0)
|
|
||||||
Setting._config_file_cache = None
|
|
||||||
|
|
||||||
self.assertEqual(
|
def test_signatures_storage_backend_arguments_0001_migration_with_dict(self):
|
||||||
setting_storage_backend_arguments.value,
|
test_value = {'location': 'test value'}
|
||||||
test_value
|
self.test_setting = setting_storage_backend_arguments
|
||||||
)
|
self.test_config_value = test_value
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
setting_storage_backend_arguments.value,
|
||||||
|
test_value
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mayan.apps.common.serialization import yaml_load
|
|
||||||
from mayan.apps.smart_settings.classes import NamespaceMigration
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
from mayan.apps.smart_settings.utils import smart_yaml_load
|
||||||
|
|
||||||
|
|
||||||
class DocumentsSettingMigration(NamespaceMigration):
|
class DocumentsSettingMigration(NamespaceMigration):
|
||||||
@@ -10,11 +10,7 @@ class DocumentsSettingMigration(NamespaceMigration):
|
|||||||
but YAML valid too. Changed in version 3.3.
|
but YAML valid too. Changed in version 3.3.
|
||||||
"""
|
"""
|
||||||
def documents_cache_storage_backend_arguments_0001(self, value):
|
def documents_cache_storage_backend_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|
||||||
def documents_storage_backend_arguments_0001(self, value):
|
def documents_storage_backend_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,12 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
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.base import BaseTestCase
|
||||||
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
|
||||||
from mayan.apps.smart_settings.classes import Setting
|
|
||||||
from mayan.apps.storage.utils import NamedTemporaryFile
|
|
||||||
|
|
||||||
from ..settings import (
|
from ..settings import (
|
||||||
setting_documentimagecache_storage_arguments,
|
setting_documentimagecache_storage_arguments,
|
||||||
@@ -14,49 +9,47 @@ from ..settings import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class DocumentSettingMigrationTestCase(EnvironmentTestCaseMixin, BaseTestCase):
|
class DocumentSettingMigrationTestCase(SmartSettingTestMixin, BaseTestCase):
|
||||||
def test_documents_storage_backend_arguments_0001(self):
|
def test_documents_storage_backend_arguments_0001(self):
|
||||||
test_value = {'location': 'test value'}
|
test_value = {'location': 'test value'}
|
||||||
|
self.test_setting = setting_documentimagecache_storage_arguments
|
||||||
|
self.test_config_value = '{}'.format(test_value)
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
with NamedTemporaryFile() as file_object:
|
self.assertEqual(
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
setting_documentimagecache_storage_arguments.value,
|
||||||
file_object.write(
|
test_value
|
||||||
force_bytes(
|
)
|
||||||
'{}: {}'.format(
|
|
||||||
'DOCUMENTS_CACHE_STORAGE_BACKEND_ARGUMENTS',
|
|
||||||
'"{}"'.format(
|
|
||||||
Setting.serialize_value(value=test_value)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
file_object.seek(0)
|
|
||||||
Setting._config_file_cache = None
|
|
||||||
|
|
||||||
self.assertEqual(
|
def test_documents_storage_backend_arguments_0001_with_dict(self):
|
||||||
setting_documentimagecache_storage_arguments.value,
|
test_value = {'location': 'test value'}
|
||||||
test_value
|
self.test_setting = setting_documentimagecache_storage_arguments
|
||||||
)
|
self.test_config_value = test_value
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
setting_documentimagecache_storage_arguments.value,
|
||||||
|
test_value
|
||||||
|
)
|
||||||
|
|
||||||
def test_documents_cache_storage_backend_arguments_0001(self):
|
def test_documents_cache_storage_backend_arguments_0001(self):
|
||||||
test_value = {'location': 'test value'}
|
test_value = {'location': 'test value'}
|
||||||
|
self.test_setting = setting_storage_backend_arguments
|
||||||
|
self.test_config_value = '{}'.format(test_value)
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
with NamedTemporaryFile() as file_object:
|
self.assertEqual(
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
setting_storage_backend_arguments.value,
|
||||||
file_object.write(
|
test_value
|
||||||
force_bytes(
|
)
|
||||||
'{}: {}'.format(
|
|
||||||
'DOCUMENTS_STORAGE_BACKEND_ARGUMENTS',
|
|
||||||
'"{}"'.format(
|
|
||||||
Setting.serialize_value(value=test_value)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
file_object.seek(0)
|
|
||||||
Setting._config_file_cache = None
|
|
||||||
|
|
||||||
self.assertEqual(
|
def test_documents_cache_storage_backend_arguments_0001_with_dict(self):
|
||||||
setting_storage_backend_arguments.value,
|
test_value = {'location': 'test value'}
|
||||||
test_value
|
self.test_setting = setting_storage_backend_arguments
|
||||||
)
|
self.test_config_value = test_value
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
setting_storage_backend_arguments.value,
|
||||||
|
test_value
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mayan.apps.common.serialization import yaml_load
|
|
||||||
from mayan.apps.smart_settings.classes import NamespaceMigration
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
from mayan.apps.smart_settings.utils import smart_yaml_load
|
||||||
|
|
||||||
|
|
||||||
class FileMetadataSettingMigration(NamespaceMigration):
|
class FileMetadataSettingMigration(NamespaceMigration):
|
||||||
@@ -10,6 +10,4 @@ class FileMetadataSettingMigration(NamespaceMigration):
|
|||||||
but YAML valid too. Changed in version 3.3.
|
but YAML valid too. Changed in version 3.3.
|
||||||
"""
|
"""
|
||||||
def file_metadata_drivers_arguments_0001(self, value):
|
def file_metadata_drivers_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,39 +1,32 @@
|
|||||||
from __future__ import unicode_literals
|
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.base import BaseTestCase
|
||||||
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
|
||||||
from mayan.apps.smart_settings.classes import Setting
|
|
||||||
from mayan.apps.storage.utils import NamedTemporaryFile
|
|
||||||
|
|
||||||
from ..settings import setting_drivers_arguments
|
from ..settings import setting_drivers_arguments
|
||||||
|
|
||||||
|
|
||||||
class FileMetadataSettingMigrationTestCase(
|
class FileMetadataSettingMigrationTestCase(
|
||||||
EnvironmentTestCaseMixin, BaseTestCase
|
SmartSettingTestMixin, BaseTestCase
|
||||||
):
|
):
|
||||||
def test_file_metadata_drivers_arguments_0001_migration(self):
|
def test_file_metadata_drivers_arguments_0001_migration(self):
|
||||||
|
|
||||||
test_value = {'location': 'test value'}
|
test_value = {'location': 'test value'}
|
||||||
|
self.test_setting = setting_drivers_arguments
|
||||||
|
self.test_config_value = '{}'.format(test_value)
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
with NamedTemporaryFile() as file_object:
|
self.assertEqual(
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
setting_drivers_arguments.value,
|
||||||
file_object.write(
|
test_value
|
||||||
force_bytes(
|
)
|
||||||
'{}: {}'.format(
|
|
||||||
'FILE_METADATA_DRIVERS_ARGUMENTS',
|
|
||||||
'"{}"'.format(
|
|
||||||
Setting.serialize_value(value=test_value)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
file_object.seek(0)
|
|
||||||
Setting._config_file_cache = None
|
|
||||||
|
|
||||||
self.assertEqual(
|
def test_file_metadata_drivers_arguments_0001_migration_with_dict(self):
|
||||||
setting_drivers_arguments.value,
|
test_value = {'location': 'test value'}
|
||||||
test_value
|
self.test_setting = setting_drivers_arguments
|
||||||
)
|
self.test_config_value = test_value
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
setting_drivers_arguments.value,
|
||||||
|
test_value
|
||||||
|
)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mayan.apps.common.serialization import yaml_load
|
|
||||||
from mayan.apps.smart_settings.classes import NamespaceMigration
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
from mayan.apps.smart_settings.utils import smart_yaml_load
|
||||||
|
|
||||||
|
|
||||||
class OCRSettingMigration(NamespaceMigration):
|
class OCRSettingMigration(NamespaceMigration):
|
||||||
@@ -10,6 +10,4 @@ class OCRSettingMigration(NamespaceMigration):
|
|||||||
but YAML valid too. Changed in version 3.3.
|
but YAML valid too. Changed in version 3.3.
|
||||||
"""
|
"""
|
||||||
def ocr_backend_arguments_0001(self, value):
|
def ocr_backend_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,36 +1,28 @@
|
|||||||
from __future__ import unicode_literals
|
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.base import BaseTestCase
|
||||||
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
|
||||||
from mayan.apps.smart_settings.classes import Setting
|
|
||||||
from mayan.apps.storage.utils import NamedTemporaryFile
|
|
||||||
|
|
||||||
from ..settings import setting_ocr_backend_arguments
|
from ..settings import setting_ocr_backend_arguments
|
||||||
|
|
||||||
|
|
||||||
class OCRSettingMigrationTestCase(EnvironmentTestCaseMixin, BaseTestCase):
|
class OCRSettingMigrationTestCase(SmartSettingTestMixin, BaseTestCase):
|
||||||
def test_ocr_backend_arguments_0001(self):
|
def test_ocr_backend_arguments_0001(self):
|
||||||
|
|
||||||
test_value = {'location': 'test value'}
|
test_value = {'location': 'test value'}
|
||||||
|
self.test_setting = setting_ocr_backend_arguments
|
||||||
|
self.test_config_value = '{}'.format(test_value)
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
with NamedTemporaryFile() as file_object:
|
self.assertEqual(
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
setting_ocr_backend_arguments.value, test_value
|
||||||
file_object.write(
|
)
|
||||||
force_bytes(
|
|
||||||
'{}: {}'.format(
|
|
||||||
'OCR_BACKEND_ARGUMENTS',
|
|
||||||
'"{}"'.format(
|
|
||||||
Setting.serialize_value(value=test_value)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
file_object.seek(0)
|
|
||||||
Setting._config_file_cache = None
|
|
||||||
|
|
||||||
self.assertEqual(
|
def test_ocr_backend_arguments_0001_with_dict(self):
|
||||||
setting_ocr_backend_arguments.value, test_value
|
test_value = {'location': 'test value'}
|
||||||
)
|
self.test_setting = setting_ocr_backend_arguments
|
||||||
|
self.test_config_value = test_value
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
setting_ocr_backend_arguments.value, test_value
|
||||||
|
)
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ from __future__ import absolute_import, unicode_literals
|
|||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
from django.utils.encoding import force_bytes
|
from django.utils.encoding import force_bytes
|
||||||
|
|
||||||
|
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
||||||
from mayan.apps.storage.utils import fs_cleanup, NamedTemporaryFile
|
from mayan.apps.storage.utils import fs_cleanup, NamedTemporaryFile
|
||||||
|
|
||||||
from ..classes import Namespace, Setting
|
from ..classes import Namespace, Setting
|
||||||
@@ -36,7 +37,7 @@ class SmartSettingsTestCaseMixin(object):
|
|||||||
Namespace.invalidate_cache_all()
|
Namespace.invalidate_cache_all()
|
||||||
|
|
||||||
|
|
||||||
class SmartSettingTestMixin(object):
|
class SmartSettingTestMixin(EnvironmentTestCaseMixin):
|
||||||
test_setting_global_name = None
|
test_setting_global_name = None
|
||||||
test_config_file_object = None
|
test_config_file_object = None
|
||||||
|
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import os
|
|||||||
|
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
|
from mayan.apps.common.compat import dict_type
|
||||||
from mayan.apps.common.serialization import yaml_load
|
from mayan.apps.common.serialization import yaml_load
|
||||||
|
|
||||||
from .literals import (
|
from .literals import (
|
||||||
@@ -219,6 +220,15 @@ class MediaBootstrapSetting(FilesystemBootstrapSetting):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def smart_yaml_load(value):
|
||||||
|
if isinstance(value, dict_type):
|
||||||
|
return value
|
||||||
|
else:
|
||||||
|
return yaml_load(
|
||||||
|
stream=value or '{}',
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# FilesystemBootstrapSetting settings
|
# FilesystemBootstrapSetting settings
|
||||||
|
|
||||||
SettingNamespaceSingleton.register_setting(
|
SettingNamespaceSingleton.register_setting(
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from mayan.apps.common.serialization import yaml_load
|
|
||||||
from mayan.apps.smart_settings.classes import NamespaceMigration
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
from mayan.apps.smart_settings.utils import smart_yaml_load
|
||||||
|
|
||||||
|
|
||||||
class SourcesSettingMigration(NamespaceMigration):
|
class SourcesSettingMigration(NamespaceMigration):
|
||||||
@@ -10,6 +10,4 @@ class SourcesSettingMigration(NamespaceMigration):
|
|||||||
but YAML valid too. Changed in version 3.3.
|
but YAML valid too. Changed in version 3.3.
|
||||||
"""
|
"""
|
||||||
def sources_staging_file_cache_storage_backend_arguments_0001(self, value):
|
def sources_staging_file_cache_storage_backend_arguments_0001(self, value):
|
||||||
return yaml_load(
|
return smart_yaml_load(value=value)
|
||||||
stream=value or '{}',
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,35 +1,33 @@
|
|||||||
from __future__ import unicode_literals
|
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.base import BaseTestCase
|
||||||
from mayan.apps.common.tests.mixins import EnvironmentTestCaseMixin
|
from mayan.apps.smart_settings.tests.mixins import SmartSettingTestMixin
|
||||||
from mayan.apps.smart_settings.classes import Setting
|
|
||||||
from mayan.apps.storage.utils import NamedTemporaryFile
|
|
||||||
|
|
||||||
from ..settings import setting_staging_file_image_cache_storage_arguments
|
from ..settings import setting_staging_file_image_cache_storage_arguments
|
||||||
|
|
||||||
|
|
||||||
class SourceSettingMigrationTestCase(EnvironmentTestCaseMixin, BaseTestCase):
|
class SourceSettingMigrationTestCase(
|
||||||
|
SmartSettingTestMixin, BaseTestCase
|
||||||
|
):
|
||||||
def test_setting_staging_file_image_cache_storage_arguments_0001_migration(self):
|
def test_setting_staging_file_image_cache_storage_arguments_0001_migration(self):
|
||||||
|
test_value = {'location': 'test value'}
|
||||||
|
self.test_setting = setting_staging_file_image_cache_storage_arguments
|
||||||
|
self.test_config_value = '{}'.format(test_value)
|
||||||
|
self._create_test_config_file()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
setting_staging_file_image_cache_storage_arguments.value,
|
||||||
|
test_value
|
||||||
|
)
|
||||||
|
|
||||||
|
def test_setting_staging_file_image_cache_storage_arguments_0001_migration_with_dict(self):
|
||||||
test_value = {'location': 'test value'}
|
test_value = {'location': 'test value'}
|
||||||
|
|
||||||
with NamedTemporaryFile() as file_object:
|
self.test_setting = setting_staging_file_image_cache_storage_arguments
|
||||||
settings.CONFIGURATION_FILEPATH = file_object.name
|
self.test_config_value = test_value
|
||||||
file_object.write(
|
self._create_test_config_file()
|
||||||
force_bytes(
|
|
||||||
'{}: {}'.format(
|
|
||||||
'SOURCES_STAGING_FILE_CACHE_STORAGE_BACKEND_ARGUMENTS',
|
|
||||||
'"{}"'.format(Setting.serialize_value(value=test_value))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
file_object.seek(0)
|
|
||||||
Setting._config_file_cache = None
|
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
setting_staging_file_image_cache_storage_arguments.value,
|
setting_staging_file_image_cache_storage_arguments.value,
|
||||||
test_value
|
test_value
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user