0003-toulouse-maelis-pass-get-direct-debit-order-paramete.patch
functests/toulouse_maelis/test_invoice.py | ||
---|---|---|
20 | 20 |
'bank/firstName': 'John Ross', |
21 | 21 |
} |
22 | 22 |
resp = requests.post(url, json=payload) |
23 | 23 |
resp.raise_for_status() |
24 | 24 |
res = resp.json() |
25 | 25 |
assert res['data'] == 'ok' |
26 | 26 | |
27 | 27 |
url = conn + '/get-rl1-direct-debit-order?NameID=%s' % create_data['name_id'] |
28 |
payload = {
|
|
28 |
params = {
|
|
29 | 29 |
'codeRegie': '1', |
30 | 30 |
'dateRef': '2023-01-01', |
31 | 31 |
} |
32 |
resp = requests.post(url, json=payload)
|
|
32 |
resp = requests.get(url, params=params)
|
|
33 | 33 |
resp.raise_for_status() |
34 | 34 |
res = resp.json() |
35 | 35 |
res['data']['numPerson'] = 'N/A' |
36 | 36 |
assert diff(res['data'], 'test_get_rl1_direct_debit_order.json') |
passerelle/contrib/toulouse_maelis/invoice_schemas.py | ||
---|---|---|
69 | 69 |
'codeRegie': { |
70 | 70 |
'description': 'Code de la régie', |
71 | 71 |
'type': 'string', |
72 | 72 |
}, |
73 | 73 |
}, |
74 | 74 |
'additionalProperties': False, |
75 | 75 |
'unflatten': True, |
76 | 76 |
} |
77 | ||
78 | ||
79 |
GET_DIRECT_DEBIT_ORDER_SCHEMA = { |
|
80 |
'$schema': 'http://json-schema.org/draft-04/schema#', |
|
81 |
'title': 'Get direct debit order', |
|
82 |
'description': "Lecture des informations relatives à l'autorisation de prélèvement en cours à la date de référence", |
|
83 |
'type': 'object', |
|
84 |
'required': ['codeRegie', 'dateRef'], |
|
85 |
'properties': { |
|
86 |
'codeRegie': { |
|
87 |
'description': 'Code de la régie', |
|
88 |
'type': 'string', |
|
89 |
}, |
|
90 |
'dateRef': { |
|
91 |
'description': 'Date de référence ', |
|
92 |
'type': 'string', |
|
93 |
'pattern': '^[0-9]{4}-[0-9]{2}-[0-9]{2}$', |
|
94 |
}, |
|
95 |
}, |
|
96 |
'additionalProperties': False, |
|
97 |
'unflatten': True, |
|
98 |
} |
passerelle/contrib/toulouse_maelis/models.py | ||
---|---|---|
13 | 13 |
# You should have received a copy of the GNU Affero General Public License |
14 | 14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 | |
16 | 16 |
from urllib.parse import urljoin |
17 | 17 | |
18 | 18 |
import zeep |
19 | 19 |
from django.contrib.postgres.fields import JSONField |
20 | 20 |
from django.db import models |
21 |
from django.utils.dateparse import parse_date |
|
21 | 22 |
from django.utils.timezone import now |
22 | 23 |
from zeep.helpers import serialize_object |
23 | 24 |
from zeep.wsse.username import UsernameToken |
24 | 25 | |
25 | 26 |
from passerelle.base.models import BaseResource, HTTPResource |
26 | 27 |
from passerelle.utils.api import endpoint |
27 | 28 |
from passerelle.utils.conversion import simplify |
28 | 29 |
from passerelle.utils.jsonresponse import APIError |
... | ... | |
1564 | 1565 |
self.call('Invoice', 'addDirectDebitOrder', dossierNumber=family_id, **post_data) |
1565 | 1566 |
return {'data': 'ok'} |
1566 | 1567 | |
1567 | 1568 |
@endpoint( |
1568 | 1569 |
display_category='Facture', |
1569 | 1570 |
description="Lecture des informations relatives à l'autorisation de prélèvement en cours à la date de référence", |
1570 | 1571 |
name='get-rl1-direct-debit-order', |
1571 | 1572 |
perm='can_access', |
1572 |
parameters={'NameID': {'description': 'Publik NameID'}}, |
|
1573 |
post={ |
|
1574 |
'request_body': {'schema': {'application/json': invoice_schemas.GET_DIRECT_DEBIT_ORDER_SCHEMA}} |
|
1573 |
parameters={ |
|
1574 |
'NameID': {'description': 'Publik NameID'}, |
|
1575 |
'codeRegie': {'description': 'Code de la régie'}, |
|
1576 |
'dateRef': { |
|
1577 |
'description': 'Date de référence', |
|
1578 |
'example_value': '2023-01-01', |
|
1579 |
}, |
|
1575 | 1580 |
}, |
1576 | 1581 |
) |
1577 |
def get_rl1_direct_debit_order(self, request, NameID, post_data): |
|
1582 |
def get_rl1_direct_debit_order(self, request, NameID, codeRegie, dateRef): |
|
1583 |
try: |
|
1584 |
dateRef = parse_date(dateRef) |
|
1585 |
except ValueError: |
|
1586 |
raise APIError('invalid value for parameter dateRef (not a valid date)') |
|
1587 |
if not dateRef: |
|
1588 |
raise APIError('invalid value for parameter dateRef (YYYY-MM-DD expected)') |
|
1578 | 1589 |
family_id = self.get_link(NameID).family_id |
1579 | 1590 |
family = self.get_family_raw(family_id) |
1580 | 1591 | |
1581 |
post_data['numPerson'] = family['RL1']['num'] |
|
1582 |
response = self.call('Invoice', 'getDirectDebitOrder', dossierNumber=family_id, **post_data) |
|
1592 |
payload = { |
|
1593 |
'dossierNumber': family_id, |
|
1594 |
'numPerson': family['RL1']['num'], |
|
1595 |
'codeRegie': codeRegie, |
|
1596 |
'dateRef': dateRef, |
|
1597 |
} |
|
1598 |
response = self.call('Invoice', 'getDirectDebitOrder', **payload) |
|
1583 | 1599 |
data = serialize_object(response) |
1584 | 1600 |
return {'data': data} |
1585 | 1601 | |
1586 | 1602 | |
1587 | 1603 |
class Link(models.Model): |
1588 | 1604 |
resource = models.ForeignKey(ToulouseMaelis, on_delete=models.CASCADE) |
1589 | 1605 |
name_id = models.CharField(blank=False, max_length=256) |
1590 | 1606 |
family_id = models.CharField(blank=False, max_length=128) |
tests/test_toulouse_maelis.py | ||
---|---|---|
8 | 8 |
# This program is distributed in the hope that it will be useful, |
9 | 9 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | 10 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | 11 |
# GNU Affero General Public License for more details. |
12 | 12 |
# |
13 | 13 |
# You should have received a copy of the GNU Affero General Public License |
14 | 14 |
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | 15 | |
16 |
import datetime |
|
16 | 17 |
import logging |
17 | 18 |
import os |
18 | 19 |
from unittest import mock |
19 | 20 | |
20 | 21 |
import pytest |
21 | 22 |
import responses |
22 | 23 |
from requests.exceptions import ConnectionError |
23 | 24 |
from zeep import Settings |
... | ... | |
3298 | 3299 |
resp.json['err_desc'] |
3299 | 3300 |
== "indicatorList/0/code key value 'plop' do not belong to 'ChildIndicator' required referential" |
3300 | 3301 |
) |
3301 | 3302 | |
3302 | 3303 | |
3303 | 3304 |
def test_add_rl1_direct_debit_order(all_services, con, app): |
3304 | 3305 |
def request_check(request): |
3305 | 3306 |
assert request.dossierNumber == 1312 |
3307 |
assert request.bank['dateStart'] == datetime.datetime(2023, 1, 1, 0, 0) |
|
3306 | 3308 | |
3307 | 3309 |
all_services.add_soap_response('family', 'readFamily', get_xml_file('R_read_family.xml')) |
3308 | 3310 |
all_services.add_soap_response( |
3309 | 3311 |
'invoice', |
3310 | 3312 |
'addDirectDebitOrder', |
3311 | 3313 |
get_xml_file('R_add_direct_debit_order.xml'), |
3312 | 3314 |
request_check=request_check, |
3313 | 3315 |
) |
... | ... | |
3386 | 3388 |
) |
3387 | 3389 |
url = get_endpoint('get-rl1-direct-debit-order') |
3388 | 3390 |
params = { |
3389 | 3391 |
'codeRegie': '22', |
3390 | 3392 |
'dateRef': '2023-01-01', |
3391 | 3393 |
} |
3392 | 3394 | |
3393 | 3395 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
3394 |
resp = app.post_json(url + '?NameID=local', params=params) |
|
3396 |
resp = app.get(url + '?NameID=local', params=params) |
|
3397 | ||
3395 | 3398 |
assert resp.json['err'] == 0 |
3396 | 3399 |
assert resp.json['data'] == { |
3397 | 3400 |
'bankBIC': 'BDFEFR2T', |
3398 | 3401 |
'bankIBAN': 'FR7630001007941234567890185', |
3399 | 3402 |
'bankRUM': 'xxx', |
3400 | 3403 |
'dateStart': '2023-01-01T00:00:00+01:00', |
3401 | 3404 |
'bankAddress': '75049 PARIS cedex 01', |
3402 | 3405 |
'civility': 'x', |
3403 | 3406 |
'lastName': 'Ewing', |
3404 | 3407 |
'firstName': 'John Ross', |
3405 | 3408 |
} |
3406 | 3409 | |
3407 | 3410 | |
3408 | 3411 |
def test_get_rl1_direct_debit_order_parameter_error(con, app): |
3409 | 3412 |
url = get_endpoint('get-rl1-direct-debit-order') |
3413 | ||
3410 | 3414 |
params = { |
3411 | 3415 |
'codeRegie': '22', |
3412 | 3416 |
'dateRef': 'plop', |
3413 | 3417 |
} |
3418 |
resp = app.get(url + '?NameID=local', params=params) |
|
3419 |
assert resp.json['err'] == 1 |
|
3420 |
assert resp.json['err_class'] == 'passerelle.utils.jsonresponse.APIError' |
|
3421 |
assert resp.json['err_desc'] == 'invalid value for parameter dateRef (YYYY-MM-DD expected)' |
|
3414 | 3422 | |
3415 |
resp = app.post_json(url + '?NameID=local', params=params, status=400) |
|
3423 |
params = { |
|
3424 |
'codeRegie': '22', |
|
3425 |
'dateRef': '2023-02-31', |
|
3426 |
} |
|
3427 | ||
3428 |
resp = app.get(url + '?NameID=local', params=params) |
|
3416 | 3429 |
assert resp.json['err'] == 1 |
3417 | 3430 |
assert resp.json['err_class'] == 'passerelle.utils.jsonresponse.APIError' |
3418 |
assert resp.json['err_desc'] == "dateRef: 'plop' does not match '^[0-9]{4}-[0-9]{2}-[0-9]{2}$'"
|
|
3431 |
assert resp.json['err_desc'] == 'invalid value for parameter dateRef (not a valid date)'
|
|
3419 | 3432 | |
3420 | 3433 | |
3421 | 3434 |
def test_get_rl1_direct_debit_order_not_linked_error(con, app): |
3422 | 3435 |
url = get_endpoint('get-rl1-direct-debit-order') |
3423 | 3436 |
params = { |
3424 | 3437 |
'codeRegie': '22', |
3425 | 3438 |
'dateRef': '2023-01-01', |
3426 | 3439 |
} |
3427 | 3440 | |
3428 |
resp = app.post_json(url + '?NameID=local', params=params)
|
|
3441 |
resp = app.get(url + '?NameID=local', params=params)
|
|
3429 | 3442 |
assert resp.json['err'] == 'not-linked' |
3430 | 3443 |
assert resp.json['err_desc'] == 'User not linked to family' |
3431 | 3444 | |
3432 | 3445 | |
3433 | 3446 |
def test_get_rl1_direct_debit_order_soap_error(all_services, con, app): |
3434 | 3447 |
all_services.add_soap_response('family', 'readFamily', get_xml_file('R_read_family.xml')) |
3435 | 3448 |
all_services.add_soap_response( |
3436 | 3449 |
'invoice', 'getDirectDebitOrder', get_xml_file('R_direct_debit_order_soap_error.xml'), status=500 |
3437 | 3450 |
) |
3438 | 3451 |
url = get_endpoint('get-rl1-direct-debit-order') |
3439 | 3452 |
params = { |
3440 | 3453 |
'codeRegie': '12345', |
3441 | 3454 |
'dateRef': '2023-01-01', |
3442 | 3455 |
} |
3443 | 3456 | |
3444 | 3457 |
Link.objects.create(resource=con, family_id='1312', name_id='local') |
3445 |
resp = app.post_json(url + '?NameID=local', params=params)
|
|
3458 |
resp = app.get(url + '?NameID=local', params=params)
|
|
3446 | 3459 |
assert resp.json['err'] == 'Invoice-getDirectDebitOrder-soap:Server' |
3447 | 3460 |
assert resp.json['err_desc'] == "E520 : La REGIE CS [{0}] n''existe pas dans la base Maelis" |
3448 |
- |