Projet

Général

Profil

0002-toulouse_axel-invoice-history-39028.patch

Lauréline Guérin, 20 janvier 2020 16:37

Télécharger (23 ko)

Voir les différences:

Subject: [PATCH 2/2] toulouse_axel: invoice history (#39028)

 passerelle/contrib/toulouse_axel/models.py    |  90 ++++++++--
 .../Dui/Q_ListeDuiFacturesPayeesRecettees.xsd |  18 ++
 .../Dui/R_ListeDuiFacturesPayeesRecettees.xsd |  95 ++++++++++
 tests/data/toulouse_axel/invoices_history.xml |  35 ++++
 tests/test_toulouse_axel.py                   | 168 +++++++++++++++++-
 5 files changed, 391 insertions(+), 15 deletions(-)
 create mode 100644 passerelle/contrib/toulouse_axel/xsd/Dui/Q_ListeDuiFacturesPayeesRecettees.xsd
 create mode 100644 passerelle/contrib/toulouse_axel/xsd/Dui/R_ListeDuiFacturesPayeesRecettees.xsd
 create mode 100644 tests/data/toulouse_axel/invoices_history.xml
passerelle/contrib/toulouse_axel/models.py
210 210

  
211 211

  
212 212
class Operation(object):
213
    def __init__(self, operation, prefix='Dui/'):
213
    def __init__(self, operation, prefix='Dui/', request_root_element='PORTAIL'):
214 214
        self.operation = operation
215
        self.request_converter = xml_schema_converter('%sQ_%s.xsd' % (prefix, operation), 'PORTAIL')
215
        self.request_converter = xml_schema_converter('%sQ_%s.xsd' % (prefix, operation), request_root_element)
216 216
        self.response_converter = xml_schema_converter('%sR_%s.xsd' % (prefix, operation), 'PORTAILSERVICE')
217 217
        self.name = re.sub(
218 218
            '(.?)([A-Z])',
......
280 280
form_paiement_dui = Operation('FormPaiementDui')
281 281
ref_facture_a_payer = Operation('RefFactureAPayer')
282 282
ref_facture_pdf = Operation('RefFacturePDF', prefix='')
283
list_dui_factures = Operation('ListeDuiFacturesPayeesRecettees', request_root_element='LISTFACTURE')
283 284

  
284 285

  
285 286
class ToulouseAxel(BaseResource):
......
753 754
            }
754 755
        }
755 756

  
756
    def normalize_invoice(self, invoice, dui):
757
    def normalize_invoice(self, invoice, dui, historical=False, vendor_base=None):
758
        vendor = invoice
759
        vendor.update(vendor_base or {})
757 760
        invoice_id = '%s-%s' % (dui, invoice['IDFACTURE'])
758 761
        data = {
759 762
            'id': invoice_id,
760 763
            'display_id': str(invoice['IDFACTURE']),
761 764
            'label': invoice['LIBELLE'],
762
            'amount': invoice['RESTEAPAYER'],
763
            'total_amount': invoice['MONTANTTOTAL'],
764
            'created': invoice['DATEEMISSION'],
765
            'pay_limit_date': invoice['DATEECHEANCE'],
766
            'has_pdf': True if invoice['EXISTEPDF'] == '1' else False,
767 765
            'paid': False,
768
            'vendor': {'toulouse-axel': invoice},
766
            'vendor': {'toulouse-axel': vendor},
769 767
        }
770
        pay_limit_date = datetime.datetime.strptime(invoice['DATEECHEANCE'], '%Y-%m-%d').date()
771
        data['online_payment'] = data['amount'] > 0 and pay_limit_date >= datetime.date.today()
768
        if historical:
769
            data.update({
770
                'amount': 0,
771
                'total_amount': invoice['MONTANT'],
772
                'created': invoice['EMISSION'],
773
                'pay_limit_date': '',
774
                'online_payment': False,
775
                'has_pdf': True if invoice['IPDF'] == '1' else False,
776
            })
777
        else:
778
            data.update({
779
                'amount': invoice['RESTEAPAYER'],
780
                'total_amount': invoice['MONTANTTOTAL'],
781
                'created': invoice['DATEEMISSION'],
782
                'pay_limit_date': invoice['DATEECHEANCE'],
783
                'has_pdf': True if invoice['EXISTEPDF'] == '1' else False,
784
            })
