Projet

Général

Profil

0003-toulouse-maelis-sort-referential-values-70982.patch

Nicolas Roche, 04 novembre 2022 18:16

Télécharger (3,81 ko)

Voir les différences:

Subject: [PATCH 3/5] toulouse-maelis: sort referential values (#70982)

 passerelle/contrib/toulouse_maelis/models.py |  1 +
 tests/test_toulouse_maelis.py                | 18 +++++++++---------
 2 files changed, 10 insertions(+), 9 deletions(-)
passerelle/contrib/toulouse_maelis/models.py
99 99
                    'dict': {x.id: x.code for x in response},
100 100
                }
101 101
            else:
102 102
                data = {
103 103
                    'list': [{'id': x.code, 'text': x.libelle} for x in response],
104 104
                    'dict': {x.code: x.libelle for x in response},
105 105
                }
106 106
            data['search'] = {to_ascii(x['text']).lower(): x for x in data['list']}
107
            data['list'].sort(key=lambda c: c['text'])
107 108

  
108 109
            # put in cache for two hours
109 110
            cache.set(cache_key, data, 3600 * 2)
110 111
        return data
111 112

  
112 113
    def get_referential_value(self, referential_name, key, log_warning=False):
113 114
        try:
114 115
            return self.get_referential(referential_name)['dict'][key]
tests/test_toulouse_maelis.py
390 390
def test_read_dietcode_list(mocked_post, mocked_get, con, app):
391 391
    mocked_get.return_value = FAMILY_SERVICE_WSDL
392 392
    mocked_post.return_value = READ_DIETCODE
393 393
    url = get_endpoint('read-dietcode-list')
394 394

  
395 395
    resp = app.get(url)
396 396
    assert resp.json['err'] == 0
397 397
    assert resp.json['data'] == [
398
        {'id': 'BB', 'text': 'REPAS BEBE'},
399
        {'id': 'MSP', 'text': 'REPAS MOYEN SANS PORC'},
400
        {'id': 'MSV', 'text': 'REPAS MOYEN SANS VIANDE'},
401
        {'id': 'MST', 'text': 'REPAS MOYEN STANDARD'},
402 398
        {'id': 'STD', 'text': '1- REPAS STANDARD'},
403 399
        {'id': 'RSP', 'text': '2- RÉGIME SANS PORC'},
404 400
        {'id': 'RSV', 'text': '3- RÉGIME SANS VIANDE'},
405 401
        {'id': 'PAI', 'text': "4- PROTOCOLE D'ACCUEIL INDIVIDUALISÉ"},
402
        {'id': 'BB', 'text': 'REPAS BEBE'},
403
        {'id': 'MSP', 'text': 'REPAS MOYEN SANS PORC'},
404
        {'id': 'MSV', 'text': 'REPAS MOYEN SANS VIANDE'},
405
        {'id': 'MST', 'text': 'REPAS MOYEN STANDARD'},
406 406
    ]
407 407

  
408 408

  
409 409
@mock.patch('passerelle.utils.Request.get')
410 410
@mock.patch('passerelle.utils.Request.post')
411 411
def test_read_organ_list(mocked_post, mocked_get, con, app):
412 412
    mocked_get.return_value = FAMILY_SERVICE_WSDL
413 413
    mocked_post.return_value = READ_ORGAN
414 414
    url = get_endpoint('read-organ-list')
415 415

  
416 416
    resp = app.get(url)
417 417
    assert resp.json['err'] == 0
418 418
    assert len(resp.json['data']) == 92
419 419
    assert resp.json['data'][:5] == [
420
        {'id': 'A10004460232', 'text': 'LEVENS'},
421
        {'id': 'A10007752822', 'text': 'LA COLLE SUR LOUP'},
422
        {'id': 'A10001133770', 'text': 'ASSIM'},
423
        {'id': 'A10007751483', 'text': 'EZE'},
424
        {'id': 'A10008152785', 'text': 'LUCERAM'},
420
        {'id': 'A10000979374', 'text': 'ALC L OLIVIER'},
421
        {'id': 'A10000979372', 'text': 'ALVA 06'},
422
        {'id': 'A10000980566', 'text': 'ANTIBES'},
423
        {'id': 'A10000980388', 'text': 'APAJH'},
424
        {'id': 'A10016401771', 'text': 'ASCROS'},
425 425
    ]
426 426

  
427 427

  
428 428
@mock.patch('passerelle.utils.Request.get')
429 429
@mock.patch('passerelle.utils.Request.post')
430 430
def test_read_pai_list(mocked_post, mocked_get, con, app):
431 431
    mocked_get.return_value = FAMILY_SERVICE_WSDL
432 432
    mocked_post.return_value = READ_PAI
433
-