Projet

Général

Profil

0005-wcs-snapshot-loading-with-old-card-cells-68140.patch

Lauréline Guérin, 12 août 2022 15:37

Télécharger (9,66 ko)

Voir les différences:

Subject: [PATCH 5/5] wcs: snapshot loading with old card cells (#68140)

 combo/data/models.py   |  10 ++
 tests/wcs/test_card.py | 204 ++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 213 insertions(+), 1 deletion(-)
combo/data/models.py
605 605
    def load_serialized_cells(cls, cells):
606 606
        # load new cells
607 607
        for cell_data in cells:
608
            # legacy card cells, for snapshots
609
            if cell_data['model'] == 'wcs.wcscardinfoscell':
610
                cell_data['model'] = 'wcs.wcscardcell'
611
            elif cell_data['model'] == 'wcs.wcscardscell':
612
                cell_data['model'] = 'wcs.wcscardcell'
613
                cell_data['fields']['related_card_path'] = '__all__'
614
                cell_data['fields']['display_mode'] = 'table'
615
                cell_data['fields']['title_type'] = 'auto'
616
                if cell_data['fields'].get('custom_title'):
617
                    cell_data['fields']['title_type'] = 'manual'
608 618
            model = apps.get_model(cell_data['model'])
609 619
            cell_data = model.prepare_serialized_data(cell_data)
610 620
            cell = list(serializers.deserialize('json', json.dumps([cell_data]), ignorenonexistent=True))[0]
tests/wcs/test_card.py
14 14

  
15 15
from combo.apps.wcs.forms import WcsCardCellDisplayForm
16 16
from combo.apps.wcs.models import WcsCardCell
17
from combo.data.models import Page, TextCell, ValidityInfo
17
from combo.data.models import Page, PageSnapshot, TextCell, ValidityInfo
18 18
from tests.test_manager import login
19 19
from tests.utils import manager_submit_cell
20 20

  
......
2511 2511
    resp = app.get('/manage/assets/')
2512 2512
    assert 'Picture — %s' % cell1.get_label_for_asset() in resp.text
2513 2513
    assert 'Logo — %s' % cell2.get_label_for_asset() in resp.text
2514

  
2515

  
2516
def test_page_snapshot_with_old_card_cells():
2517
    """
2518
    page_serialization = {
2519
        'cells': [{
2520
            'model': 'data.parentcontentcell',
2521
            'fields': {
2522
                'slug': '',
2523
                'order': 0,
2524
                'groups': [],
2525
                'public': True,
2526
                'condition': None,
2527
                'placeholder': 'footer',
2528
                'template_name': None,
2529
                'extra_css_class': '',
2530
                'last_update_timestamp': '2022-08-08T13:55:29.599Z',
2531
                'restricted_to_unlogged': False,
2532
                'page': 14
2533
            }
2534
        }, {
2535
            'model': 'wcs.wcscardinfoscell',
2536
            'fields': {
2537
                'slug': 'enfant',
2538
                'limit': None,
2539
                'order': 1,
2540
                'groups': [],
2541
                'public': True,
2542
                'card_ids': '',
2543
                'condition': '',
2544
                'title_type': 'auto',
2545
                'placeholder': 'content',
2546
                'custom_title': '',
2547
                'display_mode': 'card',
2548
                'without_user': False,
2549
                'custom_schema': {},
2550
                'only_for_user': False,
2551
                'template_name': None,
2552
                'extra_css_class': '',
2553
                'carddef_reference': 'eservices:test-related-enfant',
2554
                'related_card_path': '',
2555
                'last_update_timestamp': '2022-08-11T13:57:43.362Z',
2556
                'restricted_to_unlogged': False,
2557
                'page': 14
2558
            }
2559
        }, {
2560
            'model': 'wcs.wcscardinfoscell',
2561
            'fields': {
2562
                'slug': '',
2563
                'limit': None,
2564
                'order': 2,
2565
                'groups': [],
2566
                'public': True,
2567
                'card_ids': '',
2568
                'condition': '',
2569
                'title_type': 'auto',
2570
                'placeholder': 'content',
2571
                'custom_title': '',
2572
                'display_mode': 'card',
2573
                'without_user': False,
2574
                'custom_schema': {},
2575
                'only_for_user': False,
2576
                'template_name': None,
2577
                'extra_css_class': '',
2578
                'carddef_reference': 'eservices:test-related-adulte:par-defaut',
2579
                'related_card_path': 'enfant/block_parents_parent',
2580
                'last_update_timestamp': '2022-08-08T19:53:02.097Z',
2581
                'restricted_to_unlogged': False,
2582
                'page': 14
2583
            }
2584
        }, {
2585
            'model': 'wcs.wcscardinfoscell',
2586
            'fields': {
2587
                'slug': '',
2588
                'limit': None,
2589
                'order': 3,
2590
                'groups': [],
2591
                'public': True,
2592
                'card_ids': '',
2593
                'condition': '',
2594
                'title_type': 'empty',
2595
                'placeholder': 'content',
2596
                'custom_title': 'Les parents !',
2597
                'display_mode': 'table',
2598
                'without_user': False,
2599
                'custom_schema': {},
2600
                'only_for_user': False,
2601
                'template_name': None,
2602
                'extra_css_class': '',
2603
                'carddef_reference': 'eservices:test-related-adulte:par-defaut',
2604
                'related_card_path': 'enfant/block_parents_parent',
2605
                'last_update_timestamp': '2022-08-11T13:07:35.757Z',
2606
                'restricted_to_unlogged': False,
2607
                'page': 14
2608
            }
2609
        }],
2610
        'fields': {
2611
            'slug': 'related-enfant',
2612
            'order': 6,
2613
            'title': 'Related enfant',
2614
            'groups': [],
2615
            'parent': ['search-related'],
2616
            'public': True,
2617
            'picture': '',
2618
            'snapshot': None,
2619
            'sub_slug': 'test-related-enfant_id',
2620
            'edit_role': None,
2621
            'description': '',
2622
            'redirect_url': '',
2623
            'template_name': 'standard',
2624
            'extra_variables': {},
2625
            'creation_timestamp': '2022-08-08T13:55:29.502Z',
2626
            'subpages_edit_role': None,
2627
            'placeholder_options': {},
2628
            'last_update_timestamp': '2022-08-11T13:57:43.369Z',
2629
            'exclude_from_navigation': True
2630
        },
2631
        'model': 'data.page',
2632
        'pk': 14
2633
    }
2634
    """
2635
    page = Page.objects.create(title='xxx', slug='test_snapshots', template_name='standard')
2636
    PageSnapshot.take(page)
2637
    snapshot = page.pagesnapshot_set.first()
2638
    snapshot.serialization['cells'].append(
2639
        {
2640
            'model': 'wcs.wcscardinfoscell',
2641
            'fields': {
2642
                'slug': 'my-card',
2643
                'limit': 42,
2644
                'order': 1,
2645
                'groups': [],
2646
                'public': True,
2647
                'card_ids': '42,35',
2648
                'condition': 'my-condition',
2649
                'title_type': 'manual',
2650
                'placeholder': 'content',
2651
                'custom_title': 'my-title',
2652
                'display_mode': 'card',
2653
                'without_user': True,
2654
                'custom_schema': {},
2655
                'only_for_user': True,
2656
                'template_name': None,
2657
                'extra_css_class': '',
2658
                'carddef_reference': 'default:card_model_1',
2659
                'related_card_path': '',
2660
                'last_update_timestamp': '2022-08-11T13:57:43.362Z',
2661
                'restricted_to_unlogged': False,
2662
                'page': page.pk,
2663
            },
2664
        }
2665
    )
2666
    snapshot.serialization['cells'].append(
2667
        {
2668
            'model': 'wcs.wcscardscell',
2669
            'fields': {
2670
                'slug': 'my-other-card',
2671
                'limit': 35,
2672
                'order': 2,
2673
                'groups': [],
2674
                'public': True,
2675
                'condition': '',
2676
                'placeholder': 'content',
2677
                'custom_title': 'my-other-title',
2678
                'without_user': False,
2679
                'only_for_user': False,
2680
                'template_name': None,
2681
                'extra_css_class': '',
2682
                'carddef_reference': 'default:card_model_1',
2683
                'last_update_timestamp': '2022-08-12T07:19:18.541Z',
2684
                'restricted_to_unlogged': False,
2685
                'page': page.pk,
2686
            },
2687
        }
2688
    )
2689
    old_page = snapshot.get_page()
2690
    cell1 = old_page.get_cells()[0]
2691
    assert type(cell1) == WcsCardCell
2692
    assert cell1.slug == 'my-card'
2693
    assert cell1.limit == 42
2694
    assert cell1.card_ids == '42,35'
2695
    assert cell1.title_type == 'manual'
2696
    assert cell1.custom_title == 'my-title'
2697
    assert cell1.display_mode == 'card'
2698
    assert cell1.without_user is True
2699
    assert cell1.custom_schema == {}
2700
    assert cell1.only_for_user is True
2701
    assert cell1.carddef_reference == 'default:card_model_1'
2702
    assert cell1.related_card_path == ''
2703
    cell2 = old_page.get_cells()[1]
2704
    assert type(cell2) == WcsCardCell
2705
    assert cell2.slug == 'my-other-card'
2706
    assert cell2.limit == 35
2707
    assert cell2.card_ids == ''
2708
    assert cell2.title_type == 'manual'
2709
    assert cell2.custom_title == 'my-other-title'
2710
    assert cell2.display_mode == 'table'
2711
    assert cell2.without_user is False
2712
    assert cell2.custom_schema == {}
2713
    assert cell2.only_for_user is False
2714
    assert cell2.carddef_reference == 'default:card_model_1'
2715
    assert cell2.related_card_path == '__all__'
2514
-