Projet

Général

Profil

0001-toulouse_axel-accept-DUI-with-dashes-55753.patch

Benjamin Dauvergne, 22 juillet 2021 11:33

Télécharger (7,55 ko)

Voir les différences:

Subject: [PATCH] toulouse_axel: accept DUI with dashes (#55753)

 passerelle/contrib/toulouse_axel/models.py |  8 ++---
 tests/test_toulouse_axel.py                | 37 ++++++++++++----------
 2 files changed, 24 insertions(+), 21 deletions(-)
passerelle/contrib/toulouse_axel/models.py
774 774
        display_order=3,
775 775
        name='regie',
776 776
        perm='can_access',
777
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>(historical-)?\w+-\d+)/?$',
777
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>(historical-)?[\w-]+-\d+)/?$',
778 778
        example_pattern='{regie_id}/invoice/{invoice_id}',
779 779
        description=_('Get invoice details'),
780 780
        parameters={
......
799 799
        display_order=4,
800 800
        name='regie',
801 801
        perm='can_access',
802
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>(historical-)?\w+-\d+)/pdf/?$',
802
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>(historical-)?[\w-]+-\d+)/pdf/?$',
803 803
        example_pattern='{regie_id}/invoice/{invoice_id}/pdf',
804 804
        description=_('Get invoice as a PDF file'),
805 805
        parameters={
......
851 851
        name='regie',
852 852
        methods=['post'],
853 853
        perm='can_access',
854
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>\w+-\d+)/pay/?$',
854
        pattern=r'^(?P<regie_id>[\w-]+)/invoice/(?P<invoice_id>[\w-]+-\d+)/pay/?$',
855 855
        example_pattern='{regie_id}/invoice/{invoice_id}/pay',
856 856
        description=_('Notify an invoice as paid'),
857 857
        parameters={
......
868 868
    )
869 869
    def pay_invoice(self, request, regie_id, invoice_id, **kwargs):
870 870
        data = json_loads(request.body)
871
        dui, invoice_id = invoice_id.split('-')
871
        dui, invoice_id = invoice_id.rsplit('-', 1)
872 872

  
873 873
        invoice = self.get_invoice(regie_id=regie_id, dui=dui, invoice_id=invoice_id)
874 874
        if invoice is None:
tests/test_toulouse_axel.py
2296 2296
    assert resp.json['err'] == 'not-found'
2297 2297

  
2298 2298

  
2299
def test_invoice_endpoint(app, resource):
2300
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
2299
@pytest.mark.parametrize('dui', ['XXX', 'S-XXX'])
2300
def test_invoice_endpoint(app, resource, dui):
2301
    Link.objects.create(resource=resource, name_id='yyy', dui=dui, person_id='42')
2301 2302
    filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices.xml')
2302 2303
    with open(filepath) as xml:
2303
        content = xml.read()
2304
        content = xml.read().replace('XXX', dui)
2304 2305
    with mock_getdata(content, 'RefFactureAPayer'):
2305
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-42?NameID=yyy')
2306
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/%s-42?NameID=yyy' % dui)
2306 2307
    assert resp.json['err'] == 0
