Projet

Général

Profil

0002-toulouse_axel-invoice-history-39028.patch

Lauréline Guérin, 21 janvier 2020 09:27

Télécharger (22,6 ko)

Voir les différences:

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

 passerelle/contrib/toulouse_axel/models.py    | 113 ++++++++++---
 .../Dui/Q_ListeDuiFacturesPayeesRecettees.xsd |  18 +++
 .../Dui/R_ListeDuiFacturesPayeesRecettees.xsd |  95 +++++++++++
 tests/data/toulouse_axel/invoices_history.xml |  35 ++++
 tests/test_toulouse_axel.py                   | 150 ++++++++++++++++++
 5 files changed, 385 insertions(+), 26 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'])
761
        if historical:
762
            invoice_id = 'historical-%s' % invoice_id
758 763
        data = {
759 764
            'id': invoice_id,
760 765
            'display_id': str(invoice['IDFACTURE']),
761 766
            '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 767
            'paid': False,
768
            'vendor': {'toulouse-axel': invoice},
768
            'vendor': {'toulouse-axel': vendor},
769 769
        }
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()
770
        if historical:
771
            data.update({
772
                'amount': 0,
773
                'total_amount': invoice['MONTANT'],
774
                'created': invoice['EMISSION'],
775
                'pay_limit_date': '',
776
                'online_payment': False,
777
                'has_pdf': True if invoice['IPDF'] == '1' else False,
778
            })
779
        else:
780
            data.update({
781
                'amount': invoice['RESTEAPAYER'],
782
                'total_amount': invoice['MONTANTTOTAL'],
783
                'created': invoice['DATEEMISSION'],
784
                'pay_limit_date': invoice['DATEECHEANCE'],
785
                'has_pdf': True if invoice['EXISTEPDF'] == '1' else False,
786
            })
787
            pay_limit_date = datetime.datetime.strptime(invoice['DATEECHEANCE'], '%Y-%m-%d').date()
788
            data['online_payment'] = data['amount'] > 0 and pay_limit_date >= datetime.date.today()
772 789
        return data
773 790

  
774 791
    def get_invoices(self, regie_id, dui=None, name_id=None):
......
793 810
            result.append(self.normalize_invoice(facture, dui))
794 811
        return result
795 812

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

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

  
842
    def get_invoice(self, regie_id, invoice_id, dui=None, name_id=None, historical=None):
843
        if historical:
844
            invoices_data = self.get_historical_invoices(name_id=name_id)
845
        else:
846
            invoices_data = self.get_invoices(regie_id=regie_id, dui=dui, name_id=name_id)
798 847
        for invoice in invoices_data:
799 848
            if invoice['display_id'] == invoice_id:
800 849
                return invoice
......
816 865
    @endpoint(
817 866
        name='regie',
818 867
        perm='can_access',
819
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>\w+-\d+)/?$',
868
        pattern=r'^(?P<regie_id>[\w-]+)/invoices/history/?$',
869
        example_pattern='{regie_id}/invoices/history/',
870
        description=_("Get invoices already paid"),
871
        parameters={
872
            'NameID': {'description': _('Publik ID')},
873
            'regie_id': {'description': _('Regie identifier'), 'example_value': '42-PERISCOL'}
874
        })
875
    def invoices_history(self, request, regie_id, NameID):
876
        invoices_data = self.get_historical_invoices(name_id=NameID)
877
        return {'data': invoices_data}
878

  
879
    @endpoint(
880
        name='regie',
881
        perm='can_access',
882
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>(historical-)?\w+-\d+)/?$',
820 883
        example_pattern='{regie_id}/invoice/{invoice_id}/',
821 884
        description=_('Get invoice details'),
822 885
        parameters={
......
825 888
            'invoice_id': {'description': _('Invoice identifier'), 'example_value': 'DUI-42'}
826 889
        })
827 890
    def invoice(self, request, regie_id, invoice_id, NameID):
828
        invoice_id = invoice_id.split('-')[1]
829
        invoice = self.get_invoice(regie_id=regie_id, name_id=NameID, invoice_id=invoice_id)
891
        real_invoice_id = invoice_id.split('-')[-1]
892
        historical = invoice_id.startswith('historical-')
893
        invoice = self.get_invoice(regie_id=regie_id, name_id=NameID, invoice_id=real_invoice_id, historical=historical)
830 894
        if invoice is None:
831 895
            raise APIError('Invoice not found', err_code='not-found')
832 896

  
......
835 899
    @endpoint(
836 900
        name='regie',
837 901
        perm='can_access',
838
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>\w+-\d+)/pdf/?$',
902
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>(historical-)?\w+-\d+)/pdf/?$',
839 903
        example_pattern='{regie_id}/invoice/{invoice_id}/pdf/',
840 904
        description=_('Get invoice as a PDF file'),
841 905
        parameters={
......
845 909
        })
846 910
    def invoice_pdf(self, request, regie_id, invoice_id, NameID):
847 911
        # check that invoice is related to current user
848
        invoice_id = invoice_id.split('-')[1]
912
        real_invoice_id = invoice_id.split('-')[-1]
913
        historical = invoice_id.startswith('historical-')
849 914
        try:
850
            invoice = self.get_invoice(regie_id=regie_id, name_id=NameID, invoice_id=invoice_id)
915
            invoice = self.get_invoice(regie_id=regie_id, name_id=NameID, invoice_id=real_invoice_id, historical=historical)
851 916
        except APIError as e:
852 917
            e.http_status = 404
853 918
            raise
......
897 962
        data = json.loads(request.body)
898 963
        dui, invoice_id = invoice_id.split('-')
899 964

  
900
        invoices_data = self.get_invoices(regie_id=regie_id, dui=dui)
901
        transaction_amount = None
902
        for invoice in invoices_data:
903
            if invoice['display_id'] == invoice_id:
904
                transaction_amount = invoice['amount']
905
                break
906
        if transaction_amount is None:
965
        invoice = self.get_invoice(regie_id=regie_id, dui=dui, invoice_id=invoice_id)
966
        if invoice is None:
907 967
            raise APIError('Invoice not found', err_code='not-found')
908 968

  
969
        transaction_amount = invoice['amount']
909 970
        transaction_id = data['transaction_id']
910 971
        transaction_date = encode_datetime(data['transaction_date'])
911 972
        post_data = {
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': 'historical-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': 'historical-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:
......
1400 1509
        }
1401 1510
    }
1402 1511

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

  
1403 1546

  
1404 1547
def test_invoice_pdf_endpoint_axel_error(app, resource):
1405 1548
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
......
1464 1607
        invoice.return_value = {'has_pdf': True, 'display_id': '42'}
1465 1608
        with mock_getdata(pdf_content, 'RefFacturePDF'):
1466 1609
            app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-42/pdf?NameID=yyy')
1610
    assert invoice.call_args_list[0][1]['historical'] is False
1611

  
1612
    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_invoice') as invoice:
1613
        invoice.return_value = {'has_pdf': True, 'display_id': '42'}
1614
        with mock_getdata(pdf_content, 'RefFacturePDF'):
1615
            app.get('/toulouse-axel/test/regie/MAREGIE/invoice/historical-XXX-42/pdf?NameID=yyy')
1616
    assert invoice.call_args_list[0][1]['historical'] is True
1467 1617

  
1468 1618

  
1469 1619
def test_pay_invoice_endpoint_axel_error(app, resource):
1470
-