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 |
|
-
|