Projet

Général

Profil

0001-wcs-fix-card-cell-reverse-relations-60891.patch

Lauréline Guérin, 21 janvier 2022 09:37

Télécharger (4,57 ko)

Voir les différences:

Subject: [PATCH] wcs: fix card cell reverse relations (#60891)

 combo/apps/wcs/models.py |  3 ++
 tests/test_wcs.py        | 79 +++++++++++++++++++++++++++++++++++++++-
 2 files changed, 81 insertions(+), 1 deletion(-)
combo/apps/wcs/models.py
1081 1081
        def get_relation(relations, varname, reverse):
1082 1082
            for relation in relations:
1083 1083
                if relation['reverse'] == reverse and relation['varname'] == varname:
1084
                    if reverse and relation['obj'][8:] != self.card_slug:
1085
                        # if reverse, it's the last part; check it's the correct card model
1086
                        continue
1084 1087
                    return relation
1085 1088

  
1086 1089
        def follow_data(card_data, relations, varname, parts):
tests/test_wcs.py
218 218
            'fields': {},
219 219
        },
220 220
    ],
221
    'card_f': [
222
        {'id': 41, 'fields': {'cardh_raw': 42}},
223
    ],
224
    'card_g': [
225
        {'id': 43, 'fields': {'cardh_raw': 44}},
226
    ],
227
    'card_h': [
228
        {'id': 42, 'fields': {}},
229
        {'id': 44, 'fields': {}},
230
    ],
221 231
}
222 232

  
223 233
WCS_CARDS_CUSTOM_VIEW_DATA = [
......
329 339
            {'obj': 'carddef:card_d', 'varname': 'carde-foo', 'type': 'item', 'reverse': True},
330 340
        ],
331 341
    },
342
    'card_f': {
343
        'name': 'Card F',
344
        'fields': [
345
            {'label': 'Card H', 'varname': 'cardh', 'type': 'item'},
346
        ],
347
        'relations': [
348
            {'obj': 'carddef:card_h', 'varname': 'cardh', 'type': 'item', 'reverse': False},
349
        ],
350
    },
351
    'card_g': {
352
        'name': 'Card G',
353
        'fields': [
354
            {'label': 'Card H', 'varname': 'cardh', 'type': 'item'},
355
        ],
356
        'relations': [
357
            {'obj': 'carddef:card_h', 'varname': 'cardh', 'type': 'item', 'reverse': False},
358
        ],
359
    },
360
    'card_h': {
361
        'name': 'Card H',
362
        'fields': [],
363
        'relations': [
364
            {'obj': 'carddef:card_f', 'varname': 'cardh', 'type': 'item', 'reverse': True},
365
            {'obj': 'carddef:card_g', 'varname': 'cardh', 'type': 'item', 'reverse': True},
366
        ],
367
    },
332 368
}
333 369

  
334 370

  
......
3018 3054

  
3019 3055
    def multiple(urls):
3020 3056
        resp = app.get(page.get_online_url())
3021
        assert len(resp.context['cells']) >= 3
3057
        assert len(resp.context['cells']) >= 2
3022 3058
        assert resp.context['cells'][0].pk == cell.pk
3023 3059
        extra_ctx = re.findall(r'data-extra-context="(.*)"', resp.text)
3024 3060
        for i in range(0, len(resp.context['cells']) - 1):
......
3366 3402
        ]
3367 3403
    )
3368 3404

  
3405
    # reverse relation with many models using the same varname
3406
    cell.carddef_reference = 'default:card_h'
3407
    cell.slug = 'slugh'
3408
    cell.card_ids = '42'
3409
    cell.related_card_path = ''
3410
    cell.save()
3411
    cell2.carddef_reference = 'default:card_f'
3412
    cell2.slug = 'slugf'
3413
    cell2.card_ids = ''
3414
    cell2.related_card_path = 'slugh/reverse:cardh'
3415
    cell2.save()
3416
    multiple(
3417
        urls=[
3418
            # get first cell data
3419
            '/api/cards/card_h/42/',
3420
            # get list of card_f with cardf=42
3421
            '/api/cards/card_f/list?orig=combo&filter-cardh=42',
3422
            # and follow cardf reverse relation
3423
            ['/api/cards/card_f/41/'],
3424
        ]
3425
    )
3426

  
3427
    cell.card_ids = '44'
3428
    cell.related_card_path = ''
3429
    cell.save()
3430
    cell2.carddef_reference = 'default:card_g'
3431
    cell2.slug = 'slugg'
3432
    cell2.card_ids = ''
3433
    cell2.related_card_path = 'slugh/reverse:cardh'
3434
    cell2.save()
3435
    multiple(
3436
        urls=[
3437
            # get first cell data
3438
            '/api/cards/card_h/44/',
3439
            # get list of card_g with cardf=44
3440
            '/api/cards/card_g/list?orig=combo&filter-cardh=44',
3441
            # and follow cardf reverse relation
3442
            ['/api/cards/card_g/43/'],
3443
        ]
3444
    )
3445

  
3369 3446

  
3370 3447
@mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send)
3371 3448
def test_card_cell_render_user(mock_send, context, nocache):
3372
-