planitec: make custom fields optionnals (#32188)
This commit is contained in:
parent
9396e907da
commit
d7abdba261
|
@ -302,7 +302,7 @@ class PlanitechConnector(BaseResource):
|
|||
}
|
||||
}
|
||||
|
||||
for custom_field in self.custom_fields:
|
||||
for custom_field in self.custom_fields or []:
|
||||
field_name = custom_field['name']
|
||||
extensionAttributes[field_name] = {
|
||||
'name': field_name,
|
||||
|
@ -353,7 +353,7 @@ class PlanitechConnector(BaseResource):
|
|||
# Filter on custom fields
|
||||
skip = False
|
||||
for filter_name, filter_value in kwargs.items():
|
||||
for field in self.custom_fields:
|
||||
for field in self.custom_fields or []:
|
||||
if filter_name == field['name']:
|
||||
if field['type'] == 'int':
|
||||
filter_value = int(filter_value)
|
||||
|
|
|
@ -472,6 +472,51 @@ def test_getplace(app, connector, monkeypatch):
|
|||
assert response.json['err_desc'] == 'No place with ID 12'
|
||||
|
||||
|
||||
def test_getplaces_referential_no_configuration(app, connector, monkeypatch):
|
||||
# Custom fields not returned if no configuration
|
||||
connector.custom_fields = None
|
||||
connector.save()
|
||||
side_effect = [
|
||||
{
|
||||
'placesList': [
|
||||
{'identifier': 1.0, 'label': 'salle 1'},
|
||||
{'identifier': 2.0, 'label': 'salle 2'}
|
||||
]
|
||||
},
|
||||
{
|
||||
'requestedPlaces': [
|
||||
{
|
||||
'identifier': 1.0, 'capacity': 10.0,
|
||||
'streetNumber': 1, 'address1': 'rue planitech',
|
||||
'city': 'thecity', 'zipCode': '00000'
|
||||
},
|
||||
{
|
||||
'identifier': 2.0, 'capacity': 20.0,
|
||||
'some_custom_field': 'Yes'
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
||||
mock_planitech(monkeypatch, side_effect=side_effect)
|
||||
response = app.get('/planitech/slug-planitech/getplacesreferential')
|
||||
mock_planitech(monkeypatch, side_effect=side_effect)
|
||||
response = app.get('/planitech/slug-planitech/getplacesreferential')
|
||||
expected_res = {
|
||||
'2': {
|
||||
u'capacity': 20, u'label': u'salle 2', u'identifier': 2,
|
||||
'street_number': None, 'address': None,
|
||||
'city': None, 'zipcode': None,
|
||||
},
|
||||
'1': {
|
||||
u'capacity': 10, u'label': u'salle 1', u'identifier': 1,
|
||||
'street_number': 1, 'address': 'rue planitech',
|
||||
'city': 'thecity', 'zipcode': '00000',
|
||||
}
|
||||
}
|
||||
assert response.json['data'] == expected_res
|
||||
|
||||
|
||||
def test_getplaces_referential_use_cache(app, connector):
|
||||
cache_key = 'planitech-%s-places' % connector.id
|
||||
cache.set(cache_key, {'some': 'data'})
|
||||
|
|
Loading…
Reference in New Issue