785
            pay_limit_date = datetime.datetime.strptime(invoice['DATEECHEANCE'], '%Y-%m-%d').date()
786
            data['online_payment'] = data['amount'] > 0 and pay_limit_date >= datetime.date.today()
772 787
        return data
773 788

  
774 789
    def get_invoices(self, regie_id, dui=None, name_id=None):
......
793 808
            result.append(self.normalize_invoice(facture, dui))
794 809
        return result
795 810

  
811
    def get_historical_invoices(self, name_id):
812
        link = self.get_link(name_id)
813
        try:
814
            result = list_dui_factures(
815
                self,
816
                {'LISTFACTURE': {'NUMDUI': link.dui, 'DEBUT': '1970-01-01'}})
817
        except AxelError as e:
818
            raise APIError(
819
                'Axel error: %s' % e,
820
                err_code='error',
821
                data={'xml_request': e.xml_request,
822
                      'xml_response': e.xml_response})
823

  
824
        data = result.json_response['DATA']['PORTAIL']['LISTFACTURE']
825
        result = []
826
        for direction in data.get('DIRECTION', []):
827
            for facture in direction.get('FACTURE', []):
828
                result.append(
829
                    self.normalize_invoice(
830
                        facture,
831
                        link.dui,
832
                        historical=True,
833
                        vendor_base={
834
                            'NUMDIRECTION': direction['NUMDIRECTION'],
835
                            'IDDIRECTION': direction['IDDIRECTION'],
836
                            'LIBDIRECTION': direction['LIBDIRECTION'],
837
                        }))
838
        return result
839

  
796 840
    def get_invoice(self, regie_id, invoice_id, dui=None, name_id=None):
797 841
        invoices_data = self.get_invoices(regie_id=regie_id, dui=dui, name_id=name_id)
798 842
        for invoice in invoices_data:
799 843
            if invoice['display_id'] == invoice_id:
800 844
                return invoice
801 845

  
846
    def get_historical_invoice(self, invoice_id, name_id):
847
        invoices_data = self.get_historical_invoices(name_id=name_id)
848
        for invoice in invoices_data:
849
            if invoice['display_id'] == invoice_id:
850
                return invoice
