greco: add support for passing application id to create endpoint (#51842)

This commit is contained in:
Nicolas Roche 2021-03-09 17:55:59 +01:00 committed by Frédéric Péters
parent 97a18c3018
commit 76946f7cb1
2 changed files with 28 additions and 0 deletions

View File

@ -43,6 +43,7 @@ CREATION_SCHEMA = (
('danger', bool),
'mediareponse',
'priorite',
'application',
'beneficiaire_civilite',
'beneficiaire_nom',
'beneficiaire_prenom',

View File

@ -14,6 +14,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from base64 import b64encode
import copy
import os
import pytest
import mock
@ -78,6 +79,7 @@ CREATE_PAYLOAD = {
'iddemande': 'MDFGDZRF',
'mediareponse': 'Mail',
'priorite': 'Normal',
'application': '69999',
'description': 'Nom de lusager\xa0:\n admin admin\n '
+ 'Carte\xa0:\n 45.75399700317313;4.846451997582336\nNuméro\xa0:\n '
+ '48\n Nom de la voie\xa0:\n Cours Gambetta\n Code postal\xa0:\n '
@ -174,6 +176,7 @@ def test_greco_create_ok(mocked_post, app, conn):
call_args = to_json(ET.fromstring(mocked_post.call_args[1]['data']))
demande_creation = call_args['Envelope']['Body']['creer']['demandeCreation']
assert demande_creation['application'] == '69999'
assert demande_creation['localisation']['xgeoloc'] == '50.89491'
assert demande_creation['localisation']['ygeoloc'] == '4.34151'
assert demande_creation['transmetteur']['nom'] == 'Vertommen'
@ -189,6 +192,30 @@ def test_greco_create_ok(mocked_post, app, conn):
}
@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})
url += '?apikey=grecokey'
payload = copy.copy(CREATE_PAYLOAD)
del payload['application']
resp = app.post_json(url, params=payload)
assert mocked_post.call_count == 2
def to_json(root):
tag = root.tag[root.tag.find('}') + 1 :]
if len(root) == 0: # text node
return {tag: root.text or None}
childs = {}
for child in root:
childs.update(to_json(child))
return {tag: childs or None}
call_args = to_json(ET.fromstring(mocked_post.call_args[1]['data']))
demande_creation = call_args['Envelope']['Body']['creer']['demandeCreation']
assert demande_creation['application'] == 'appid'
@mock.patch('passerelle.utils.Request.post', side_effect=(TOKEN, CREATE_KO))
def test_greco_create_ko(mocked_post, app, conn):
url = reverse('generic-endpoint', kwargs={'connector': 'greco', 'endpoint': 'create', 'slug': conn.slug})