2307 2308
    assert resp.json['data'] == {
2308
        'id': 'XXX-42',
2309
        'id': '%s-42' % dui,
2309 2310
        'display_id': '42',
2310 2311
        'label': 'PRESTATIONS PERISCOLAIRES SEPTEMBRE-OCTOBRE 2019',
2311 2312
        'amount': '4.94',
......
2334 2335

  
2335 2336
    filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices_history.xml')
2336 2337
    with open(filepath) as xml:
2337
        content = xml.read()
2338
        content = xml.read().replace('XXX', dui)
2338 2339
    with mock_getdata(content, 'ListeDuiFacturesPayeesRecettees'):
2339
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/historical-XXX-42?NameID=yyy')
2340
        resp = app.get('/toulouse-axel/test/regie/MAREGIE/invoice/historical-%s-42?NameID=yyy' % dui)
2340 2341
    assert resp.json['err'] == 0
2341 2342
    assert resp.json['data'] == {
2342 2343
        'amount': 0,
2343 2344
        'created': '2017-03-23',
2344 2345
        'display_id': '42',
2345 2346
        'has_pdf': True,
2346
        'id': 'historical-XXX-42',
2347
        'id': 'historical-%s-42' % dui,
2347 2348
        'label': 'PRESTATIONS SEPTEMBRE 2015',
2348 2349
        'online_payment': False,
2349 2350
        'paid': False,
......
2355 2356
                'IDAXEL': 'AXEL',
2356 2357
                'IDDIRECTION': 'DIR-A',
2357 2358
                'IDFACTURE': 42,
2358
                'IDFAMILLE': 'XXX',
2359
                'IDFAMILLE': dui,
2359 2360
                'IPDF': 'O',
2360 2361
                'LIBDIRECTION': 'DIRECTION A',
2361 2362
                'LIBELLE': 'PRESTATIONS SEPTEMBRE 2015',
......
2421 2422
    assert resp.json['err'] == 'error'
2422 2423

  
2423 2424

  
2424
def test_invoice_pdf_endpoint(app, resource):
2425
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
2425
@pytest.mark.parametrize('dui', ['XXX', 'S-XXX'])
2426
def test_invoice_pdf_endpoint(app, resource, dui):
2427
    Link.objects.create(resource=resource, name_id='yyy', dui=dui, person_id='42')
2426 2428
    pdf_content = '''<PORTAIL>
2427 2429
    <PDF FILE='aGVsbG8gd29ybGQ='></PDF>
2428 2430
</PORTAIL>'''
2429 2431
    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_invoice') as invoice:
2430 2432
        invoice.return_value = {'has_pdf': True, 'display_id': '42'}
2431 2433
        with mock_getdata(pdf_content, 'RefFacturePDF'):
2432
            app.get('/toulouse-axel/test/regie/MAREGIE/invoice/XXX-42/pdf?NameID=yyy')
2434
            app.get('/toulouse-axel/test/regie/MAREGIE/invoice/%s-42/pdf?NameID=yyy' % dui)
2433 2435
    assert invoice.call_args_list[0][1]['historical'] is False
2434 2436

  
2435 2437
    with mock.patch('passerelle.contrib.toulouse_axel.models.ToulouseAxel.get_invoice') as invoice:
2436 2438
        invoice.return_value = {'has_pdf': True, 'display_id': '42'}
2437 2439
        with mock_getdata(pdf_content, 'RefFacturePDF'):
2438
            app.get('/toulouse-axel/test/regie/MAREGIE/invoice/historical-XXX-42/pdf?NameID=yyy')
2440
            app.get('/toulouse-axel/test/regie/MAREGIE/invoice/historical-%s-42/pdf?NameID=yyy' % dui)
2439 2441
    assert invoice.call_args_list[0][1]['historical'] is True
2440 2442

  
2441 2443

  
......
2488 2490
    assert resp.json['err'] == 'not-found'
2489 2491

  
2490 2492

  
2491
def test_pay_invoice_endpoint(app, resource):
2493
@pytest.mark.parametrize('dui', ['XXX', 'S-XXX'])
2494
def test_pay_invoice_endpoint(app, resource, dui):
2492 2495
    payload = {
2493 2496
        'transaction_date': '2020-01-01T12:00:00',
2494 2497
        'transaction_id': 'foo',
2495 2498
    }
2496
    Link.objects.create(resource=resource, name_id='yyy', dui='XXX', person_id='42')
2499
    Link.objects.create(resource=resource, name_id='yyy', dui=dui, person_id='42')
2497 2500
    filepath = os.path.join(os.path.dirname(__file__), 'data/toulouse_axel/invoices.xml')
2498 2501
    with open(filepath) as xml:
2499
        content = xml.read()
2502
        content = xml.read().replace('XXX', dui)
2500 2503
    with mock_getdata(content, 'RefFactureAPayer'):
2501 2504
        with mock.patch('passerelle.contrib.toulouse_axel.schemas.form_paiement_dui') as operation:
2502 2505
            resp = app.post_json(
2503
                '/toulouse-axel/test/regie/MAREGIE/invoice/XXX-42/pay?NameID=yyy', params=payload
2506
                '/toulouse-axel/test/regie/MAREGIE/invoice/%s-42/pay?NameID=yyy' % dui, params=payload
2504 2507
            )
2505 2508
    assert resp.json['err'] == 0
2506 2509
    assert resp.json['data'] is True
2507
-