851

  
802 852
    @endpoint(
803 853
        name='regie',
804 854
        perm='can_access',
......
813 863
        invoices_data = self.get_invoices(regie_id=regie_id, name_id=NameID)
814 864
        return {'data': invoices_data}
815 865

  
866
    @endpoint(
867
        name='regie',
868
        perm='can_access',
869
        pattern=r'^(?P<regie_id>[\w-]+)/invoices/history/?$',
870
        example_pattern='{regie_id}/invoices/history/',
871
        description=_("Get invoices already paid"),
872
        parameters={
873
            'NameID': {'description': _('Publik ID')},
874
            'regie_id': {'description': _('Regie identifier'), 'example_value': '42-PERISCOL'}
875
        })
876
    def invoices_history(self, request, regie_id, NameID):
877
        invoices_data = self.get_historical_invoices(name_id=NameID)
878
        return {'data': invoices_data}
879

  
816 880
    @endpoint(
817 881
        name='regie',
818 882
        perm='can_access',
......
827 891
    def invoice(self, request, regie_id, invoice_id, NameID):
828 892
        invoice_id = invoice_id.split('-')[1]
829 893
        invoice = self.get_invoice(regie_id=regie_id, name_id=NameID, invoice_id=invoice_id)
894
        if invoice is None:
895
            invoice = self.get_historical_invoice(name_id=NameID, invoice_id=invoice_id)
830 896
        if invoice is None:
831 897
            raise APIError('Invoice not found', err_code='not-found')
832 898

  
......
848 914
        invoice_id = invoice_id.split('-')[1]
849 915
        try:
850 916
            invoice = self.get_invoice(regie_id=regie_id, name_id=NameID, invoice_id=invoice_id)
917
            if invoice is None:
918
                invoice = self.get_historical_invoice(name_id=NameID, invoice_id=invoice_id)
851 919
        except APIError as e:
852 920
            e.http_status = 404
853 921
            raise
passerelle/contrib/toulouse_axel/xsd/Dui/Q_ListeDuiFacturesPayeesRecettees.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="listefacture">
7
		<xsd:all>
8
			<xsd:element ref="NUMDUI" minOccurs="1" maxOccurs="1"/>
9
			<xsd:element ref="DEBUT" minOccurs="1" maxOccurs="1"/>
10
		</xsd:all> 
11
	</xsd:complexType>
12
	
13
	<xsd:element name="DEBUT" type="all:DATEREQUIREDType"/>
14
	<xsd:element name="NUMDUI" type="all:IDENTREQUIREDType"/>
15
	
16
	<xsd:element name="LISTFACTURE" type="listefacture"/>	
17
		
18
</xsd:schema>
passerelle/contrib/toulouse_axel/xsd/Dui/R_ListeDuiFacturesPayeesRecettees.xsd
1
<?xml version="1.0" encoding="utf-8" ?>
2
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
3
	xmlns:all="urn:AllAxelTypes">
4

  
5
	<xsd:import schemaLocation="../AllAxelTypes.xsd" namespace="urn:AllAxelTypes" />
6

  
7
	<xsd:redefine schemaLocation="../R_ShemaResultat.xsd">
8
		<xsd:simpleType name="TYPEType">
9
			<xsd:restriction base="TYPEType">
10
				<xsd:enumeration value="ListeDuiFacturesPayeesRecettees" />
11
			</xsd:restriction>
12
		</xsd:simpleType>
13

  
14
		<xsd:complexType name="PORTAILType">
15
			<xsd:complexContent>
16
				<xsd:extension base="PORTAILType">
17
					<xsd:sequence>
18
						<xsd:element ref="LISTFACTURE" minOccurs="0"
19
							maxOccurs="1" />
20
					</xsd:sequence>
21
				</xsd:extension>
22
			</xsd:complexContent>
23
		</xsd:complexType>
24
	</xsd:redefine>
25

  
26
	<xsd:complexType name="listfacture">
27
		<xsd:sequence>
28
			<xsd:element ref="NBFACTURERESTANTE" />
29
			<xsd:element ref="DIRECTION" minOccurs="0" maxOccurs="unbounded" />
30
		</xsd:sequence>
31
	</xsd:complexType>
32
	
33
	<xsd:complexType name="direction">
34
		<xsd:sequence>
35
			<xsd:element ref="NUMDIRECTION" />
36
			<xsd:element ref="IDDIRECTION" />
37
			<xsd:element ref="LIBDIRECTION" />
38
			<xsd:element ref="FACTURE" minOccurs="0" maxOccurs="unbounded" />
39
		</xsd:sequence>
40
	</xsd:complexType>
41

  
42
	<xsd:complexType name="facture">
43
		<xsd:sequence>
44
			<xsd:element ref="IDAXEL" />
45
			<xsd:element ref="IDFAMILLE" />
46
			<xsd:element ref="EMISSION" />
47
			<xsd:element ref="MONTANT" />
48
			<xsd:element ref="IDFACTURE" />
49
			<xsd:element ref="NOFACTURE" />
50
			<xsd:element ref="LIBELLE" />
51
			<xsd:element ref="IPDF" />
52
		</xsd:sequence>
53
	</xsd:complexType>
54

  
55
	<xsd:simpleType name="idaxel">
56
		<xsd:restriction base="xsd:string">
57
			<xsd:pattern value="AXEL" />
58
		</xsd:restriction>
59
	</xsd:simpleType>
60

  
61
	<xsd:simpleType name="libelle">
62
		<xsd:restriction base="xsd:string">
63
			<xsd:minLength value="1" />
64
			<xsd:maxLength value="50" />
65
		</xsd:restriction>
66
	</xsd:simpleType>
67

  
68

  
69
	<xsd:simpleType name="positiveInteger" id="positiveInteger">
70
		<xsd:restriction base="xsd:nonNegativeInteger">
71
			<xsd:minInclusive value="0" />
72
		</xsd:restriction>
73
	</xsd:simpleType>
74

  
75
	<xsd:element name="NUMDIRECTION" type="xsd:nonNegativeInteger" />
76
	<xsd:element name="IDDIRECTION" type="all:IDREQUIREDType" />
77
	<xsd:element name="LIBDIRECTION" type="all:NOMREQUIREDType" />
78
	
79
	<xsd:element name="IDAXEL" type="idaxel" />
80
	<xsd:element name="IDFAMILLE" type="all:IDENTREQUIREDType" />
81
	<xsd:element name="EMISSION" type="all:DATEREQUIREDType" />
82
	<xsd:element name="MONTANT" type="xsd:decimal" />
83
	<xsd:element name="IDFACTURE" type="xsd:positiveInteger" />
84
	<xsd:element name="NOFACTURE" type="xsd:positiveInteger" />
85
	<xsd:element name="LIBELLE" type="libelle" />
86
	<xsd:element name="IPDF" type="all:ONType" />
87
	<xsd:element name="NBFACTURERESTANTE" type="positiveInteger" />
88

  
89
	<xsd:element name="DIRECTION" type="direction" />
90
	<xsd:element name="FACTURE" type="facture" />
91
	<xsd:element name="LISTFACTURE" type="listfacture" />
92
	
93
</xsd:schema>
94

  
95

  
tests/data/toulouse_axel/invoices_history.xml
1
<PORTAIL>
2
  <LISTFACTURE>
3
    <NBFACTURERESTANTE>0</NBFACTURERESTANTE>
4
    <DIRECTION>
5
      <NUMDIRECTION>10</NUMDIRECTION>
6
      <IDDIRECTION>DIR-A</IDDIRECTION>
7
      <LIBDIRECTION>DIRECTION A</LIBDIRECTION>
8
      <FACTURE>
9
        <IDAXEL>AXEL</IDAXEL>
10
        <IDFAMILLE>XXX</IDFAMILLE>
11
        <EMISSION>23/03/2017</EMISSION>
12
        <MONTANT>28.98</MONTANT>
13
        <IDFACTURE>42</IDFACTURE>
14
        <NOFACTURE>42</NOFACTURE>
15
        <LIBELLE>PRESTATIONS SEPTEMBRE 2015</LIBELLE>
16
        <IPDF>O</IPDF>
17
      </FACTURE>
18
    </DIRECTION>
19
    <DIRECTION>
20
      <NUMDIRECTION>11</NUMDIRECTION>
21
      <IDDIRECTION>DIR-B</IDDIRECTION>
22
      <LIBDIRECTION>DIRECTION B</LIBDIRECTION>
23
      <FACTURE>
24
        <IDAXEL>AXEL</IDAXEL>
25
        <IDFAMILLE>XXX</IDFAMILLE>
26
        <EMISSION>23/03/2017</EMISSION>
27
        <MONTANT>28.98</MONTANT>
28
        <IDFACTURE>43</IDFACTURE>
29
        <NOFACTURE>43</NOFACTURE>
30
        <LIBELLE>PRESTATIONS OCTOBRE 2015</LIBELLE>
31
        <IPDF>O</IPDF>
32
      </FACTURE>
33
    </DIRECTION>
34
</LISTFACTURE>
35
</PORTAIL>
tests/test_toulouse_axel.py
34 34
    ToulouseAxel,
35 35
    form_maj_famille_dui,
36 36
    form_paiement_dui,
37
    list_dui_factures,
37 38
    ref_date_gestion_dui,
38 39
    ref_famille_dui,
39 40
    ref_facture_a_payer,
......
314 315
            })
