2018-07-09 14:29:28 +02:00
|
|
|
import base64
|
2018-09-14 12:04:31 +02:00
|
|
|
import os
|
|
|
|
import xml.etree.ElementTree as ET
|
2022-03-18 09:46:37 +01:00
|
|
|
from unittest import mock
|
2018-09-14 12:04:31 +02:00
|
|
|
|
2018-06-15 15:07:44 +02:00
|
|
|
import pytest
|
2022-08-31 10:21:14 +02:00
|
|
|
from django.utils.encoding import force_str
|
2018-06-15 15:07:44 +02:00
|
|
|
from zeep.exceptions import Fault as WebFault
|
2018-07-24 15:58:08 +02:00
|
|
|
from zeep.exceptions import TransportError
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
from passerelle.contrib.dpark.models import DPark, Pairing
|
2022-12-20 12:00:57 +01:00
|
|
|
from passerelle.utils.conversion import to_pdf
|
2018-07-24 15:58:08 +02:00
|
|
|
from passerelle.utils.jsonresponse import APIError
|
2022-12-20 12:00:57 +01:00
|
|
|
from tests.utils import ResponsesSoap, make_resource
|
2018-06-15 15:07:44 +02:00
|
|
|
|
2018-09-14 12:04:31 +02:00
|
|
|
SLUG = 'test'
|
|
|
|
WSDL_URL = 'https://example.net/dpark?wsdl'
|
2022-12-20 12:00:57 +01:00
|
|
|
SERVICE_URL = 'https://example.net/dpark'
|
2018-09-14 12:04:31 +02:00
|
|
|
|
|
|
|
with open(os.path.join(os.path.dirname(__file__), 'data/dpark.awws.wsdl')) as f:
|
|
|
|
WSDL_CONTENT = f.read()
|
|
|
|
|
2020-01-15 14:30:27 +01:00
|
|
|
with open(os.path.join(os.path.dirname(__file__), 'data/small.jpg'), 'rb') as f:
|
2018-09-24 16:23:36 +02:00
|
|
|
JPEG_CONTENT = f.read()
|
|
|
|
|
2018-09-14 12:04:31 +02:00
|
|
|
|
2018-10-25 11:56:02 +02:00
|
|
|
def make_response(name, items):
|
|
|
|
base = '''<?xml version="1.0" encoding="utf-8"?>
|
2022-03-18 15:29:28 +01:00
|
|
|
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
|
|
|
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
|
2018-10-25 11:56:02 +02:00
|
|
|
<SOAP-ENV:Header/>
|
|
|
|
<SOAP-ENV:Body>
|
|
|
|
</SOAP-ENV:Body>
|
|
|
|
</SOAP-ENV:Envelope>'''
|
|
|
|
root = ET.fromstring(base)
|
|
|
|
body = root.find('{http://schemas.xmlsoap.org/soap/envelope/}Body')
|
|
|
|
response_tag_name = '{urn:Webservice_Residants}PLS_%sResponse' % name
|
|
|
|
result_tag_name = 'PLS_%sResult' % name
|
|
|
|
response = ET.SubElement(body, response_tag_name)
|
|
|
|
result = ET.SubElement(response, result_tag_name)
|
|
|
|
for key, value in items:
|
|
|
|
elt = ET.SubElement(result, key)
|
|
|
|
if value:
|
|
|
|
elt.text = value
|
|
|
|
return ET.tostring(root)
|
|
|
|
|
|
|
|
|
2018-06-15 15:07:44 +02:00
|
|
|
@pytest.fixture
|
|
|
|
def dpark(db):
|
2018-09-14 12:04:31 +02:00
|
|
|
resource = make_resource(
|
|
|
|
DPark,
|
|
|
|
**{
|
|
|
|
'slug': SLUG,
|
|
|
|
'wsdl_url': WSDL_URL,
|
2022-12-20 12:00:57 +01:00
|
|
|
'operation_url': SERVICE_URL,
|
2018-06-15 15:07:44 +02:00
|
|
|
},
|
|
|
|
)
|
2022-12-20 12:00:57 +01:00
|
|
|
return resource
|
2018-09-14 12:04:31 +02:00
|
|
|
|
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def soap_mock(dpark):
|
|
|
|
responses_soap = ResponsesSoap(WSDL_URL, WSDL_CONTENT, address=SERVICE_URL)
|
|
|
|
with responses_soap() as soap_mock:
|
|
|
|
yield soap_mock
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
|
|
|
|
class ReplyDataClass(dict):
|
|
|
|
def __init__(self, **kwargs):
|
|
|
|
self.__dict__.update(kwargs)
|
2022-03-17 15:18:48 +01:00
|
|
|
super().__init__(**kwargs)
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
|
2019-12-19 15:57:27 +01:00
|
|
|
class WebFaultHavingLatin1(WebFault):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
2022-03-18 14:24:29 +01:00
|
|
|
class MockedService:
|
2022-12-20 12:00:57 +01:00
|
|
|
def __init__(self, success=True, error_class=None, replydata=None):
|
2018-06-15 15:07:44 +02:00
|
|
|
self.success = success
|
|
|
|
self.error_class = error_class
|
|
|
|
self.replydata = replydata
|
|
|
|
|
|
|
|
def raise_error(self):
|
|
|
|
if self.error_class is WebFault:
|
|
|
|
raise self.error_class(mock.Mock(faulstring='Error %s raised' % self.error_class.__name__), None)
|
2022-03-18 15:43:23 +01:00
|
|
|
if self.error_class is TransportError:
|
2018-06-15 15:07:44 +02:00
|
|
|
raise self.error_class('connection error occured', None)
|
2022-03-18 15:43:23 +01:00
|
|
|
if self.error_class is WebFaultHavingLatin1:
|
2022-03-17 16:54:24 +01:00
|
|
|
raise WebFault(message='éêè')
|
2022-03-18 15:43:23 +01:00
|
|
|
raise Exception('random error')
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
def return_response(self, *args, **kwargs):
|
|
|
|
return ReplyDataClass(**self.replydata)
|
|
|
|
|
|
|
|
def __getattr__(self, name):
|
|
|
|
if self.error_class:
|
|
|
|
self.raise_error()
|
|
|
|
return self.return_response
|
|
|
|
|
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
@pytest.fixture
|
|
|
|
def get_service():
|
|
|
|
with mock.patch('passerelle.contrib.dpark.models.get_service') as get_service:
|
|
|
|
yield get_service
|
|
|
|
|
|
|
|
|
|
|
|
def test_call_service_error(dpark, app, get_service):
|
|
|
|
get_service.return_value = MockedService(error_class=WebFault)
|
|
|
|
resp = app.get('/dpark/test/ping/')
|
|
|
|
assert 'ServiceError: ' in resp.json['err_desc']
|
|
|
|
get_service.return_value = MockedService(error_class=TransportError)
|
|
|
|
resp = app.get('/dpark/test/ping/')
|
|
|
|
assert 'Error: connection error occured' in resp.json['err_desc']
|
|
|
|
get_service.return_value = MockedService(error_class=Exception)
|
|
|
|
resp = app.get('/dpark/test/ping/')
|
|
|
|
assert 'Error: random error' in resp.json['err_desc']
|
|
|
|
get_service.return_value = MockedService(error_class=WebFaultHavingLatin1)
|
|
|
|
resp = app.get('/dpark/test/ping/')
|
|
|
|
assert 'ServiceError: éêè' in resp.json['err_desc']
|
|
|
|
|
|
|
|
|
|
|
|
def test_ping(dpark, app, get_service):
|
|
|
|
get_service.return_value = MockedService(replydata={'Code_Retour': '01', 'Lib_Retour': 'whatever'})
|
|
|
|
resp = app.get('/dpark/test/ping/')
|
|
|
|
assert resp.json['data'] is True
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_search(dpark, app, get_service):
|
|
|
|
params = {
|
|
|
|
'lastname': 'bar',
|
|
|
|
'firstnames': 'foo',
|
|
|
|
'filenumber': '1' * 9,
|
|
|
|
'cardnumber': '3' * 9,
|
|
|
|
}
|
|
|
|
# missing lastname
|
|
|
|
app.get('/dpark/test/search/', params={'firstnames': 'toto'}, status=400)
|
|
|
|
# unknown file
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Dossier inconnu'}
|
|
|
|
)
|
|
|
|
resp = app.get('/dpark/test/search/', params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['code'] == 'unknown-file'
|
|
|
|
# invalid cardnumber
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '04', 'MessageRetour': 'Numéro de support inconnu'}
|
|
|
|
)
|
|
|
|
resp = app.get('/dpark/test/search/', params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['code'] == 'support-number-unknown'
|
|
|
|
# valid data
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '01', 'MessageRetour': 'Dossier existant'}
|
|
|
|
)
|
|
|
|
resp = app.get('/dpark/test/search/', params=params)
|
|
|
|
assert resp.json['err'] == 0
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_link(dpark, app, get_service):
|
|
|
|
params = {
|
|
|
|
'lastname': 'bar ',
|
|
|
|
'firstnames': ' foo',
|
|
|
|
'filenumber': ' ' + '1' * 9,
|
|
|
|
}
|
|
|
|
# missing nameid
|
|
|
|
app.post_json('/dpark/test/link/', params=params, status=400)
|
|
|
|
params['nameid'] = 'abcd' * 8
|
|
|
|
# unknown file
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Dossier inconnu'}
|
|
|
|
)
|
|
|
|
resp = app.post_json('/dpark/test/link/', params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['code'] == 'unknown-file'
|
|
|
|
# invalid cardnumber
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '04', 'MessageRetour': 'Numéro de support inconnu'}
|
|
|
|
)
|
|
|
|
resp = app.post_json('/dpark/test/link/', params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['code'] == 'support-number-unknown'
|
|
|
|
# valid data
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '01', 'MessageRetour': 'Dossier existant'}
|
|
|
|
)
|
|
|
|
resp = app.post_json('/dpark/test/link/', params=params)
|
|
|
|
assert resp.json['err'] == 0
|
|
|
|
assert Pairing.objects.count() == 1
|
|
|
|
pairing = Pairing.objects.get(resource=dpark)
|
|
|
|
assert pairing.nameid == 'abcd' * 8
|
|
|
|
assert pairing.filenumber == '1' * 9
|
|
|
|
assert pairing.firstnames == 'foo'
|
|
|
|
assert pairing.lastname == 'bar'
|
|
|
|
|
|
|
|
|
|
|
|
def test_unlink(dpark, app, get_service):
|
|
|
|
get_service.return_value = MockedService()
|
|
|
|
nameid = 'abcd' * 8
|
|
|
|
params = {'nameid': nameid}
|
|
|
|
# missing nameid
|
|
|
|
app.post_json('/dpark/test/unlink/', params={}, status=400)
|
|
|
|
# no pairing exists
|
|
|
|
resp = app.post_json('/dpark/test/unlink/', params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'No pairing exists'
|
|
|
|
# pairing exist
|
|
|
|
Pairing.objects.create(
|
|
|
|
resource=dpark,
|
|
|
|
nameid=nameid,
|
|
|
|
lastname='bar',
|
|
|
|
firstnames='foo',
|
|
|
|
filenumber='1' * 9,
|
|
|
|
badgenumber='2' * 9,
|
|
|
|
cardnumber='3' * 9,
|
|
|
|
)
|
|
|
|
resp = app.post_json('/dpark/test/unlink/', params=params)
|
|
|
|
assert resp.json['data'] is True
|
|
|
|
assert Pairing.objects.count() == 0
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_address_eligibility(dpark, app, soap_mock):
|
|
|
|
# first response, will be removed from responses registry after first call
|
|
|
|
soap_mock.add_soap_response(
|
|
|
|
'PLS_ELIGADR',
|
|
|
|
{
|
|
|
|
'PLS_ELIGADRResult': {
|
|
|
|
'CodeRetour': '99',
|
|
|
|
'MessageRetour': 'Erreur extension',
|
|
|
|
'Adresse_EtageEscalierAppartement': '',
|
|
|
|
'Adresse_ImmeubleBatimentResidence': '',
|
|
|
|
'Adresse_NumeroVoie': '',
|
|
|
|
'Adresse_Extension': '',
|
|
|
|
'Adresse_NomVoie': '',
|
|
|
|
'Adresse_CodeSTI': '',
|
|
|
|
'Adresse_BoitePostaleLieudit': '',
|
|
|
|
'Adresse_CodePostal': '',
|
|
|
|
'Adresse_Localite': '',
|
|
|
|
'Adresse_Quartier': '',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
soap_mock.add_soap_response(
|
|
|
|
'PLS_ELIGADR',
|
|
|
|
{
|
|
|
|
'PLS_ELIGADRResult': {
|
|
|
|
'CodeRetour': '01',
|
|
|
|
'MessageRetour': 'Elligible',
|
|
|
|
'Adresse_EtageEscalierAppartement': '',
|
|
|
|
'Adresse_ImmeubleBatimentResidence': '',
|
|
|
|
'Adresse_NumeroVoie': '13',
|
|
|
|
'Adresse_Extension': '1',
|
|
|
|
'Adresse_NomVoie': 'Rue des Abeilles',
|
|
|
|
'Adresse_CodeSTI': '315550016038',
|
|
|
|
'Adresse_BoitePostaleLieudit': '',
|
|
|
|
'Adresse_CodePostal': '31000',
|
|
|
|
'Adresse_Localite': 'Toulouse',
|
|
|
|
'Adresse_Quartier': 'Dupuy',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-06-15 15:07:44 +02:00
|
|
|
|
2018-10-25 11:56:02 +02:00
|
|
|
params = {'address_sticode': '315553637461', 'address_zipcode': '44000'}
|
|
|
|
# missing required parameter
|
|
|
|
app.get('/dpark/test/address-eligibility/', params=params, status=400)
|
|
|
|
# not eligible
|
|
|
|
params['address_locality'] = 'Nantes'
|
|
|
|
resp = app.get('/dpark/test/address-eligibility/', params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'Erreur extension'
|
|
|
|
# eligible
|
|
|
|
params['address_streetext'] = 1
|
|
|
|
resp = app.get('/dpark/test/address-eligibility/', params=params)
|
|
|
|
content = resp.json
|
|
|
|
assert content['data'] is True
|
|
|
|
assert content['address']
|
|
|
|
assert content['address']['address_locality'] == 'Toulouse'
|
2018-06-15 15:07:44 +02:00
|
|
|
|
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_subscriber_infos(dpark, app, get_service):
|
|
|
|
nameid = 'abcd' * 8
|
|
|
|
url = '/dpark/test/infos/%s/' % nameid
|
|
|
|
params = {
|
|
|
|
'nameid': nameid,
|
|
|
|
'firstnames': 'spam eggs',
|
|
|
|
'lastname': 'bar',
|
|
|
|
'filenumber': '1' * 9,
|
|
|
|
'badgenumber': '2' * 9,
|
|
|
|
}
|
|
|
|
Pairing.objects.create(resource=dpark, **params)
|
|
|
|
# unknown subscriber
|
|
|
|
resp = app.get('/dpark/test/infos/toto/')
|
|
|
|
assert resp.json['data'] == []
|
|
|
|
# unknown file
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Dossier inconnu'}
|
|
|
|
)
|
|
|
|
resp = app.get(url)
|
|
|
|
assert resp.json['data'] == []
|
|
|
|
# known file
|
|
|
|
replydata = {
|
|
|
|
'CodeRetour': '01',
|
|
|
|
'MessageRetour': 'Dossier existant',
|
|
|
|
"Adresse_BoitePostaleLieuDit": None,
|
|
|
|
"Adresse_CodePostal": "44000",
|
|
|
|
"Adresse_CodeSTI": "315553609651",
|
|
|
|
"Adresse_EtageEscalierAppartement": None,
|
|
|
|
"Adresse_Extension": 1,
|
|
|
|
"Adresse_ImmeubleBatimentResidence": None,
|
|
|
|
"Adresse_Localite": "Nantes",
|
|
|
|
"Adresse_NomVoie": "All\u00e9es Jean Jaur\u00e8s",
|
|
|
|
"Adresse_NumeroVoie": 80,
|
|
|
|
"Adresse_Quartier": "PERI",
|
|
|
|
"Demande_DateDebutAbo": "20180625",
|
|
|
|
"Demande_DateFinAbo": "20190624",
|
|
|
|
"Demande_DelaiAutorise": 30,
|
|
|
|
"Demande_ImmatVehicule1": "CX453AD",
|
|
|
|
"Demande_ImmatVehicule2": None,
|
|
|
|
"Demande_MarqueVehicule1": "CITROEN",
|
|
|
|
"Demande_MarqueVehicule2": None,
|
|
|
|
"Demande_ModeleVehicule1": "GS",
|
|
|
|
"Demande_ModeleVehicule2": None,
|
|
|
|
"Demande_NumeroDossier": 22952,
|
|
|
|
"Demandeur_Civilite": 1,
|
|
|
|
"Demandeur_Email": "spameggs@example.net",
|
|
|
|
"Demandeur_NomUsuel": "BAR",
|
|
|
|
"Demandeur_Prenom": "Foo Spam",
|
|
|
|
"Demandeur_TelephoneFixe": "0611111111",
|
|
|
|
"Demandeur_TelephonePortable": None,
|
|
|
|
}
|
|
|
|
get_service.return_value = MockedService(replydata=replydata)
|
|
|
|
resp = app.get(url)
|
|
|
|
data = resp.json['data']
|
|
|
|
assert data[0]['id'] == '22952'
|
|
|
|
assert data[0]['text'] == '22952 - BAR Foo Spam - CX453AD'
|
|
|
|
assert data[0]['adresse_codepostal'] == '44000'
|
|
|
|
assert data[0]['adresse_codesti'] == '315553609651'
|
|
|
|
assert data[0]['adresse_localite'] == 'Nantes'
|
|
|
|
assert data[0]['demande_numerodossier'] == 22952
|
|
|
|
assert data[0]['demandeur_email'] == 'spameggs@example.net'
|
|
|
|
assert data[0]['demandeur_telephonefixe'] == '0611111111'
|
|
|
|
assert data[0]['demande_datedebutabo'] == '2018-06-25'
|
|
|
|
assert data[0]['demande_datefinabo'] == '2019-06-24'
|
|
|
|
|
|
|
|
# mutiple pairing
|
|
|
|
Pairing.objects.create(
|
|
|
|
resource=dpark,
|
|
|
|
nameid=nameid,
|
|
|
|
firstnames='monty',
|
|
|
|
lastname='eggs',
|
|
|
|
filenumber='5' * 9,
|
|
|
|
badgenumber='6' * 9,
|
|
|
|
cardnumber='7' * 9,
|
|
|
|
)
|
|
|
|
replydata2 = {
|
|
|
|
'CodeRetour': '01',
|
|
|
|
'MessageRetour': 'Dossier existant',
|
|
|
|
"Adresse_BoitePostaleLieuDit": None,
|
|
|
|
"Adresse_CodePostal": "94000",
|
|
|
|
"Adresse_CodeSTI": "315553609651",
|
|
|
|
"Adresse_EtageEscalierAppartement": None,
|
|
|
|
"Adresse_Extension": 1,
|
|
|
|
"Adresse_ImmeubleBatimentResidence": None,
|
|
|
|
"Adresse_Localite": "Creteil",
|
|
|
|
"Adresse_NomVoie": "Allée les sablons",
|
|
|
|
"Adresse_NumeroVoie": 5,
|
|
|
|
"Adresse_Quartier": "HOOLI",
|
|
|
|
"Demande_DateDebutAbo": "20180430",
|
|
|
|
"Demande_DateFinAbo": None,
|
|
|
|
"Demande_DelaiAutorise": 30,
|
|
|
|
"Demande_ImmatVehicule1": "AA555BB",
|
|
|
|
"Demande_ImmatVehicule2": "XX333YY",
|
|
|
|
"Demande_MarqueVehicule1": "FORD",
|
|
|
|
"Demande_MarqueVehicule2": "MERCEDES",
|
|
|
|
"Demande_ModeleVehicule1": "Fiesta",
|
|
|
|
"Demande_ModeleVehicule2": "Serie A",
|
|
|
|
"Demande_NumeroDossier": 22955,
|
|
|
|
"Demandeur_Civilite": 1,
|
|
|
|
"Demandeur_Email": "spameggs@example.net",
|
|
|
|
"Demandeur_NomUsuel": "EGGS",
|
|
|
|
"Demandeur_Prenom": "Monty",
|
|
|
|
"Demandeur_TelephoneFixe": "0611111111",
|
|
|
|
"Demandeur_TelephonePortable": None,
|
|
|
|
}
|
|
|
|
# there will be only one call as first pairing is now cached
|
|
|
|
get_service.side_effect = [MockedService(replydata=replydata2)]
|
|
|
|
resp = app.get(url)
|
|
|
|
data = resp.json['data']
|
|
|
|
assert len(data) == 2
|
|
|
|
assert data[1]['id'] == '22955'
|
|
|
|
assert data[1]['text'] == '22955 - EGGS Monty - AA555BB/XX333YY'
|
|
|
|
assert data[1]['adresse_codepostal'] == '94000'
|
|
|
|
assert data[1]['adresse_codesti'] == '315553609651'
|
|
|
|
assert data[1]['adresse_localite'] == 'Creteil'
|
|
|
|
assert data[1]['demande_numerodossier'] == 22955
|
|
|
|
assert data[1]['demandeur_email'] == 'spameggs@example.net'
|
|
|
|
assert data[1]['demandeur_telephonefixe'] == '0611111111'
|
|
|
|
assert data[1]['demande_datedebutabo'] == '2018-04-30'
|
|
|
|
assert data[1]['demande_datefinabo'] is None
|
|
|
|
|
|
|
|
# filtering by filenumber
|
|
|
|
for pairing in Pairing.objects.all():
|
|
|
|
pairing.clear_cache()
|
|
|
|
# we modify numerodossier to verify cache is not used
|
|
|
|
replydata['Demande_NumeroDossier'] = 22953
|
|
|
|
get_service.side_effect = [
|
|
|
|
MockedService(replydata=replydata),
|
|
|
|
]
|
|
|
|
resp = app.get(url, params={'filenumber': '1' * 9})
|
|
|
|
data = resp.json['data']
|
|
|
|
assert len(data) == 1
|
|
|
|
assert data[0]['id'] == '22953'
|
|
|
|
assert data[0]['text'] == '22953 - BAR Foo Spam - CX453AD'
|
|
|
|
assert data[0]['adresse_codepostal'] == '44000'
|
|
|
|
assert data[0]['adresse_codesti'] == '315553609651'
|
|
|
|
assert data[0]['adresse_localite'] == 'Nantes'
|
|
|
|
assert data[0]['demande_numerodossier'] == 22953
|
|
|
|
assert data[0]['demandeur_email'] == 'spameggs@example.net'
|
|
|
|
assert data[0]['demandeur_telephonefixe'] == '0611111111'
|
|
|
|
assert data[0]['demande_datedebutabo'] == '2018-06-25'
|
|
|
|
assert data[0]['demande_datefinabo'] == '2019-06-24'
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_renewal_time(dpark, app, get_service):
|
|
|
|
url = '/dpark/test/check-renewal-time/'
|
|
|
|
params = {'firstnames': 'spam eggs', 'lastname': 'bar', 'filenumber': '1' * 9, 'badgenumber': '2' * 9}
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Renouvellement hors délai'}
|
|
|
|
)
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is False
|
|
|
|
assert resp.json['desc'] == 'Renouvellement hors délai'
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '01', 'MessageRetour': 'Dossier existant'}
|
|
|
|
)
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_renewal_duplicate(dpark, app, get_service):
|
|
|
|
url = '/dpark/test/check-renewal-time/'
|
|
|
|
params = {'firstnames': 'spam eggs', 'lastname': 'bar', 'filenumber': '1' * 9, 'badgenumber': '2' * 9}
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Demande déjà en cours'}
|
|
|
|
)
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is False
|
|
|
|
assert resp.json['desc'] == 'Demande déjà en cours'
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '01', 'MessageRetour': 'Dossier existant'}
|
|
|
|
)
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is True
|
|
|
|
assert resp.json['err'] == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_creation_duplicate(dpark, app, get_service):
|
|
|
|
url = '/dpark/test/check-creation-duplicate/'
|
|
|
|
params = {
|
|
|
|
'address_district': 'PERI',
|
|
|
|
'address_locality': 'Toulouse',
|
|
|
|
'address_sticode': '315553609651',
|
|
|
|
'address_streetext': '1',
|
|
|
|
'address_zipcode': '31000',
|
|
|
|
'applicant_firstnames': 'Spam',
|
|
|
|
'applicant_lastname': 'Ham',
|
|
|
|
}
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Demande déjà en cours'}
|
|
|
|
)
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is False
|
|
|
|
assert resp.json['desc'] == 'Demande déjà en cours'
|
|
|
|
get_service.return_value = MockedService(replydata={'CodeRetour': '01', 'MessageRetour': ''})
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is True
|
|
|
|
assert resp.json['err'] == 0
|
|
|
|
|
|
|
|
|
|
|
|
def test_check_creation_not_renewal(dpark, app, get_service):
|
|
|
|
url = '/dpark/test/check-creation-not-renewal/'
|
|
|
|
params = {
|
|
|
|
'address_district': 'PERI',
|
|
|
|
'address_locality': 'Toulouse',
|
|
|
|
'address_sticode': '315553609651',
|
|
|
|
'address_streetext': '1',
|
|
|
|
'address_zipcode': '31000',
|
|
|
|
'applicant_firstnames': 'Spam',
|
|
|
|
'applicant_lastname': 'Ham',
|
|
|
|
}
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Usager existe déjà dans D-Park'}
|
|
|
|
)
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is False
|
|
|
|
assert resp.json['desc'] == 'Usager existe déjà dans D-Park'
|
|
|
|
get_service.return_value = MockedService(replydata={'CodeRetour': '01', 'MessageRetour': ''})
|
|
|
|
resp = app.get(url, params=params)
|
|
|
|
assert resp.json['data'] is True
|
|
|
|
|
|
|
|
|
|
|
|
def test_get_payment_infos(dpark, app, get_service):
|
|
|
|
nameid = 'abcd' * 8
|
|
|
|
url = '/dpark/test/payment-info/%s/' % nameid
|
|
|
|
resp = app.get(url)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'No pairing exists'
|
|
|
|
params = {
|
|
|
|
'nameid': nameid,
|
|
|
|
'firstnames': 'spam eggs',
|
|
|
|
'lastname': 'bar',
|
|
|
|
'filenumber': '1' * 9,
|
|
|
|
'badgenumber': '2' * 9,
|
|
|
|
}
|
|
|
|
Pairing.objects.create(resource=dpark, **params)
|
|
|
|
get_service.return_value = MockedService(
|
|
|
|
replydata={'CodeRetour': '02', 'MessageRetour': 'Dossier inconnu'}
|
|
|
|
)
|
|
|
|
resp = app.get(url)
|
|
|
|
assert resp.json['err'] == 0
|
|
|
|
assert resp.json['data'] == []
|
|
|
|
replydata = {
|
|
|
|
'CodeRetour': '01',
|
|
|
|
'MessageRetour': 'Demande acceptée',
|
|
|
|
'NumeroDemande': '55555',
|
|
|
|
'Montant': 12500,
|
|
|
|
'TypePaiement': 10,
|
|
|
|
'NumeroTeledossierPhase1': 'E-8-0AA666BB',
|
|
|
|
}
|
|
|
|
get_service.return_value = MockedService(replydata=replydata)
|
|
|
|
resp = app.get(url)
|
|
|
|
data = resp.json['data'][0]
|
|
|
|
assert data['montant'] == 125
|
|
|
|
assert data['typepaiement'] == 10
|
|
|
|
assert data['typepaiement_text'] == 'Carte Bancaire via Internet'
|
|
|
|
assert data['numerodemande'] == '55555'
|
2018-07-09 14:29:28 +02:00
|
|
|
|
|
|
|
|
2020-04-07 15:04:38 +02:00
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'transaction_datetime,expected_date',
|
|
|
|
[
|
|
|
|
('20180611', '20180611'),
|
|
|
|
# UTC datetime should be converted to Europe/Paris date
|
|
|
|
('2018-06-11T23:59:00', '20180612'),
|
|
|
|
],
|
|
|
|
)
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_payment_notification(dpark, app, transaction_datetime, expected_date, get_service):
|
2020-04-07 15:04:38 +02:00
|
|
|
operation = mock.Mock(name='PLS_NOTIFCB')
|
|
|
|
service = mock.Mock(spec=['PLS_NOTIFCB'], PLS_NOTIFCB=operation)
|
2022-12-20 12:00:57 +01:00
|
|
|
get_service.return_value = service
|
|
|
|
|
|
|
|
nameid = 'abcd' * 8
|
|
|
|
filenumber = '1' * 9
|
|
|
|
params = {
|
|
|
|
'nameid': nameid,
|
|
|
|
'filenumber': filenumber,
|
|
|
|
'transaction_id': 'I123456789',
|
|
|
|
'transaction_datetime': transaction_datetime,
|
|
|
|
'total_amount': '125',
|
|
|
|
'application_id': '61718',
|
|
|
|
'application_external_id': 'E-8-N5UTAK6P',
|
|
|
|
}
|
|
|
|
url = '/dpark/test/notify-payment/'
|
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'No pairing exists'
|
|
|
|
Pairing.objects.create(
|
|
|
|
resource=dpark,
|
|
|
|
**{
|
2018-07-09 14:29:28 +02:00
|
|
|
'nameid': nameid,
|
2022-12-20 12:00:57 +01:00
|
|
|
'firstnames': 'spam eggs',
|
|
|
|
'lastname': 'bar',
|
2018-07-09 14:29:28 +02:00
|
|
|
'filenumber': filenumber,
|
2022-12-20 12:00:57 +01:00
|
|
|
'badgenumber': '2' * 9,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
operation.return_value = mock.Mock(CodeRetour='02', MessageRetour='Dossier inconnu')
|
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert operation.call_args_list[-1].args[5] == expected_date
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'Dossier inconnu'
|
|
|
|
operation.return_value = mock.Mock(CodeRetour='01')
|
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['data'] is True
|
2018-07-09 14:29:28 +02:00
|
|
|
|
|
|
|
|
2018-10-22 13:10:19 +02:00
|
|
|
@pytest.mark.parametrize('application_thirdparty_subscription', [True, False])
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_registration(dpark, app, application_thirdparty_subscription, soap_mock):
|
|
|
|
soap_mock.add_soap_response(
|
|
|
|
'PLS_ENREG',
|
|
|
|
{
|
|
|
|
'PLS_ENREGResult': {
|
|
|
|
'CodeRetour': '02',
|
|
|
|
'MessageRetour': 'Dossier incomplet',
|
|
|
|
'NumeroDossier': 0,
|
|
|
|
'NumeroDemande': 0,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
soap_mock.add_soap_response(
|
|
|
|
'PLS_ENREG',
|
|
|
|
{
|
|
|
|
'PLS_ENREGResult': {
|
|
|
|
'CodeRetour': '01',
|
|
|
|
'MessageRetour': '',
|
|
|
|
'NumeroDossier': 22334,
|
|
|
|
'NumeroDemande': 59492,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
2018-10-22 13:10:19 +02:00
|
|
|
url = '/dpark/test/register/'
|
|
|
|
params = {
|
|
|
|
"address_complement1": "",
|
|
|
|
"address_complement2": "",
|
|
|
|
"address_locality": "Toulouse",
|
|
|
|
"address_sticode": "315553609651",
|
|
|
|
"address_streetext": "1",
|
|
|
|
"address_streetname": "",
|
|
|
|
"address_streetno": "16",
|
|
|
|
"address_zipcode": "31000",
|
|
|
|
"applicant_email": "sh@eggs.org",
|
|
|
|
"applicant_firstnames": "Spam Ham",
|
|
|
|
"applicant_lastname": "EGGS",
|
|
|
|
"applicant_mobilephone": "0655443322",
|
|
|
|
"applicant_phone": "",
|
|
|
|
"applicant_title": "1",
|
|
|
|
"application_car1_brand": "Peugeot",
|
|
|
|
"application_car1_exemption": "8",
|
|
|
|
"application_car1_model": "206",
|
|
|
|
"application_car1_plate": "AA777ZZ",
|
|
|
|
"application_id": "12-4",
|
|
|
|
"application_payment_type": "10",
|
|
|
|
"application_thirdparty_subscription": application_thirdparty_subscription,
|
|
|
|
"application_type": 1,
|
|
|
|
}
|
|
|
|
# with missing parameter
|
|
|
|
app.post_json(url, params=params, status=400)
|
|
|
|
params['address_district'] = "PERI"
|
2022-12-20 12:00:57 +01:00
|
|
|
|
|
|
|
# with an incomplete application
|
2018-10-22 13:10:19 +02:00
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['err'] == 1
|
2022-03-17 16:54:24 +01:00
|
|
|
assert resp.json['err_desc'] == 'Dossier incomplet'
|
2022-12-20 12:00:57 +01:00
|
|
|
|
|
|
|
soap_request = soap_mock.soap_requests[0]
|
|
|
|
assert type(soap_request).__name__ == 'tPLS_ENREG'
|
|
|
|
assert soap_request.Entree_Demande.Demande_AbonnementTiers is application_thirdparty_subscription
|
|
|
|
|
2018-10-22 13:10:19 +02:00
|
|
|
# with complete application
|
|
|
|
resp = app.post_json(url, params=params)
|
2022-12-20 12:00:57 +01:00
|
|
|
soap_request = soap_mock.soap_requests[1]
|
2018-10-22 13:10:19 +02:00
|
|
|
assert resp.json['data']['numerodossier'] == 22334
|
|
|
|
assert resp.json['data']['numerodemande'] == 59492
|
2018-07-09 14:29:28 +02:00
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
assert type(soap_request).__name__ == 'tPLS_ENREG'
|
|
|
|
assert soap_request.Entree_Demande.Demande_AbonnementTiers is application_thirdparty_subscription
|
|
|
|
|
2018-07-09 14:29:28 +02:00
|
|
|
|
2018-10-21 16:14:35 +02:00
|
|
|
# we need to freeze_time as Pillow (used by to_pdf()) embed the current time in
|
|
|
|
# the produced PDF, so to get some deterministic behaviour it's needed to
|
|
|
|
# freeze the time.
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_send_files(dpark, app, soap_mock, settings, freezer):
|
2018-07-24 15:58:08 +02:00
|
|
|
params = {'application_external_id': 'E-8-N5UTAK6P'}
|
|
|
|
with mock.patch('passerelle.contrib.dpark.models.DPark.call') as soap_call:
|
2018-07-09 14:29:28 +02:00
|
|
|
url = '/dpark/test/send-files/'
|
2018-07-24 15:58:08 +02:00
|
|
|
app.post_json(url, params=params, status=400)
|
|
|
|
params['application_id'] = ''
|
2018-07-09 14:29:28 +02:00
|
|
|
app.post_json(url, params=params, status=400)
|
|
|
|
params['application_id'] = '61718'
|
2018-07-24 15:58:08 +02:00
|
|
|
soap_call.side_effect = APIError('Numéro de demande introuvable')
|
2018-07-09 14:29:28 +02:00
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['err'] == 1
|
2022-03-17 16:54:24 +01:00
|
|
|
assert resp.json['err_desc'] == 'Numéro de demande introuvable'
|
2018-07-24 15:58:08 +02:00
|
|
|
|
|
|
|
params['justif_domicile'] = {
|
2019-04-26 18:28:02 +02:00
|
|
|
'filename': 'address_proof.pDf',
|
|
|
|
'content_type': 'application/pdf',
|
2022-08-31 10:21:14 +02:00
|
|
|
'content': force_str(base64.b64encode(b'%PDF this is my proof of address')),
|
2020-01-21 10:42:22 +01:00
|
|
|
}
|
2018-07-24 15:58:08 +02:00
|
|
|
params['cartegrise,1'] = {
|
|
|
|
'filename': 'cartegrise.pdf',
|
|
|
|
'content_type': 'application/pdf',
|
2022-08-31 10:21:14 +02:00
|
|
|
'content': force_str(base64.b64encode(b'%PDF carte grise 1')),
|
2018-07-24 15:58:08 +02:00
|
|
|
}
|
|
|
|
params['toto,6'] = {
|
2019-04-26 18:28:02 +02:00
|
|
|
'filename': 'cartegrisetoto.jpg',
|
2018-09-24 16:23:36 +02:00
|
|
|
'content_type': 'application/pdf',
|
2022-08-31 10:21:14 +02:00
|
|
|
'content': force_str(base64.b64encode(JPEG_CONTENT)),
|
2018-07-24 15:58:08 +02:00
|
|
|
}
|
|
|
|
params['cartegrise,6'] = {
|
|
|
|
'filename': 'cartegrise2.pdf',
|
|
|
|
'content_type': 'application/pdf',
|
2022-08-31 10:21:14 +02:00
|
|
|
'content': force_str(base64.b64encode(b'%PDF carte grise 2')),
|
2018-07-24 15:58:08 +02:00
|
|
|
}
|
|
|
|
params['taxe_habitat'] = {
|
|
|
|
'filename': 'cartegrise2.pdf',
|
|
|
|
'content_type': 'application/pdf',
|
|
|
|
'content': None,
|
|
|
|
}
|
|
|
|
params['taxe_habitat,2'] = {'content_type': 'application/pdf', 'content': 'whatever'}
|
|
|
|
params['impot_revenu'] = 'this is my tax notice'
|
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
errors = [
|
2022-03-17 16:54:24 +01:00
|
|
|
"<impot_revenu> value is not a dict",
|
|
|
|
"<taxe_habitat> <content> is either absent or has an invalid value",
|
|
|
|
"<taxe_habitat,2> <filename> is either absent or has an invalid value",
|
|
|
|
"Invalid document type: <toto,6>",
|
2018-07-24 15:58:08 +02:00
|
|
|
]
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == '%s' % errors
|
|
|
|
|
|
|
|
params.pop('impot_revenu')
|
|
|
|
params.pop('taxe_habitat')
|
|
|
|
params.pop('taxe_habitat,2')
|
|
|
|
|
|
|
|
# add custom document type
|
|
|
|
settings.DPARK_DOCUMENT_CODES = {'toto': '73'}
|
2022-12-20 12:00:57 +01:00
|
|
|
soap_mock.add_soap_response(
|
|
|
|
'PLS_ENVOIPJ',
|
|
|
|
{
|
|
|
|
'PLS_ENVOIPJResult': {
|
|
|
|
'CodeRetour': '01',
|
|
|
|
'MessageRetour': '',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
2018-09-14 12:04:31 +02:00
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['err'] == 0
|
|
|
|
assert resp.json['data'] is True
|
2022-12-20 12:00:57 +01:00
|
|
|
assert len(soap_mock.soap_requests) == 1
|
2018-09-24 16:23:36 +02:00
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
soap_request = soap_mock.soap_requests[0]
|
|
|
|
assert soap_request.NumeroTeledossier == 'E-8-N5UTAK6P'
|
|
|
|
assert soap_request.NumeroDossier == 61718
|
|
|
|
assert soap_request.NbFichier == 4
|
|
|
|
assert soap_request.Bloc_Fichiers[0].TypeDocument == '6'
|
|
|
|
assert soap_request.Bloc_Fichiers[0].NomFichier == 'cartegrise.pdf'
|
|
|
|
assert soap_request.Bloc_Fichiers[0].Fichier == b'%PDF carte grise 1'
|
2021-02-20 16:26:01 +01:00
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
assert soap_request.Bloc_Fichiers[1].TypeDocument == '6'
|
|
|
|
assert soap_request.Bloc_Fichiers[1].NomFichier == 'cartegrise2.pdf'
|
|
|
|
assert soap_request.Bloc_Fichiers[1].Fichier == b'%PDF carte grise 2'
|
|
|
|
|
|
|
|
assert soap_request.Bloc_Fichiers[2].TypeDocument == '2'
|
|
|
|
assert soap_request.Bloc_Fichiers[2].NomFichier == 'address_proof.pDf'
|
|
|
|
assert soap_request.Bloc_Fichiers[2].Fichier == b'%PDF this is my proof of address'
|
|
|
|
|
|
|
|
assert soap_request.Bloc_Fichiers[3].TypeDocument == '73'
|
|
|
|
assert soap_request.Bloc_Fichiers[3].NomFichier == 'cartegrisetoto.jpg.pdf'
|
|
|
|
assert soap_request.Bloc_Fichiers[3].Fichier == to_pdf(JPEG_CONTENT)
|
|
|
|
assert soap_request.Bloc_Fichiers[3].Fichier.startswith(b'%PDF')
|
2022-05-30 15:39:34 +02:00
|
|
|
|
|
|
|
|
|
|
|
@pytest.mark.parametrize('application_thirdparty_subscription', [True, False])
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_registration_double_plaque(dpark, app, soap_mock, application_thirdparty_subscription):
|
2022-05-30 15:39:34 +02:00
|
|
|
url = '/dpark/test/register/'
|
|
|
|
params = {
|
|
|
|
"address_complement1": "",
|
|
|
|
"address_complement2": "",
|
|
|
|
"address_district": "PERI",
|
|
|
|
"address_locality": "Toulouse",
|
|
|
|
"address_sticode": "315553609651",
|
|
|
|
"address_streetext": "1",
|
|
|
|
"address_streetname": "",
|
|
|
|
"address_streetno": "16",
|
|
|
|
"address_zipcode": "31000",
|
|
|
|
"applicant_email": "sh@eggs.org",
|
|
|
|
"applicant_firstnames": "Spam Ham",
|
|
|
|
"applicant_lastname": "EGGS",
|
|
|
|
"applicant_mobilephone": "0655443322",
|
|
|
|
"applicant_phone": "",
|
|
|
|
"applicant_title": "1",
|
|
|
|
"application_car1_brand": "Peugeot",
|
|
|
|
"application_car1_exemption": "8",
|
|
|
|
"application_car1_model": "206",
|
|
|
|
"application_car1_plate": "AA777ZZ",
|
|
|
|
"application_id": "12-4",
|
|
|
|
"application_payment_type": "10",
|
|
|
|
"application_thirdparty_subscription": application_thirdparty_subscription,
|
|
|
|
"application_type": 1,
|
|
|
|
'double_plaque': '1',
|
|
|
|
}
|
|
|
|
# with missing parameter
|
|
|
|
app.post_json(url, params=params, status=400)
|
|
|
|
params.update(
|
|
|
|
{
|
|
|
|
'id_contexte': '1',
|
|
|
|
'id_produit': '2',
|
|
|
|
}
|
|
|
|
)
|
|
|
|
# with an imcplete application
|
2022-12-20 12:00:57 +01:00
|
|
|
soap_mock.add_soap_response(
|
|
|
|
'PLS_ENREG2',
|
|
|
|
{
|
|
|
|
'PLS_ENREG2Result': {
|
|
|
|
'CodeRetour': '02',
|
|
|
|
'MessageRetour': 'Dossier incomplet',
|
|
|
|
'NumeroDossier': 0,
|
|
|
|
'NumeroDemande': 0,
|
|
|
|
}
|
|
|
|
},
|
2022-05-30 15:39:34 +02:00
|
|
|
)
|
2022-12-20 12:00:57 +01:00
|
|
|
soap_mock.add_soap_response(
|
|
|
|
'PLS_ENREG2',
|
|
|
|
{
|
|
|
|
'PLS_ENREG2Result': {
|
|
|
|
'CodeRetour': '01',
|
|
|
|
'MessageRetour': '',
|
|
|
|
'NumeroDossier': 22334,
|
|
|
|
'NumeroDemande': 59492,
|
|
|
|
}
|
|
|
|
},
|
2022-05-30 15:39:34 +02:00
|
|
|
)
|
2022-12-20 12:00:57 +01:00
|
|
|
|
|
|
|
# result is incomplete application
|
|
|
|
resp = app.post_json(url, params=params)
|
2022-05-30 15:39:34 +02:00
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'Dossier incomplet'
|
2022-12-20 12:00:57 +01:00
|
|
|
|
|
|
|
soap_request = soap_mock.soap_requests[0]
|
|
|
|
assert soap_request.ID_CONTEXTE == 1
|
|
|
|
assert soap_request.ID_PRODUIT == 2
|
|
|
|
|
|
|
|
# with is ok
|
2022-05-30 15:39:34 +02:00
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['data']['numerodossier'] == 22334
|
|
|
|
assert resp.json['data']['numerodemande'] == 59492
|
|
|
|
|
2022-12-20 12:00:57 +01:00
|
|
|
soap_request = soap_mock.soap_requests[0]
|
|
|
|
assert soap_request.Entree_Demande.Demande_AbonnementTiers is application_thirdparty_subscription
|
|
|
|
|
2022-05-30 15:39:34 +02:00
|
|
|
|
|
|
|
@pytest.mark.parametrize(
|
|
|
|
'transaction_datetime,expected_date',
|
|
|
|
[
|
|
|
|
('20180611', '20180611'),
|
|
|
|
# UTC datetime should be converted to Europe/Paris date
|
|
|
|
('2018-06-11T23:59:00', '20180612'),
|
|
|
|
],
|
|
|
|
)
|
2022-12-20 12:00:57 +01:00
|
|
|
def test_payment_notification_double_plaque(dpark, app, transaction_datetime, expected_date, get_service):
|
2022-05-30 15:39:34 +02:00
|
|
|
operation = mock.Mock(name='PLS_NOTIFCB2')
|
|
|
|
service = mock.Mock(spec=['PLS_NOTIFCB2'], PLS_NOTIFCB2=operation)
|
2022-12-20 12:00:57 +01:00
|
|
|
get_service.return_value = service
|
|
|
|
|
|
|
|
nameid = 'abcd' * 8
|
|
|
|
filenumber = '1' * 9
|
|
|
|
params = {
|
|
|
|
'nameid': nameid,
|
|
|
|
'filenumber': filenumber,
|
|
|
|
'transaction_id': 'I123456789',
|
|
|
|
'transaction_datetime': transaction_datetime,
|
|
|
|
'total_amount': '125',
|
|
|
|
'application_id': '61718',
|
|
|
|
'application_external_id': 'E-8-N5UTAK6P',
|
|
|
|
'double_plaque': '1',
|
|
|
|
}
|
|
|
|
url = '/dpark/test/notify-payment/'
|
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'No pairing exists'
|
|
|
|
Pairing.objects.create(
|
|
|
|
resource=dpark,
|
|
|
|
**{
|
2022-05-30 15:39:34 +02:00
|
|
|
'nameid': nameid,
|
2022-12-20 12:00:57 +01:00
|
|
|
'firstnames': 'spam eggs',
|
|
|
|
'lastname': 'bar',
|
2022-05-30 15:39:34 +02:00
|
|
|
'filenumber': filenumber,
|
2022-12-20 12:00:57 +01:00
|
|
|
'badgenumber': '2' * 9,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
operation.return_value = mock.Mock(CodeRetour='02', MessageRetour='Dossier inconnu')
|
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert operation.call_args_list[-1].args[5] == expected_date
|
|
|
|
assert resp.json['err'] == 1
|
|
|
|
assert resp.json['err_desc'] == 'Dossier inconnu'
|
|
|
|
operation.return_value = mock.Mock(CodeRetour='01')
|
|
|
|
resp = app.post_json(url, params=params)
|
|
|
|
assert resp.json['data'] is True
|