Improve setting migration method matching

Avoid executing a migrations for settings with similar but
shorter names.

Signed-off-by: Roberto Rosario <roberto.rosario@mayan-edms.com>
This commit is contained in:
Roberto Rosario
2019-12-04 23:05:50 -04:00
parent 5070a4fcd6
commit aa3495ff18
4 changed files with 73 additions and 11 deletions
@@ -17,7 +17,10 @@ from .literals import (
TEST_SETTING_INITIAL_VALUE, TEST_SETTING_VALUE
)
from .mixins import SmartSettingTestMixin
from .mocks import TestNamespaceMigrationOne, TestNamespaceMigrationTwo
from .mocks import (
TestNamespaceMigrationOne, TestNamespaceMigrationTwo,
TestNamespaceMigrationInvalid, TestNamespaceMigrationInvalidDual
)
class ClassesTestCase(EnvironmentTestCaseMixin, SmartSettingTestMixin, BaseTestCase):
@@ -116,3 +119,43 @@ class NamespaceMigrationTestCase(
self.assertEqual(
self.test_setting.value, '{}_0001_0002'.format(TEST_SETTING_VALUE)
)
def test_migration_invalid(self):
self._create_test_settings_namespace(
migration_class=TestNamespaceMigrationInvalid, version='0002'
)
self._create_test_setting()
with NamedTemporaryFile() as file_object:
settings.CONFIGURATION_FILEPATH = file_object.name
file_object.write(
force_bytes(
'{}: {}'.format(TEST_SETTING_GLOBAL_NAME, TEST_SETTING_VALUE)
)
)
file_object.seek(0)
Setting._config_file_cache = None
self.assertEqual(
self.test_setting.value, TEST_SETTING_VALUE
)
def test_migration_invalid_dual(self):
self._create_test_settings_namespace(
migration_class=TestNamespaceMigrationInvalidDual, version='0002'
)
self._create_test_setting()
with NamedTemporaryFile() as file_object:
settings.CONFIGURATION_FILEPATH = file_object.name
file_object.write(
force_bytes(
'{}: {}'.format(TEST_SETTING_GLOBAL_NAME, TEST_SETTING_VALUE)
)
)
file_object.seek(0)
Setting._config_file_cache = None
self.assertEqual(
self.test_setting.value, TEST_SETTING_VALUE
)