mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-05-01 11:19:32 -05:00
Fix and test migration
This commit is contained in:
parent
ea88466129
commit
79bf125e78
@ -55,7 +55,7 @@ def reverse_migrate_customfield_selects(apps, schema_editor):
|
|||||||
instance.value_select = next(
|
instance.value_select = next(
|
||||||
index
|
index
|
||||||
for index, option in enumerate(old_select_options)
|
for index, option in enumerate(old_select_options)
|
||||||
if option.id == instance.value_select
|
if option.get("id") == instance.value_select
|
||||||
)
|
)
|
||||||
instance.save()
|
instance.save()
|
||||||
|
|
||||||
|
@ -14,9 +14,18 @@ class TestMigrateCustomFieldSelects(TestMigrations):
|
|||||||
data_type="select",
|
data_type="select",
|
||||||
extra_data={"select_options": ["Option 1", "Option 2", "Option 3"]},
|
extra_data={"select_options": ["Option 1", "Option 2", "Option 3"]},
|
||||||
)
|
)
|
||||||
|
Document = apps.get_model("documents.Document")
|
||||||
|
doc = Document.objects.create(title="doc1")
|
||||||
|
CustomFieldInstance = apps.get_model("documents.CustomFieldInstance")
|
||||||
|
self.old_instance = CustomFieldInstance.objects.create(
|
||||||
|
field=self.old_format,
|
||||||
|
value_select=0,
|
||||||
|
document=doc,
|
||||||
|
)
|
||||||
|
|
||||||
def test_migrate_old_to_new_storage_path(self):
|
def test_migrate_old_to_new_storage_path(self):
|
||||||
self.old_format.refresh_from_db()
|
self.old_format.refresh_from_db()
|
||||||
|
self.old_instance.refresh_from_db()
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.old_format.extra_data["select_options"],
|
self.old_format.extra_data["select_options"],
|
||||||
@ -27,6 +36,11 @@ class TestMigrateCustomFieldSelects(TestMigrations):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.old_instance.value_select,
|
||||||
|
self.old_format.extra_data["select_options"][0]["id"],
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestMigrationCustomFieldSelectsReverse(TestMigrations):
|
class TestMigrationCustomFieldSelectsReverse(TestMigrations):
|
||||||
migrate_from = "1057_alter_customfieldinstance_value_select"
|
migrate_from = "1057_alter_customfieldinstance_value_select"
|
||||||
@ -45,9 +59,18 @@ class TestMigrationCustomFieldSelectsReverse(TestMigrations):
|
|||||||
],
|
],
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
Document = apps.get_model("documents.Document")
|
||||||
|
doc = Document.objects.create(title="doc1")
|
||||||
|
CustomFieldInstance = apps.get_model("documents.CustomFieldInstance")
|
||||||
|
self.new_instance = CustomFieldInstance.objects.create(
|
||||||
|
field=self.new_format,
|
||||||
|
value_select="id1",
|
||||||
|
document=doc,
|
||||||
|
)
|
||||||
|
|
||||||
def test_migrate_new_to_old_storage_path(self):
|
def test_migrate_new_to_old_storage_path(self):
|
||||||
self.new_format.refresh_from_db()
|
self.new_format.refresh_from_db()
|
||||||
|
self.new_instance.refresh_from_db()
|
||||||
|
|
||||||
self.assertEqual(
|
self.assertEqual(
|
||||||
self.new_format.extra_data["select_options"],
|
self.new_format.extra_data["select_options"],
|
||||||
@ -57,3 +80,8 @@ class TestMigrationCustomFieldSelectsReverse(TestMigrations):
|
|||||||
"Option 3",
|
"Option 3",
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
self.new_instance.value_select,
|
||||||
|
0,
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user