greco: use stored application code as default (#79320)
gitea/passerelle/pipeline/head Build queued... Details

This commit is contained in:
Emmanuel Cazenave 2023-07-03 15:36:25 +02:00
parent 9386398863
commit d199eb9de7
2 changed files with 53 additions and 0 deletions

View File

@ -341,6 +341,8 @@ Response :
raise APIError('empty response from creer()')
data = sudsobject_to_dict(resp)
else:
if not formdata.json.get('application'):
formdata.json['application'] = self.application
files = []
for num, attachment in enumerate(formdata.attachments):
filename = attachment.get('filename') or 'file%s.bin' % num

View File

@ -263,6 +263,57 @@ def test_greco_rest_create_ok(app, rest_conn):
}
def test_greco_rest_create_ok_default_application_code(app, rest_conn):
rest_conn.application = '69999'
rest_conn.save()
url = reverse(
'generic-endpoint', kwargs={'connector': 'greco', 'endpoint': 'create', 'slug': rest_conn.slug}
)
url += '?apikey=grecokey'
with responses.RequestsMock() as rsps:
rsps.post(
'http://greco.example.net/token',
status=200,
body=get_json_file('token'),
)
rsps.post(
'http://greco.example.net/creer',
status=200,
json={
'iddemande': 'MDFGDZRF',
'idgreco': '538593',
'etat': '1 - Créée',
'application': '69999',
},
)
create_payload = CREATE_PAYLOAD.copy()
del create_payload['application']
resp = app.post_json(url, params=create_payload)
create_request = rsps.calls[-1].request
decoder = MultipartDecoder(create_request.body, create_request.headers['content-type'])
assert len(decoder.parts) == 1
json_part = decoder.parts[0]
assert json_part.headers[b'Content-Type'] == b'application/json'
demande_creation = json.loads(json_part.content)
assert demande_creation['application'] == '69999'
assert demande_creation['beneficiaire']['fax'] == ''
assert demande_creation['beneficiaire']['numerovoie'] == ''
assert demande_creation['localisation']['xgeoloc'] == '50.89491'
assert demande_creation['localisation']['ygeoloc'] == '4.34151'
assert demande_creation['transmetteur']['nom'] == 'Vertommen'
assert demande_creation['transmetteur']['prenom'] == 'Agent 15'
assert demande_creation['danger'] == 'false'
assert not resp.json['err']
assert resp.json['data'] == {
'iddemande': 'MDFGDZRF',
'idgreco': '538593',
'etat': '1 - Créée',
'application': '69999',
}
@mock.patch('passerelle.utils.Request.post', side_effect=(TOKEN, CREATE_OK))
def test_greco_create_ok_no_application(mocked_post, app, conn):
url = reverse('generic-endpoint', kwargs={'connector': 'greco', 'endpoint': 'create', 'slug': conn.slug})