Add OCR app setting migrations
Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
- Improve setting migration method matching. Avoid executing
|
- Improve setting migration method matching. Avoid executing
|
||||||
a migrations for settings with similar but shorter names.
|
a migrations for settings with similar but shorter names.
|
||||||
- Fix sources app setting migrations.
|
- Fix sources app setting migrations.
|
||||||
|
- Add OCR app setting migrations.
|
||||||
|
|
||||||
3.3.1 (2019-12-04)
|
3.3.1 (2019-12-04)
|
||||||
==================
|
==================
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from mayan.apps.common.serialization import yaml_load
|
||||||
|
from mayan.apps.smart_settings.classes import NamespaceMigration
|
||||||
|
|
||||||
|
|
||||||
|
class OCRSettingMigration(NamespaceMigration):
|
||||||
|
"""
|
||||||
|
From version 0001 to 0002 backend arguments are no longer quoted
|
||||||
|
but YAML valid too. Changed in version 3.3.
|
||||||
|
"""
|
||||||
|
def ocr_backend_arguments_0001(self, value):
|
||||||
|
return yaml_load(
|
||||||
|
stream=value or '{}',
|
||||||
|
)
|
||||||
@@ -4,7 +4,12 @@ from django.utils.translation import ugettext_lazy as _
|
|||||||
|
|
||||||
from mayan.apps.smart_settings.classes import Namespace
|
from mayan.apps.smart_settings.classes import Namespace
|
||||||
|
|
||||||
namespace = Namespace(label=_('OCR'), name='ocr')
|
from .setting_migrations import OCRSettingMigration
|
||||||
|
|
||||||
|
namespace = Namespace(
|
||||||
|
label=_('OCR'), migration_class=OCRSettingMigration, name='ocr',
|
||||||
|
version='0002'
|
||||||
|
)
|
||||||
|
|
||||||
setting_ocr_backend = namespace.add_setting(
|
setting_ocr_backend = namespace.add_setting(
|
||||||
global_name='OCR_BACKEND',
|
global_name='OCR_BACKEND',
|
||||||
|
|||||||
@@ -0,0 +1,36 @@
|
|||||||
|
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 ..settings import setting_ocr_backend_arguments
|
||||||
|
|
||||||
|
|
||||||
|
class OCRSettingMigrationTestCase(EnvironmentTestCaseMixin, BaseTestCase):
|
||||||
|
def test_ocr_backend_arguments_0001(self):
|
||||||
|
|
||||||
|
test_value = {'location': 'test value'}
|
||||||
|
|
||||||
|
with NamedTemporaryFile() as file_object:
|
||||||
|
settings.CONFIGURATION_FILEPATH = file_object.name
|
||||||
|
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(
|
||||||
|
setting_ocr_backend_arguments.value, test_value
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user