315 316

  
316 317

  
318
@pytest.mark.parametrize('content', [
319
    '<PORTAIL><LISTFACTURE/></PORTAIL>',
320
])
321
def test_operation_list_dui_factures(resource, content):
322
    with mock_getdata(content, 'ListeDuiFacturesPayeesRecettees'):
323
        with pytest.raises(AxelError):
324
            list_dui_factures(resource, {
325
                'LISTFACTURE': {
326
                    'NUMDUI': 'XXX',
327
                    'DEBUT': '1970-01-01'
328
                }
329
            })
330

  
331

  
317 332
@pytest.mark.parametrize('content', [
318 333
    "<PORTAIL><PDF FOO='BAR'></PDF></PORTAIL>",
319 334
])
......
1337 1352
    ]
1338 1353

  
1339 1354

  
1355
def test_invoices_history_endpoint_axel_error(app, resource):
1356
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
1357
    with mock.patch('passerelle.contrib.toulouse_axel.models.list_dui_factures') as operation:
1358
        operation.side_effect = AxelError('FooBar')
1359
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices/history?NameID=yyy')
1360
    assert resp.json['err_desc'] == "Axel error: FooBar"
1361
    assert resp.json['err'] == 'error'
1362

  
1363

  
1364
def test_invoices_history_endpoint_no_result(app, resource):
1365
    resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices/history?NameID=yyy')
