Projet

Général

Profil

0001-planitec-make-custom-fields-not-mandatory-32188.patch

Emmanuel Cazenave, 25 avril 2019 11:37

Télécharger (2,95 ko)

Voir les différences:

Subject: [PATCH] planitec: make custom fields not mandatory (#32188)

 passerelle/contrib/planitech/models.py |  3 +-
 tests/test_planitech.py                | 46 ++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 2 deletions(-)
passerelle/contrib/planitech/models.py
309 309
                    'type': 'int'
310 310
                }
311 311
            }
312

  
313
            for custom_field in self.custom_fields:
312
            for custom_field in self.custom_fields or []:
314 313
                field_name = custom_field['name']
315 314
                extensionAttributes[field_name] = {
316 315
                    'name': field_name,
tests/test_planitech.py
374 374
    }
375 375

  
376 376

  
377
def test_getplaces_referential_no_configuration(app, connector, monkeypatch):
378
    # Custom fields not returned if no configuration
379
    connector.custom_fields = None
380
    connector.save()
381

  
382
    side_effect = [
383
        {
384
            'placesList': [
385
                {'identifier': 1.0, 'label': 'salle 1'},
386
                {'identifier': 2.0, 'label': 'salle 2'}
387
            ]
388
        },
389
        {
390
            'requestedPlaces': [
391
                {
392
                    'identifier': 1.0, 'capacity': 10.0,
393
                    'streetNumber': 1, 'address1': 'rue planitech',
394
                    'city': 'thecity', 'zipCode': '00000'
395
                },
396
                {
397
                    'identifier': 2.0, 'capacity': 20.0,
398
                    'some_custom_field': 'Yes'
399
                }
400
            ]
401
        }
402
    ]
403
    mock_planitech(monkeypatch, side_effect=side_effect)
404
    response = app.get('/planitech/slug-planitech/getplacesreferential')
405

  
406
    mock_planitech(monkeypatch, side_effect=side_effect)
407
    response = app.get('/planitech/slug-planitech/getplacesreferential')
408
    expected_res = {
409
        '2': {
410
            u'capacity': 20, u'label': u'salle 2', u'identifier': 2,
411
            'street_number': None, 'address': None,
412
            'city': None, 'zipcode': None,
413
        },
414
        '1': {
415
            u'capacity': 10, u'label': u'salle 1', u'identifier': 1,
416
            'street_number': 1, 'address': 'rue planitech',
417
            'city': 'thecity', 'zipcode': '00000',
418
        }
419
    }
420
    assert response.json['data'] == expected_res
421

  
422

  
377 423
def test_getplaces_referential_use_cache(app, connector):
378 424
    cache_key = 'planitech-%s-places' % connector.id
379 425
    cache.set(cache_key, {'some': 'data'})
380
-