0001-toulouse_axel-endpoint-to-pay-an-invoice-39005.patch
functests/toulouse_axel/test_toulouse_axel.py | ||
---|---|---|
4 | 4 | |
5 | 5 |
def test_link(conn, user): |
6 | 6 |
print("Get update management dates") |
7 |
url = conn + '/update_management_dates'
|
|
7 |
url = conn + '/management_dates' |
|
8 | 8 |
resp = requests.get(url) |
9 | 9 |
resp.raise_for_status() |
10 | 10 |
res = resp.json() |
... | ... | |
129 | 129 |
pprint.pprint(res) |
130 | 130 |
print('\n') |
131 | 131 | |
132 |
print("Get invoices") |
|
133 |
url = conn + '/invoices?NameID=%s' % name_id |
|
134 |
resp = requests.get(url) |
|
135 |
resp.raise_for_status() |
|
136 |
res = resp.json() |
|
137 |
assert res['err'] == 0 |
|
138 |
pprint.pprint(res) |
|
139 |
print('\n') |
|
140 | ||
141 |
data = res |
|
142 |
for invoice in data['data']: |
|
143 |
print("GET invoice info") |
|
144 |
url = conn + '/invoice/%s?NameID=%s' % (invoice['id'], name_id) |
|
145 |
resp = requests.get(url) |
|
146 |
resp.raise_for_status() |
|
147 |
res = resp.json() |
|
148 |
assert res['err'] == 0 |
|
149 |
pprint.pprint(res) |
|
150 |
print('\n') |
|
151 | ||
152 |
if res['data']['has_pdf']: |
|
153 |
print("GET invoice PDF") |
|
154 |
url = conn + '/invoice/%s/pdf?NameID=%s' % (invoice['id'], name_id) |
|
155 |
resp = requests.get(url) |
|
156 |
resp.raise_for_status() |
|
157 |
print('\n') |
|
158 | ||
159 | 132 |
print("Deleting link") |
160 | 133 |
url = conn + '/unlink?NameID=%s' % name_id |
161 | 134 |
resp = requests.post(url) |
passerelle/contrib/toulouse_axel/models.py | ||
---|---|---|
17 | 17 |
import base64 |
18 | 18 |
import copy |
19 | 19 |
import datetime |
20 |
import json |
|
20 | 21 |
import logging |
21 | 22 |
import os |
22 | 23 |
import re |
... | ... | |
249 | 250 |
ref_verif_dui = Operation('RefVerifDui') |
250 | 251 |
ref_famille_dui = Operation('RefFamilleDui') |
251 | 252 |
form_maj_famille_dui = Operation('FormMajFamilleDui') |
253 |
form_paiement_dui = Operation('FormPaiementDui') |
|
252 | 254 |
ref_facture_a_payer = Operation('RefFactureAPayer') |
253 | 255 |
ref_facture_pdf = Operation('RefFacturePDF', prefix='') |
254 | 256 | |
... | ... | |
724 | 726 |
} |
725 | 727 |
} |
726 | 728 | |
727 |
def get_invoices(self, name_id, error_status=200): |
|
729 |
def get_invoices(self, regie_id, name_id, error_status=200):
|
|
728 | 730 |
link = self.get_link(name_id, error_status=error_status) |
729 | 731 |
try: |
730 | 732 |
result = ref_facture_a_payer(self, {'PORTAIL': {'DUI': {'IDDUI': link.dui}}}) |
... | ... | |
738 | 740 |
data = result.json_response['DATA']['PORTAIL']['DUI'] |
739 | 741 |
result = [] |
740 | 742 |
for facture in data.get('FACTURES', []): |
743 |
if facture['IDREGIE'] != regie_id: |
|
744 |
continue |
|
741 | 745 |
result.append({ |
742 |
'id': facture['IDFACTURE'],
|
|
746 |
'id': str(facture['IDFACTURE']),
|
|
743 | 747 |
'label': facture['LIBELLE'], |
744 | 748 |
'amount': facture['RESTEAPAYER'], |
745 | 749 |
'total_amount': facture['MONTANTTOTAL'], |
... | ... | |
752 | 756 |
}) |
753 | 757 |
return result |
754 | 758 | |
755 |
def get_invoice(self, name_id, invoice_id, error_status=200): |
|
756 |
invoices_data = self.get_invoices(name_id, error_status=error_status) |
|
759 |
def get_invoice(self, regie_id, name_id, invoice_id, error_status=200):
|
|
760 |
invoices_data = self.get_invoices(regie_id, name_id, error_status=error_status)
|
|
757 | 761 |
for invoice in invoices_data: |
758 |
if str(invoice['id']) == invoice_id:
|
|
762 |
if invoice['id'] == invoice_id:
|
|
759 | 763 |
return invoice |
760 | 764 | |
761 | 765 |
@endpoint( |
762 |
description=_("Get invoices to pay"),
|
|
766 |
name='regie',
|
|
763 | 767 |
perm='can_access', |
768 |
pattern=r'^(?P<regie_id>[\w-]+)/invoices/?$', |
|
769 |
example_pattern='{regie_id}/invoices/', |
|
770 |
description=_("Get invoices to pay"), |
|
764 | 771 |
parameters={ |
765 | 772 |
'NameID': {'description': _('Publik ID')}, |
773 |
'regie_id': {'description': _('Regie identifier'), 'example_value': '42-PERISCOL'} |
|
766 | 774 |
}) |
767 |
def invoices(self, request, NameID): |
|
768 |
invoices_data = self.get_invoices(NameID) |
|
775 |
def invoices(self, request, regie_id, NameID):
|
|
776 |
invoices_data = self.get_invoices(regie_id, NameID)
|
|
769 | 777 |
return {'data': invoices_data} |
770 | 778 | |
771 | 779 |
@endpoint( |
780 |
name='regie', |
|
772 | 781 |
perm='can_access', |
773 |
pattern=r'^(?P<invoice_id>\w+)/?$', |
|
782 |
pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>\d+)/?$', |
|
783 |
example_pattern='{regie_id}/invoice/{invoice_id}/', |
|
774 | 784 |
description=_('Get invoice details'), |
775 | 785 |
parameters={ |
776 | 786 |
'NameID': {'description': _('Publik ID')}, |
777 |
'invoice_id': {'description': _('Invoice identifier')} |
|
787 |
'regie_id': {'description': _('Regie identifier'), 'example_value': '42-PERISCOL'}, |
|
788 |
'invoice_id': {'description': _('Invoice identifier'), 'example_value': '42'} |
|
778 | 789 |
}) |
779 |
def invoice(self, request, invoice_id, NameID): |
|
780 |
invoice = self.get_invoice(NameID, invoice_id) |
|
790 |
def invoice(self, request, regie_id, invoice_id, NameID):
|
|
791 |
invoice = self.get_invoice(regie_id, NameID, invoice_id)
|
|
781 | 792 |
if invoice is None: |
782 | 793 |
raise APIError('Invoice not found', err_code='not-found') |
783 | 794 | |
784 | 795 |
return {'data': invoice} |
785 | 796 | |
786 | 797 |
@endpoint( |
787 |
name='invoice',
|
|
798 |
name='regie',
|
|
788 | 799 |
perm='can_access', |
789 |
pattern=r'^(?P<invoice_id>\w+)/pdf/?$', |
|
800 |
pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>\d+)/pdf/?$', |
|
801 |
example_pattern='{regie_id}/invoice/{invoice_id}/pdf/', |
|
790 | 802 |
description=_('Get invoice as a PDF file'), |
791 | 803 |
parameters={ |
792 | 804 |
'NameID': {'description': _('Publik ID')}, |
793 |
'invoice_id': {'description': _('Invoice identifier')} |
|
805 |
'regie_id': {'description': _('Regie identifier'), 'example_value': '42-PERISCOL'}, |
|
806 |
'invoice_id': {'description': _('Invoice identifier'), 'example_value': '42'} |
|
794 | 807 |
}) |
795 |
def invoice_pdf(self, request, invoice_id, NameID): |
|
808 |
def invoice_pdf(self, request, regie_id, invoice_id, NameID):
|
|
796 | 809 |
# check that invoice is related to current user |
797 |
invoice = self.get_invoice(NameID, invoice_id, error_status=404) |
|
810 |
invoice = self.get_invoice(regie_id, NameID, invoice_id, error_status=404)
|
|
798 | 811 |
if invoice is None: |
799 | 812 |
raise APIError('Invoice not found', err_code='not-found', http_status=404) |
800 | 813 |
# check that PDF is available |
... | ... | |
819 | 832 |
response.write(b64content) |
820 | 833 |
return response |
821 | 834 | |
835 |
@endpoint( |
|
836 |
name='regie', |
|
837 |
methods=['post'], |
|
838 |
perm='can_access', |
|
839 |
pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>\d+)/pay/?$', |
|
840 |
example_pattern='{regie_id}/invoice/{invoice_id}/pay/', |
|
841 |
description=_('Notify an invoice as paid'), |
|
842 |
parameters={ |
|
843 |
'NameID': {'description': _('Publik ID')}, |
|
844 |
'regie_id': {'description': _('Regie identifier'), 'example_value': '42-PERISCOL'}, |
|
845 |
'invoice_id': {'description': _('Invoice identifier'), 'example_value': '42'} |
|
846 |
}) |
|
847 |
def pay_invoice(self, request, regie_id, invoice_id, NameID): |
|
848 |
# check that invoice is related to current user |
|
849 |
invoice = self.get_invoice(regie_id, NameID, invoice_id) |
|
850 |
if invoice is None: |
|
851 |
raise APIError('Invoice not found', err_code='not-found') |
|
852 | ||
853 |
data = json.loads(request.body) |
|
854 |
transaction_id = data.get('transaction_id') |
|
855 |
transaction_date = data.get('transaction_date') |
|
856 |
t_date = datetime.datetime.strptime(transaction_date, '%Y-%m-%dT%H:%M:%S') |
|
857 |
post_data = { |
|
858 |
'IDFACTURE': int(invoice_id), |
|
859 |
'IDREGIEENCAISSEMENT': '', |
|
860 |
'MONTANTPAYE': invoice['amount'], |
|
861 |
'DATEPAIEMENT': t_date.strftime('%d/%m/%Y %H:%M:%S'), |
|
862 |
'REFERENCE': transaction_id, |
|
863 |
} |
|
864 |
try: |
|
865 |
form_paiement_dui(self, {'PORTAIL': {'DUI': post_data}}) |
|
866 |
except AxelError as e: |
|
867 |
raise APIError( |
|
868 |
'Axel error: %s' % e, |
|
869 |
err_code='error', |
|
870 |
data={'xml_request': e.xml_request, |
|
871 |
'xml_response': e.xml_response}) |
|
872 |
return {'data': True} |
|
873 | ||
822 | 874 | |
823 | 875 |
class Link(models.Model): |
824 | 876 |
resource = models.ForeignKey(ToulouseAxel, on_delete=models.CASCADE) |
passerelle/contrib/toulouse_axel/xsd/Dui/Q_FormPaiementDui.xsd | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8" ?> |
|
2 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:all="urn:AllAxelTypes"> |
|
3 |
|
|
4 |
<xsd:import schemaLocation="../AllAxelTypes.xsd" namespace="urn:AllAxelTypes" /> |
|
5 |
|
|
6 |
<xsd:complexType name="DUIType"> |
|
7 |
<xsd:sequence> |
|
8 |
<xsd:element ref="IDFACTURE" /> |
|
9 |
<xsd:element ref="IDREGIEENCAISSEMENT"/> |
|
10 |
<xsd:element ref="MONTANTPAYE"/> |
|
11 |
<xsd:element ref="DATEPAIEMENT"/> |
|
12 |
<xsd:element ref="REFERENCE"/> |
|
13 |
</xsd:sequence> |
|
14 |
</xsd:complexType> |
|
15 |
|
|
16 |
<xsd:complexType name="PORTAILType"> |
|
17 |
<xsd:sequence> |
|
18 |
<xsd:element ref="DUI"/> |
|
19 |
</xsd:sequence> |
|
20 |
</xsd:complexType> |
|
21 |
|
|
22 |
<xsd:simpleType name="CHOIXType"> |
|
23 |
<xsd:restriction base="xsd:string"> |
|
24 |
<xsd:enumeration value="1" /> |
|
25 |
<xsd:enumeration value="0" /> |
|
26 |
</xsd:restriction> |
|
27 |
</xsd:simpleType> |
|
28 |
|
|
29 |
<xsd:simpleType name="IDENTREGIEType"> |
|
30 |
<xsd:restriction base="xsd:string"> |
|
31 |
<xsd:maxLength value="10" /> |
|
32 |
</xsd:restriction> |
|
33 |
</xsd:simpleType> |
|
34 |
|
|
35 |
<xsd:element name="IDFACTURE" type="xsd:unsignedInt"/> |
|
36 |
<xsd:element name="IDREGIEENCAISSEMENT" type="IDENTREGIEType"/> |
|
37 |
<xsd:element name="MONTANTPAYE" type="all:MONTANTREQUIREDType"/> |
|
38 |
<xsd:element name="DATEPAIEMENT" type="all:DATETIMEType"/> |
|
39 |
<xsd:element name="REFERENCE" type="xsd:string"/> |
|
40 |
|
|
41 |
<xsd:element name="DUI" type="DUIType"/> |
|
42 |
|
|
43 |
<xsd:element name="PORTAIL" type="PORTAILType"/> |
|
44 |
</xsd:schema> |
passerelle/contrib/toulouse_axel/xsd/Dui/R_FormPaiementDui.xsd | ||
---|---|---|
1 |
<?xml version="1.0" encoding="utf-8" ?> |
|
2 |
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:all="urn:AllAxelTypes"> |
|
3 |
|
|
4 |
<xsd:import schemaLocation="../AllAxelTypes.xsd" namespace="urn:AllAxelTypes" /> |
|
5 |
|
|
6 |
<xsd:redefine schemaLocation="../R_ShemaResultat.xsd"> |
|
7 |
<xsd:simpleType name="TYPEType"> |
|
8 |
<xsd:restriction base="TYPEType"> |
|
9 |
<xsd:enumeration value="FormPaiementDui" /> |
|
10 |
</xsd:restriction> |
|
11 |
</xsd:simpleType> |
|
12 |
|
|
13 |
<xsd:complexType name="PORTAILType"> |
|
14 |
<xsd:complexContent> |
|
15 |
<xsd:extension base="PORTAILType"> |
|
16 |
<xsd:sequence> |
|
17 |
<xsd:element ref="DUI" minOccurs="0"/> |
|
18 |
</xsd:sequence> |
|
19 |
</xsd:extension> |
|
20 |
</xsd:complexContent> |
|
21 |
</xsd:complexType> |
|
22 |
</xsd:redefine> |
|
23 |
|
|
24 |
<xsd:complexType name="DUIType"> |
|
25 |
<xsd:sequence> |
|
26 |
<xsd:element ref="IDDUI" /> |
|
27 |
<xsd:element ref="CODE" /> |
|
28 |
</xsd:sequence> |
|
29 |
</xsd:complexType> |
|
30 |
|
|
31 |
<xsd:element name="CODE" type="all:unsignedInt-or-empty"/> |
|
32 |
<xsd:element name="IDDUI" type="all:IDENTType"/> |
|
33 |
|
|
34 |
<xsd:element name="DUI" type="DUIType" /> |
|
35 |
|
|
36 |
</xsd:schema> |
tests/data/toulouse_axel/invoices.xml | ||
---|---|---|
27 | 27 |
<EXISTEPDF>0</EXISTEPDF> |
28 | 28 |
<IDFACTURE>43</IDFACTURE> |
29 | 29 |
</FACTURES> |
30 |
<FACTURES> |
|
31 |
<NUMFACTURE>44</NUMFACTURE> |
|
32 |
<DATEEMISSION>12/01/2020</DATEEMISSION> |
|
33 |
<DATEECHEANCE>04/02/2020</DATEECHEANCE> |
|
34 |
<LIBELLE>PRESTATIONS PERISCOLAIRES DECEMBRE 2019</LIBELLE> |
|
35 |
<IDFACTURATION>4244-35AA</IDFACTURATION> |
|
36 |
<MONTANTTOTAL>44.94</MONTANTTOTAL> |
|
37 |
<RESTEAPAYER>44.94</RESTEAPAYER> |
|
38 |
<IDREGIE>AUTREREGIE</IDREGIE> |
|
39 |
<EXISTEPDF>1</EXISTEPDF> |
|
40 |
<IDFACTURE>44</IDFACTURE> |
|
41 |
</FACTURES> |
|
30 | 42 |
</DUI> |
31 | 43 |
</PORTAIL> |
tests/test_toulouse_axel.py | ||
---|---|---|
17 | 17 |
from contextlib import contextmanager |
18 | 18 |
import copy |
19 | 19 |
import datetime |
20 |
import decimal |
|
20 | 21 |
import json |
21 | 22 |
import mock |
22 | 23 |
import os |
... | ... | |
32 | 33 |
OperationResult, |
33 | 34 |
ToulouseAxel, |
34 | 35 |
form_maj_famille_dui, |
36 |
form_paiement_dui, |
|
35 | 37 |
ref_date_gestion_dui, |
36 | 38 |
ref_famille_dui, |
37 | 39 |
ref_facture_a_payer, |
... | ... | |
327 | 329 |
}) |
328 | 330 | |
329 | 331 | |
332 |
@pytest.mark.parametrize('content', [ |
|
333 |
'<PORTAIL><DUI/></PORTAIL>', |
|
334 |
]) |
|
335 |
def test_operation_form_paiement_dui(resource, content): |
|
336 |
with mock_getdata(content, 'FormPaiementDui'): |
|
337 |
with pytest.raises(AxelError): |
|
338 |
form_paiement_dui(resource, { |
|
339 |
'PORTAIL': { |
|
340 |
'DUI': { |
|
341 |
'IDFACTURE': '42', |
|
342 |
'IDREGIEENCAISSEMENT': '', |
|
343 |
'MONTANTPAYE': '42.42', |
|
344 |
'DATEPAIEMENT': '01/01/2020 12:12:12', |
|
345 |
'REFERENCE': '42', |
|
346 |
} |
|
347 |
} |
|
348 |
}) |
|
349 | ||
350 | ||
330 | 351 |
def test_management_dates_endpoint_axel_error(app, resource): |
331 | 352 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_date_gestion_dui') as operation: |
332 | 353 |
operation.side_effect = AxelError('FooBar') |
... | ... | |
1195 | 1216 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
1196 | 1217 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_facture_a_payer') as operation: |
1197 | 1218 |
operation.side_effect = AxelError('FooBar') |
1198 |
resp = app.get('/toulouse-axel/test/invoices?NameID=yyy') |
|
1219 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices?NameID=yyy')
|
|
1199 | 1220 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
1200 | 1221 |
assert resp.json['err'] == 'error' |
1201 | 1222 | |
1202 | 1223 | |
1203 | 1224 |
def test_invoices_endpoint_no_result(app, resource): |
1204 |
resp = app.get('/toulouse-axel/test/invoices?NameID=yyy') |
|
1225 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices?NameID=yyy')
|
|
1205 | 1226 |
assert resp.json['err_desc'] == "Person not found" |
1206 | 1227 |
assert resp.json['err'] == 'not-found' |
1207 | 1228 | |
... | ... | |
1216 | 1237 |
</DUI> |
1217 | 1238 |
</PORTAIL>''' |
1218 | 1239 |
with mock_getdata(content, 'RefFactureAPayer'): |
1219 |
resp = app.get('/toulouse-axel/test/invoices?NameID=yyy') |
|
1240 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices?NameID=yyy')
|
|
1220 | 1241 |
assert resp.json['err'] == 0 |
1221 | 1242 |
assert resp.json['data'] == [] |
1222 | 1243 | |
... | ... | |
1227 | 1248 |
with open(filepath) as xml: |
1228 | 1249 |
content = xml.read() |
1229 | 1250 |
with mock_getdata(content, 'RefFactureAPayer'): |
1230 |
resp = app.get('/toulouse-axel/test/invoices?NameID=yyy') |
|
1251 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices?NameID=yyy')
|
|
1231 | 1252 |
assert resp.json['err'] == 0 |
1232 | 1253 |
assert resp.json['data'] == [ |
1233 | 1254 |
{ |
1234 |
'id': 42,
|
|
1255 |
'id': '42',
|
|
1235 | 1256 |
'label': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019', |
1236 | 1257 |
'amount': '44.94', |
1237 | 1258 |
'total_amount': '44.94', |
... | ... | |
1256 | 1277 |
} |
1257 | 1278 |
}, |
1258 | 1279 |
{ |
1259 |
'id': 43,
|
|
1280 |
'id': '43',
|
|
1260 | 1281 |
'label': 'PRESTATIONS PERISCOLAIRES NOVEMBRE 2019', |
1261 | 1282 |
'amount': '44.94', |
1262 | 1283 |
'total_amount': '44.94', |
... | ... | |
1281 | 1302 |
} |
1282 | 1303 |
} |
1283 | 1304 |
] |
1305 |
with mock_getdata(content, 'RefFactureAPayer'): |
|
1306 |
resp = app.get('/toulouse-axel/test/regie/AUTREREGIE/invoices?NameID=yyy') |
|
1307 |
assert resp.json['err'] == 0 |
|
1308 |
assert resp.json['data'] == [ |
|
1309 |
{ |
|
1310 |
'id': '44', |
|
1311 |
'label': 'PRESTATIONS PERISCOLAIRES DECEMBRE 2019', |
|
1312 |
'amount': '44.94', |
|
1313 |
'total_amount': '44.94', |
|
1314 |
'online_payment': True, |
|
1315 |
'created': '2020-01-12', |
|
1316 |
'pay_limit_date': '2020-02-04', |
|
1317 |
'has_pdf': True, |
|
1318 |
'paid': False, |
|
1319 |
'vendor': { |
|
1320 |
'toulouse-axel': { |
|
1321 |
'IDFACTURATION': '4244-35AA', |
|
1322 |
'IDFACTURE': 44, |
|
1323 |
'IDREGIE': 'AUTREREGIE', |
|
1324 |
'DATEECHEANCE': '2020-02-04', |
|
1325 |
'DATEEMISSION': '2020-01-12', |
|
1326 |
'EXISTEPDF': '1', |
|
1327 |
'LIBELLE': 'PRESTATIONS PERISCOLAIRES DECEMBRE 2019', |
|
1328 |
'MONTANTTOTAL': '44.94', |
|
1329 |
'NUMFACTURE': 44, |
|
1330 |
'RESTEAPAYER': '44.94', |
|
1331 |
} |
|
1332 |
} |
|
1333 |
} |
|
1334 |
] |
|
1284 | 1335 | |
1285 | 1336 | |
1286 | 1337 |
def test_invoice_endpoint_axel_error(app, resource): |
1287 | 1338 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
1288 | 1339 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_facture_a_payer') as operation: |
1289 | 1340 |
operation.side_effect = AxelError('FooBar') |
1290 |
resp = app.get('/toulouse-axel/test/invoice/42?NameID=yyy') |
|
1341 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42?NameID=yyy')
|
|
1291 | 1342 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
1292 | 1343 |
assert resp.json['err'] == 'error' |
1293 | 1344 | |
1294 | 1345 | |
1295 | 1346 |
def test_invoice_endpoint_no_result(app, resource): |
1296 |
resp = app.get('/toulouse-axel/test/invoice/42?NameID=yyy') |
|
1347 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42?NameID=yyy')
|
|
1297 | 1348 |
assert resp.json['err_desc'] == "Person not found" |
1298 | 1349 |
assert resp.json['err'] == 'not-found' |
1299 | 1350 | |
... | ... | |
1302 | 1353 |
with open(filepath) as xml: |
1303 | 1354 |
content = xml.read() |
1304 | 1355 |
with mock_getdata(content, 'RefFactureAPayer'): |
1305 |
resp = app.get('/toulouse-axel/test/invoice/35?NameID=yyy') |
|
1356 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/35?NameID=yyy') |
|
1357 |
assert resp.json['err_desc'] == "Invoice not found" |
|
1358 |
assert resp.json['err'] == 'not-found' |
|
1359 |
with mock_getdata(content, 'RefFactureAPayer'): |
|
1360 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/44?NameID=yyy') |
|
1306 | 1361 |
assert resp.json['err_desc'] == "Invoice not found" |
1307 | 1362 |
assert resp.json['err'] == 'not-found' |
1308 | 1363 | |
... | ... | |
1313 | 1368 |
with open(filepath) as xml: |
1314 | 1369 |
content = xml.read() |
1315 | 1370 |
with mock_getdata(content, 'RefFactureAPayer'): |
1316 |
resp = app.get('/toulouse-axel/test/invoice/42?NameID=yyy') |
|
1371 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42?NameID=yyy')
|
|
1317 | 1372 |
assert resp.json['err'] == 0 |
1318 | 1373 |
assert resp.json['data'] == { |
1319 |
'id': 42,
|
|
1374 |
'id': '42',
|
|
1320 | 1375 |
'label': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019', |
1321 | 1376 |
'amount': '44.94', |
1322 | 1377 |
'total_amount': '44.94', |
... | ... | |
1346 | 1401 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
1347 | 1402 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_facture_a_payer') as operation: |
1348 | 1403 |
operation.side_effect = AxelError('FooBar') |
1349 |
resp = app.get('/toulouse-axel/test/invoice/42/pdf?NameID=yyy', status=404) |
|
1404 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42/pdf?NameID=yyy', status=404)
|
|
1350 | 1405 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
1351 | 1406 |
assert resp.json['err'] == 'error' |
1352 | 1407 | |
... | ... | |
1356 | 1411 |
with mock_getdata(content, 'RefFactureAPayer'): |
1357 | 1412 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_facture_pdf') as operation: |
1358 | 1413 |
operation.side_effect = AxelError('FooBar') |
1359 |
resp = app.get('/toulouse-axel/test/invoice/42/pdf?NameID=yyy', status=404) |
|
1414 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42/pdf?NameID=yyy', status=404)
|
|
1360 | 1415 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
1361 | 1416 |
assert resp.json['err'] == 'error' |
1362 | 1417 | |
1363 | 1418 | |
1364 | 1419 |
def test_invoice_pdf_endpoint_no_result(app, resource): |
1365 |
resp = app.get('/toulouse-axel/test/invoice/42/pdf?NameID=yyy', status=404) |
|
1420 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42/pdf?NameID=yyy', status=404)
|
|
1366 | 1421 |
assert resp.json['err_desc'] == "Person not found" |
1367 | 1422 |
assert resp.json['err'] == 'not-found' |
1368 | 1423 | |
... | ... | |
1371 | 1426 |
with open(filepath) as xml: |
1372 | 1427 |
content = xml.read() |
1373 | 1428 |
with mock_getdata(content, 'RefFactureAPayer'): |
1374 |
resp = app.get('/toulouse-axel/test/invoice/35/pdf?NameID=yyy', status=404) |
|
1429 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/35/pdf?NameID=yyy', status=404) |
|
1430 |
assert resp.json['err_desc'] == "Invoice not found" |
|
1431 |
assert resp.json['err'] == 'not-found' |
|
1432 | ||
1433 |
with mock_getdata(content, 'RefFactureAPayer'): |
|
1434 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/44/pdf?NameID=yyy', status=404) |
|
1375 | 1435 |
assert resp.json['err_desc'] == "Invoice not found" |
1376 | 1436 |
assert resp.json['err'] == 'not-found' |
1377 | 1437 | |
1378 | 1438 |
with mock_getdata(content, 'RefFactureAPayer'): |
1379 |
resp = app.get('/toulouse-axel/test/invoice/43/pdf?NameID=yyy', status=404) |
|
1439 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/43/pdf?NameID=yyy', status=404)
|
|
1380 | 1440 |
assert resp.json['err_desc'] == "PDF not available" |
1381 | 1441 |
assert resp.json['err'] == 'not-available' |
1382 | 1442 | |
... | ... | |
1386 | 1446 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_invoice') as invoice: |
1387 | 1447 |
invoice.return_value = {'has_pdf': True} |
1388 | 1448 |
with mock_getdata(pdf_content, 'RefFacturePDF'): |
1389 |
resp = app.get('/toulouse-axel/test/invoice/42/pdf?NameID=yyy', status=404) |
|
1449 |
resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42/pdf?NameID=yyy', status=404)
|
|
1390 | 1450 |
assert resp.json['err_desc'] == "PDF error" |
1391 | 1451 |
assert resp.json['err'] == 'error' |
1392 | 1452 | |
... | ... | |
1399 | 1459 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_invoice') as invoice: |
1400 | 1460 |
invoice.return_value = {'has_pdf': True} |
1401 | 1461 |
with mock_getdata(pdf_content, 'RefFacturePDF'): |
1402 |
app.get('/toulouse-axel/test/invoice/42/pdf?NameID=yyy') |
|
1462 |
app.get('/toulouse-axel/test/regie/MAREGIE/invoice/42/pdf?NameID=yyy') |
|
1463 | ||
1464 | ||
1465 |
def test_pay_invoice_endpoint_axel_error(app, resource): |
|
1466 |
payload = { |
|
1467 |
'transaction_date': '2020-01-01T12:00:00', |
|
1468 |
'transaction_id': 'foo', |
|
1469 |
} |
|
1470 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
1471 |
with mock.patch('passerelle.contrib.toulouse_axel.models.ref_facture_a_payer') as operation: |
|
1472 |
operation.side_effect = AxelError('FooBar') |
|
1473 |
resp = app.post_json('/toulouse-axel/test/regie/MAREGIE/invoice/42/pay?NameID=yyy', params=payload) |
|
1474 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
|
1475 |
assert resp.json['err'] == 'error' |
|
1476 | ||
1477 |
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices.xml') |
|
1478 |
with open(filepath) as xml: |
|
1479 |
content = xml.read() |
|
1480 |
with mock_getdata(content, 'RefFactureAPayer'): |
|
1481 |
with mock.patch('passerelle.contrib.toulouse_axel.models.form_paiement_dui') as operation: |
|
1482 |
operation.side_effect = AxelError('FooBar') |
|
1483 |
resp = app.post_json('/toulouse-axel/test/regie/MAREGIE/invoice/42/pay?NameID=yyy', params=payload) |
|
1484 |
assert resp.json['err_desc'] == "Axel error: FooBar" |
|
1485 |
assert resp.json['err'] == 'error' |
|
1486 | ||
1487 | ||
1488 |
def test_pay_invoice_endpoint_no_result(app, resource): |
|
1489 |
payload = { |
|
1490 |
'transaction_date': '2020-01-01T12:00:00', |
|
1491 |
'transaction_id': 'foo', |
|
1492 |
} |
|
1493 |
resp = app.post_json('/toulouse-axel/test/regie/MAREGIE/invoice/42/pay?NameID=yyy', params=payload) |
|
1494 |
assert resp.json['err_desc'] == "Person not found" |
|
1495 |
assert resp.json['err'] == 'not-found' |
|
1496 | ||
1497 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
1498 |
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices.xml') |
|
1499 |
with open(filepath) as xml: |
|
1500 |
content = xml.read() |
|
1501 |
with mock_getdata(content, 'RefFactureAPayer'): |
|
1502 |
resp = app.post_json('/toulouse-axel/test/regie/MAREGIE/invoice/35/pay?NameID=yyy', params=payload) |
|
1503 |
assert resp.json['err_desc'] == "Invoice not found" |
|
1504 |
assert resp.json['err'] == 'not-found' |
|
1505 |
with mock_getdata(content, 'RefFactureAPayer'): |
|
1506 |
resp = app.post_json('/toulouse-axel/test/regie/MAREGIE/invoice/44/pay?NameID=yyy', params=payload) |
|
1507 |
assert resp.json['err_desc'] == "Invoice not found" |
|
1508 |
assert resp.json['err'] == 'not-found' |
|
1509 | ||
1510 | ||
1511 |
def test_pay_invoice_endpoint(app, resource): |
|
1512 |
payload = { |
|
1513 |
'transaction_date': '2020-01-01T12:00:00', |
|
1514 |
'transaction_id': 'foo', |
|
1515 |
} |
|
1516 |
Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42') |
|
1517 |
filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices.xml') |
|
1518 |
with open(filepath) as xml: |
|
1519 |
content = xml.read() |
|
1520 |
with mock_getdata(content, 'RefFactureAPayer'): |
|
1521 |
with mock.patch('passerelle.contrib.toulouse_axel.models.form_paiement_dui') as operation: |
|
1522 |
resp = app.post_json('/toulouse-axel/test/regie/MAREGIE/invoice/42/pay?NameID=yyy', params=payload) |
|
1523 |
assert resp.json['err'] == 0 |
|
1524 |
assert resp.json['data'] is True |
|
1525 |
assert operation.call_args_list[0][0][1] == { |
|
1526 |
'PORTAIL': { |
|
1527 |
'DUI': { |
|
1528 |
'DATEPAIEMENT': '01/01/2020 12:00:00', |
|
1529 |
'IDFACTURE': 42, |
|
1530 |
'IDREGIEENCAISSEMENT': '', |
|
1531 |
'MONTANTPAYE': decimal.Decimal('44.94'), |
|
1532 |
'REFERENCE': 'foo', |
|
1533 |
} |
|
1534 |
} |
|
1535 |
} |
|
1403 |
- |