combo/tests/test_migrations.py

125 lines
4.5 KiB
Python

from django.db import connection
from django.db.migrations.executor import MigrationExecutor
def test_page_snapshot_with_old_card_cells_migration(transactional_db):
migrate_from = [('data', '0062_page_uuid')]
migrate_to = [('data', '0063_old_card_cells')]
executor = MigrationExecutor(connection)
old_apps = executor.loader.project_state(migrate_from).apps
executor.migrate(migrate_from)
pagesnapshot_class = old_apps.get_model('data', 'PageSnapshot')
snapshot = pagesnapshot_class.objects.create(
serialization={
'cells': [
{
'model': 'wcs.wcscardinfoscell',
'fields': {
'card_ids': '42,35',
'title_type': 'manual',
'custom_title': 'my-title',
'display_mode': 'card',
'without_user': True,
'custom_schema': {},
'only_for_user': True,
'carddef_reference': 'default:card_model_1',
'related_card_path': '',
'limit': 42,
'slug': 'my-card',
'order': 1,
'groups': [],
'public': True,
'condition': 'my-condition',
'placeholder': 'content',
'template_name': None,
'extra_css_class': '',
'last_update_timestamp': '2022-08-11T13:57:43.362Z',
'restricted_to_unlogged': False,
},
},
{
'model': 'wcs.wcscardscell',
'fields': {
'custom_title': 'my-other-title',
'without_user': False,
'only_for_user': False,
'carddef_reference': 'default:card_model_1',
'limit': 35,
'slug': 'my-other-card',
'order': 2,
'groups': [],
'public': True,
'condition': '',
'placeholder': 'content',
'template_name': None,
'extra_css_class': '',
'last_update_timestamp': '2022-08-12T07:19:18.541Z',
'restricted_to_unlogged': False,
},
},
],
}
)
executor = MigrationExecutor(connection)
executor.migrate(migrate_to)
executor.loader.build_graph()
apps = executor.loader.project_state(migrate_to).apps
pagesnapshot_class = apps.get_model('data', 'PageSnapshot')
snapshot = pagesnapshot_class.objects.get()
assert snapshot.serialization['cells'][0] == {
'model': 'wcs.wcscardcell',
'fields': {
'card_ids': '42,35',
'title_type': 'manual',
'custom_title': 'my-title',
'display_mode': 'card',
'without_user': True,
'custom_schema': {},
'only_for_user': True,
'carddef_reference': 'default:card_model_1',
'related_card_path': '',
'limit': 42,
'slug': 'my-card',
'order': 1,
'groups': [],
'public': True,
'condition': 'my-condition',
'placeholder': 'content',
'template_name': None,
'extra_css_class': '',
'last_update_timestamp': '2022-08-11T13:57:43.362Z',
'restricted_to_unlogged': False,
},
}
assert snapshot.serialization['cells'][1] == {
'model': 'wcs.wcscardcell',
'fields': {
'card_ids': '',
'title_type': 'manual',
'custom_title': 'my-other-title',
'display_mode': 'table',
'without_user': False,
'custom_schema': {},
'only_for_user': False,
'carddef_reference': 'default:card_model_1',
'related_card_path': '__all__',
'limit': 35,
'slug': 'my-other-card',
'order': 2,
'groups': [],
'public': True,
'condition': '',
'placeholder': 'content',
'template_name': None,
'extra_css_class': '',
'last_update_timestamp': '2022-08-12T07:19:18.541Z',
'restricted_to_unlogged': False,
},
}