1366
    assert resp.json['err_desc'] == "Person not found"
1367
    assert resp.json['err'] == 'not-found'
1368

  
1369

  
1370
def test_invoices_history_endpoint_no_invoices(app, resource):
1371
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
1372
    content = '''<PORTAIL>
1373
    <LISTFACTURE>
1374
        <NBFACTURERESTANTE>0</NBFACTURERESTANTE>
1375
    </LISTFACTURE>
1376
</PORTAIL>'''
1377
    with mock_getdata(content, 'ListeDuiFacturesPayeesRecettees'):
1378
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices/history?NameID=yyy')
1379
    assert resp.json['err'] == 0
1380
    assert resp.json['data'] == []
1381

  
1382

  
1383
def test_invoices_history_endpoint(app, resource):
1384
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
1385
    filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices_history.xml')
1386
    with open(filepath) as xml:
1387
        content = xml.read()
1388
    with mock_getdata(content, 'ListeDuiFacturesPayeesRecettees'):
1389
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoices/history?NameID=yyy')
1390
    assert resp.json['err'] == 0
1391
    assert resp.json['data'] == [
1392
        {
1393
            'amount': 0,
1394
            'created': '2017-03-23',
1395
            'display_id': '42',
1396
            'has_pdf': False,
1397
            'id': 'XXX-42',
1398
            'label': 'PRESTATIONS SEPTEMBRE 2015',
1399
            'online_payment': False,
1400
            'paid': False,
1401
            'pay_limit_date': '',
1402
            'total_amount': '28.98',
1403
            'vendor': {
1404
                'toulouse-axel': {
1405
                    'EMISSION': '2017-03-23',
1406
                    'IDAXEL': 'AXEL',
1407
                    'IDDIRECTION': 'DIR-A',
1408
                    'IDFACTURE': 42,
1409
                    'IDFAMILLE': 'XXX',
1410
                    'IPDF': 'O',
1411
                    'LIBDIRECTION': 'DIRECTION A',
1412
                    'LIBELLE': 'PRESTATIONS SEPTEMBRE 2015',
1413
                    'MONTANT': '28.98',
1414
                    'NOFACTURE': 42,
1415
                    'NUMDIRECTION': 10
1416
                }
1417
            }
1418
        },
1419
        {
1420
            'amount': 0,
1421
            'created': '2017-03-23',
1422
            'display_id': '43',
1423
            'has_pdf': False,
1424
            'id': 'XXX-43',
1425
            'label': 'PRESTATIONS OCTOBRE 2015',
1426
            'online_payment': False,
1427
            'paid': False,
1428
            'pay_limit_date': '',
1429
            'total_amount': '28.98',
1430
            'vendor': {
1431
                'toulouse-axel': {
1432
                    'EMISSION': '2017-03-23',
1433
                    'IDAXEL': 'AXEL',
1434
                    'IDDIRECTION': 'DIR-B',
1435
                    'IDFACTURE': 43,
1436
                    'IDFAMILLE': 'XXX',
1437
                    'IPDF': 'O',
1438
                    'LIBDIRECTION': 'DIRECTION B',
1439
                    'LIBELLE': 'PRESTATIONS OCTOBRE 2015',
1440
                    'MONTANT': '28.98',
1441
                    'NOFACTURE': 43,
1442
                    'NUMDIRECTION': 11
1443
                }
1444
            }
1445
        }
1446
    ]
1447

  
1448

  
1340 1449
def test_invoice_endpoint_axel_error(app, resource):
1341 1450
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
1342 1451
    with mock.patch('passerelle.contrib.toulouse_axel.models.ref_facture_a_payer') as operation:
