atal_rest: accept string and float for geoloc (#87484)
gitea/passerelle/pipeline/head This commit looks good Details

This commit is contained in:
Emmanuel Cazenave 2024-02-26 17:44:54 +01:00
parent 96f992e11d
commit ea1a5a87d6
2 changed files with 38 additions and 6 deletions

View File

@ -112,9 +112,19 @@ WORKSREQUESTS_SCHEMA = {
'description': {'type': 'string'},
'desired_date': {'type': 'string', 'description': 'format YYYY-MM-DD'},
'keywords': {'type': 'string'},
'latitude': {'type': 'string'},
'latitude': {
'oneOf': [
{'type': 'number'},
{'type': 'string'},
]
},
'localisation': {'type': 'string'},
'longitude': {'type': 'string'},
'longitude': {
'oneOf': [
{'type': 'number'},
{'type': 'string'},
]
},
'object': {'type': 'string'},
'operator': {'type': 'string'},
'patrimony_id': {'type': 'string'},
@ -288,8 +298,6 @@ class AtalREST(BaseResource, HTTPResource):
data = {}
int_params = {
'activity_nature_id': 'ActivityNatureId',
'latitude': 'Latitude',
'longitude': 'Longitude',
'patrimony_id': 'PatrimonyId',
'priority_id': 'PriorityId',
'recipient_id': 'RecipientId',
@ -305,6 +313,20 @@ class AtalREST(BaseResource, HTTPResource):
except ValueError:
raise APIError('%s must be an integer' % param)
float_params = {
'latitude': 'Latitude',
'longitude': 'Longitude',
}
for param, atal_param in float_params.items():
param_value = post_data.get(param, '')
if param_value:
if isinstance(param_value, str):
param_value = param_value.replace(',', '.')
try:
data[atal_param] = float(param_value)
except ValueError:
raise APIError('%s must be a float' % param)
if 'thematic_ids' in post_data:
data['ThematicIds'] = []
for thematic_id in post_data['thematic_ids']:

View File

@ -32,7 +32,15 @@ def test_check_status(connector):
assert rsps.calls[0].request.headers['X-API-Key'] == 'secret'
def test_worksrequest(app, connector):
@pytest.mark.parametrize(
'geoloc',
[
{'latitude': '47.257117', 'longitude': '-0.07624'},
{'latitude': '47,257117', 'longitude': '-0,07624'},
{'latitude': 47.257117, 'longitude': -0.07624},
],
)
def test_worksrequest(app, connector, geoloc):
with responses.RequestsMock() as rsps:
rsps.post(
'https://atal.invalid/api/WorksRequests',
@ -46,6 +54,7 @@ def test_worksrequest(app, connector):
'requester_id': '12',
'requesting_department_id': '17',
}
params.update(geoloc)
resp = app.post_json('/atal-rest/test/worksrequests', params=params)
json_resp = resp.json
assert json_resp['err'] == 0
@ -53,7 +62,8 @@ def test_worksrequest(app, connector):
assert json_resp['data']['RequestState'] == 0
assert json_resp['data']['RequestStateLabel'] == 'En attente'
request_data = json.loads(rsps.calls[0].request.body)
assert request_data['DesiredDate'] == '2023-06-28'
assert request_data['Latitude'] == 47.257117
assert request_data['Longitude'] == -0.07624
def test_worksrequest_status(app, connector):