From 982e35a0e7319728c7556adb58bf2993e0db8a03 Mon Sep 17 00:00:00 2001 From: Serghei Mihai Date: Wed, 28 Sep 2022 12:05:07 +0200 Subject: [PATCH] astech: forward natifs parameters on demand creation (#69665) --- passerelle/apps/astech/models.py | 6 ++++++ tests/test_astech.py | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/passerelle/apps/astech/models.py b/passerelle/apps/astech/models.py index 61949464..f2ff939c 100644 --- a/passerelle/apps/astech/models.py +++ b/passerelle/apps/astech/models.py @@ -377,6 +377,12 @@ class ASTech(BaseResource, HTTPResource): 'sgesdemCpladr3': post_data.get('address3') or '', } } + + # forward payload parameters matching APIs params name pattern + for key, value in post_data.items(): + if key.startswith('sgesdem'): + payload['interface_citoyenne_demande'][key] = value + create = self.call('apicli/interface-citoyenne/demande-intervention', json=payload) if not isinstance(create, dict) or not create.get('sgesdemNum'): raise APIError('no sgesdemNum in response: %s' % create) diff --git a/tests/test_astech.py b/tests/test_astech.py index 1d52b1d0..df4669d6 100644 --- a/tests/test_astech.py +++ b/tests/test_astech.py @@ -332,6 +332,13 @@ def test_create_demand(mocked_auth, mocked_request, app, setup): assert response.json['err'] == 1 assert response.json['err_desc'].startswith('no sgesdemNum in response: ') + # send AsTech named params + demand['sgesdemArbo'] = 1 + demand['sgesdemAff'] = 'E' + response = app.post_json(endpoint, params=demand, status=200) + assert mocked_request.call_args[1]['json']['interface_citoyenne_demande']['sgesdemArbo'] == 1 + assert mocked_request.call_args[1]['json']['interface_citoyenne_demande']['sgesdemAff'] == 'E' + # test invalid requests response = app.get(endpoint, status=405) response = app.post_json(endpoint, status=400)