......
1356 1465
    with open(filepath) as xml:
1357 1466
        content = xml.read()
1358 1467
    with mock_getdata(content, 'RefFactureAPayer'):
1359
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-35?NameID=yyy')
1468
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_historical_invoice') as invoice:
1469
            invoice.return_value = None
1470
            resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-35?NameID=yyy')
1360 1471
    assert resp.json['err_desc'] == "Invoice not found"
1361 1472
    assert resp.json['err'] == 'not-found'
1362 1473
    with mock_getdata(content, 'RefFactureAPayer'):
1363
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-44?NameID=yyy')
1474
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_historical_invoice') as invoice:
1475
            invoice.return_value = None
1476
            resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-44?NameID=yyy')
1364 1477
    assert resp.json['err_desc'] == "Invoice not found"
1365 1478
    assert resp.json['err'] == 'not-found'
1366 1479

  
......
1400 1513
        }
1401 1514
    }
1402 1515

  
1516
    filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices_history.xml')
1517
    with open(filepath) as xml:
1518
        content = xml.read()
1519
    with mock_getdata(content, 'ListeDuiFacturesPayeesRecettees'):
1520
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_invoice') as invoice:
1521
            invoice.return_value = None
1522
            resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-42?NameID=yyy')
1523
    assert resp.json['err'] == 0
1524
    assert resp.json['data'] == {
1525
        'amount': 0,
1526
        'created': '2017-03-23',
1527
        'display_id': '42',
1528
        'has_pdf': False,
1529
        'id': 'XXX-42',
1530
        'label': 'PRESTATIONS SEPTEMBRE 2015',
1531
        'online_payment': False,
1532
        'paid': False,
1533
        'pay_limit_date': '',
1534
        'total_amount': '28.98',
1535
        'vendor': {
1536
            'toulouse-axel': {
1537
                'EMISSION': '2017-03-23',
1538
                'IDAXEL': 'AXEL',
1539
                'IDDIRECTION': 'DIR-A',
1540
                'IDFACTURE': 42,
1541
                'IDFAMILLE': 'XXX',
1542
                'IPDF': 'O',
1543
                'LIBDIRECTION': 'DIRECTION A',
1544
                'LIBELLE': 'PRESTATIONS SEPTEMBRE 2015',
1545
                'MONTANT': '28.98',
1546
                'NOFACTURE': 42,
1547
                'NUMDIRECTION': 10
1548
            }
1549
        }
1550
    }
1551

  
1403 1552

  
1404 1553
def test_invoice_pdf_endpoint_axel_error(app, resource):
1405 1554
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
......
1430 1579
    with open(filepath) as xml:
1431 1580
        content = xml.read()
1432 1581
    with mock_getdata(content, 'RefFactureAPayer'):
1433
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-35/pdf?NameID=yyy', status=404)
1582
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_historical_invoice') as invoice:
1583
            invoice.return_value = None
1584
            resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-35/pdf?NameID=yyy', status=404)
1434 1585
    assert resp.json['err_desc'] == "Invoice not found"
1435 1586
    assert resp.json['err'] == 'not-found'
1436 1587

  
1437 1588
    with mock_getdata(content, 'RefFactureAPayer'):
1438
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-44/pdf?NameID=yyy', status=404)
1589
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_historical_invoice') as invoice:
1590
            invoice.return_value = None
1591
            resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-44/pdf?NameID=yyy', status=404)
1439 1592
    assert resp.json['err_desc'] == "Invoice not found"
1440 1593
    assert resp.json['err'] == 'not-found'
1441 1594

  
......
1465 1618
        with mock_getdata(pdf_content, 'RefFacturePDF'):
1466 1619
            app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-42/pdf?NameID=yyy')
1467 1620

  
1621
    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_invoice') as invoice:
1622
        with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_historical_invoice') as historical_invoice:
1623
            invoice.return_value = None
1624
            historical_invoice.return_value = {'has_pdf': True, 'display_id': '42'}
1625
            with mock_getdata(pdf_content, 'RefFacturePDF'):
1626
                app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-42/pdf?NameID=yyy')
1627

  
1468 1628

  
1469 1629
def test_pay_invoice_endpoint_axel_error(app, resource):
1470 1630
    payload = {
1471
-