A community-supported supercharged document management system: scan, index and archive all your documents
Python aiangulararchivingdjangodmsdocument-managementdocument-management-systemllmmachine-learningocroptical-character-recognitionpdf
refactor migration test case
jonaswinkler302ebf737e7d
diff --git a/src/documents/tests/test_migrations.py b/src/documents/tests/test_migration_mime_type.pysimilarity index 66%rename from src/documents/tests/test_migrations.pyrename to src/documents/tests/test_migration_mime_type.pyindex ee7180c63..5e825e89d 100644--- a/src/documents/tests/test_migrations.py+++ b/src/documents/tests/test_migration_mime_type.py@@ -1,52 +1,11 @@import osimport shutil-from pathlib import Path-from django.apps import appsfrom django.conf import settings-from django.db import connection-from django.db.migrations.executor import MigrationExecutor-from django.test import TestCase, TransactionTestCase, override_settings+from django.test import override_settings-from documents.models import Documentfrom documents.parsers import get_default_file_extension-from documents.tests.utils import DirectoriesMixin---class TestMigrations(TransactionTestCase):-- @property- def app(self):- return apps.get_containing_app_config(type(self).__module__).name-- migrate_from = None- migrate_to = None-- def setUp(self):- super(TestMigrations, self).setUp()-- assert self.migrate_from and self.migrate_to, \- "TestCase '{}' must define migrate_from and migrate_to properties".format(type(self).__name__)- self.migrate_from = [(self.app, self.migrate_from)]- self.migrate_to = [(self.app, self.migrate_to)]- executor = MigrationExecutor(connection)- old_apps = executor.loader.project_state(self.migrate_from).apps-- # Reverse to the original migration- executor.migrate(self.migrate_from)-- self.setUpBeforeMigration(old_apps)-- # Run the migration to test- executor = MigrationExecutor(connection)- executor.loader.build_graph() # reload.- executor.migrate(self.migrate_to)-- self.apps = executor.loader.project_state(self.migrate_to).apps-- def setUpBeforeMigration(self, apps):- pass-+from documents.tests.utils import DirectoriesMixin, TestMigrationsSTORAGE_TYPE_UNENCRYPTED = "unencrypted"STORAGE_TYPE_GPG = "gpg"diff --git a/src/documents/tests/utils.py b/src/documents/tests/utils.pyindex ebf79f6c5..b9be25d70 100644--- a/src/documents/tests/utils.py+++ b/src/documents/tests/utils.py@@ -4,7 +4,10 @@ import tempfilefrom collections import namedtuplefrom contextlib import contextmanager-from django.test import override_settings+from django.apps import apps+from django.db import connection+from django.db.migrations.executor import MigrationExecutor+from django.test import override_settings, TransactionTestCasedef setup_directories():@@ -79,3 +82,38 @@ class DirectoriesMixin:def tearDown(self) -> None:super(DirectoriesMixin, self).tearDown()remove_dirs(self.dirs)+++class TestMigrations(TransactionTestCase):++ @property+ def app(self):+ return apps.get_containing_app_config(type(self).__module__).name++ migrate_from = None+ migrate_to = None++ def setUp(self):+ super(TestMigrations, self).setUp()++ assert self.migrate_from and self.migrate_to, \+ "TestCase '{}' must define migrate_from and migrate_to properties".format(type(self).__name__)+ self.migrate_from = [(self.app, self.migrate_from)]+ self.migrate_to = [(self.app, self.migrate_to)]+ executor = MigrationExecutor(connection)+ old_apps = executor.loader.project_state(self.migrate_from).apps++ # Reverse to the original migration+ executor.migrate(self.migrate_from)++ self.setUpBeforeMigration(old_apps)++ # Run the migration to test+ executor = MigrationExecutor(connection)+ executor.loader.build_graph() # reload.+ executor.migrate(self.migrate_to)++ self.apps = executor.loader.project_state(self.migrate_to).apps++ def setUpBeforeMigration(self, apps):+ pass