planitec: add getplace endpoint (#32800)

This commit is contained in:
Emmanuel Cazenave 2019-05-06 12:12:15 +02:00
parent e1f8bf238c
commit f1d45d0d0e
2 changed files with 61 additions and 0 deletions

View File

@ -667,6 +667,19 @@ class PlanitechConnector(BaseResource):
def getactivitytypes(self, request):
return {'data': self.generic_call('getActivityTypes', 'types')}
@endpoint(description_get=_('Get place'), methods=['get'], perm='can_access')
def getplace(self, request, id):
try:
id_ = int(id)
except ValueError:
raise APIError('ID must be an integer')
ref = self._get_places_referential()
if id_ not in ref:
raise APIError('No place with ID %s' % id_)
return {
'data': self._get_places_referential()[int(id_)]
}
@endpoint(description_get=_('Get places referential'), methods=['get'], perm='can_access')
def getplacesreferential(self, request, **kwargs):
return {

View File

@ -374,6 +374,54 @@ def test_getplaces_referential(app, connector, monkeypatch):
}
def test_getplace(app, connector, monkeypatch):
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'
}
]
}
]
# filter by identifier
mock_planitech(monkeypatch, side_effect=side_effect)
response = app.get(
'/planitech/slug-planitech/getplace?id=2')
assert response.json['data'] == {
u'capacity': 20, u'label': u'salle 2', u'identifier': 2,
'street_number': None, 'address': None,
'city': None, 'zipcode': None, 'some_custom_field': 'Yes'
}
# bad value
mock_planitech(monkeypatch, side_effect=side_effect)
response = app.get(
'/planitech/slug-planitech/getplace?id=toto')
assert response.json['err'] == 1
assert response.json['err_desc'] == 'ID must be an integer'
# missing place
mock_planitech(monkeypatch, side_effect=side_effect)
response = app.get(
'/planitech/slug-planitech/getplace?id=12')
assert response.json['err'] == 1
assert response.json['err_desc'] == 'No place with ID 12'
def test_getplaces_referential_use_cache(app, connector):
cache_key = 'planitech-%s-places' % connector.id
cache.set(cache_key, {'some': 'data'})