sigerly: allow for new nom_rue parameter (and elements as not required) (#70409)

This commit is contained in:
Frédéric Péters 2022-10-18 11:33:26 +02:00
parent 6ba26ee12a
commit 193217b495
2 changed files with 32 additions and 2 deletions

View File

@ -26,7 +26,7 @@ from passerelle.utils.jsonresponse import APIError
CREATE_SCHEMA = {
'$schema': 'http://json-schema.org/draft-04/schema#',
"type": "object",
'required': ['demandeur', 'id_typeinterv', 'id_urgence', 'elements'],
'required': ['demandeur', 'id_typeinterv', 'id_urgence'],
'properties': {
'demandeur': {
'description': "Nom du demandeur",
@ -53,6 +53,10 @@ CREATE_SCHEMA = {
'type': 'string',
'pattern': r'^[0-9A-Z :]+$',
},
'nom_rue': {
'description': 'Adresse',
'type': 'string',
},
},
}
@ -120,7 +124,8 @@ class Sigerly(BaseResource, HTTPResource):
post_data['id_typeinterv'] = int(post_data['id_typeinterv'])
post_data['id_urgence'] = int(post_data['id_urgence'])
post_data['id_qualification'] = int(post_data['id_qualification'])
post_data['elements'] = [x.strip() for x in post_data['elements'].split(':') if x.strip()]
if 'elements' in post_data:
post_data['elements'] = [x.strip() for x in post_data['elements'].split(':') if x.strip()]
response = self.request('createIntervention.php', json=post_data)
if not response.get('success', None):

View File

@ -79,6 +79,31 @@ def test_create(app, connector):
def sigerly_mock(url, request):
assert request.headers['Accept'] == 'application/json'
assert json.loads(request.body)['elements'] == ['LIMW003D', 'LIMWW003C']
assert 'nom_rue' not in json.loads(request.body)
return httmock.response(200, json.dumps({'success': True, 'message': '7830'}))
with httmock.HTTMock(sigerly_mock):
resp = app.post_json(endpoint, params=payload)
assert not resp.json['err']
assert resp.json['data']['message'] == '7830' # id unusable within query endpoint
def test_create_nom_rue(app, connector):
endpoint = get_endpoint('create')
payload = {
'demandeur': 'Test webservice',
'id_typeinterv': '5',
'id_urgence': '1',
'id_qualification': '8',
'observations': 'Test webservice',
'nom_rue': 'some place',
}
@httmock.urlmatch(netloc='sigerly.example.net', path='/createIntervention.php', method='POST')
def sigerly_mock(url, request):
assert request.headers['Accept'] == 'application/json'
assert json.loads(request.body)['nom_rue'] == 'some place'
assert 'elements' not in json.loads(request.body)
return httmock.response(200, json.dumps({'success': True, 'message': '7830'}))
with httmock.HTTMock(sigerly_mock):