3298 |
3298 |
with mock_data(content, 'GetFacturesaPayer'):
|
3299 |
3299 |
with mock.patch('passerelle.contrib.caluire_axel.schemas.set_paiement') as operation:
|
3300 |
3300 |
operation.side_effect = AxelError('FooBar')
|
3301 |
3301 |
resp = app.post_json(
|
3302 |
3302 |
'/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pay?NameID=yyy', params=payload
|
3303 |
3303 |
)
|
3304 |
3304 |
assert resp.json['err_desc'] == "Axel error: FooBar"
|
3305 |
3305 |
assert resp.json['err'] == 'error'
|
3306 |
|
for key in ('xml_request', 'xml_response', 'regie_id', 'family_id', 'invoice', 'post_data', 'kwargs'):
|
|
3306 |
for key in (
|
|
3307 |
'xml_request',
|
|
3308 |
'xml_response',
|
|
3309 |
'regie_id',
|
|
3310 |
'invoice_id',
|
|
3311 |
'NameID',
|
|
3312 |
'post_data',
|
|
3313 |
'invoice',
|
|
3314 |
'payload',
|
|
3315 |
):
|
3307 |
3316 |
assert key in resp.json['data'].keys()
|
3308 |
3317 |
|
3309 |
3318 |
content2 = '''
|
3310 |
3319 |
<PORTAIL>
|
3311 |
3320 |
<SETPAIEMENT>
|
3312 |
3321 |
<CODE>-3</CODE>
|
3313 |
3322 |
</SETPAIEMENT>
|
3314 |
3323 |
</PORTAIL>'''
|
... | ... | |
3324 |
3333 |
|
3325 |
3334 |
|
3326 |
3335 |
def test_pay_invoice_endpoint_bad_request(app, resource):
|
3327 |
3336 |
resp = app.post_json(
|
3328 |
3337 |
'/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pay?NameID=yyy', params={}, status=400
|
3329 |
3338 |
)
|
3330 |
3339 |
assert resp.json['err_desc'] == "'transaction_date' is a required property"
|
3331 |
3340 |
|
|
3341 |
payload = {
|
|
3342 |
'transaction_date': '2021-06-15T12:00:00',
|
|
3343 |
'transaction_id': 'foo',
|
|
3344 |
}
|
|
3345 |
resp = app.post_json('/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pay?NameID=yyy', params=payload)
|
|
3346 |
assert resp.json['err_desc'] == "Person not found"
|
|
3347 |
assert resp.json['err'] == 'not-found'
|
|
3348 |
|
|
3349 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
|
3350 |
resp = app.post_json(
|
|
3351 |
'/caluire-axel/test/regie/MAREGIE/invoice/ZZZ-42/pay?NameID=yyy', params=payload, status=500
|
|
3352 |
)
|
|
3353 |
assert resp.json['err'] == 1
|
|
3354 |
assert resp.json['err_class'] == 'AssertionError'
|
|
3355 |
assert resp.json['err_desc'] == 'invoice does not belongs to linked family'
|
|
3356 |
|
3332 |
3357 |
|
3333 |
3358 |
@freezegun.freeze_time('2019-12-04')
|
3334 |
3359 |
def test_pay_invoice_endpoint_no_result(app, resource):
|
3335 |
3360 |
payload = {
|
3336 |
3361 |
'transaction_date': '2021-06-15T12:00:00',
|
3337 |
3362 |
'transaction_id': 'foo',
|
3338 |
3363 |
}
|
|
3364 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
3339 |
3365 |
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
|
3340 |
3366 |
with open(filepath) as xml:
|
3341 |
3367 |
content = (
|
3342 |
3368 |
'''<PORTAIL>
|
3343 |
3369 |
<GETFACTURESAPAYER>
|
3344 |
3370 |
%s
|
3345 |
3371 |
</GETFACTURESAPAYER>
|
3346 |
3372 |
</PORTAIL>'''
|
... | ... | |
3357 |
3383 |
assert resp.json['err'] == 'not-found'
|
3358 |
3384 |
|
3359 |
3385 |
|
3360 |
3386 |
def test_pay_invoice_endpoint_wrong_response(app, resource):
|
3361 |
3387 |
payload = {
|
3362 |
3388 |
'transaction_date': '2021-06-15T12:00:00',
|
3363 |
3389 |
'transaction_id': 'foo',
|
3364 |
3390 |
}
|
|
3391 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
3365 |
3392 |
with mock.patch(
|
3366 |
3393 |
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_invoice',
|
3367 |
3394 |
return_value={'amount': '44.9'},
|
3368 |
3395 |
):
|
3369 |
3396 |
with mock.patch('passerelle.contrib.caluire_axel.schemas.set_paiement') as operation:
|
3370 |
3397 |
operation.return_value = OperationResult(
|
3371 |
3398 |
json_response={'DATA': {'PORTAIL': {}}},
|
3372 |
3399 |
xml_request='',
|
... | ... | |
3374 |
3401 |
)
|
3375 |
3402 |
resp = app.post_json(
|
3376 |
3403 |
'/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pay?NameID=yyy',
|
3377 |
3404 |
params=payload,
|
3378 |
3405 |
status=500,
|
3379 |
3406 |
)
|
3380 |
3407 |
assert resp.json['err'] == 'pay-invoice-code-response-error'
|
3381 |
3408 |
assert resp.json['err_desc'] == 'Wrong pay-invoice response'
|
3382 |
|
for key in 'regie_id', 'family_id', 'invoice', 'post_data', 'kwargs', 'result':
|
|
3409 |
for key in 'regie_id', 'invoice_id', 'NameID', 'post_data', 'invoice', 'payload', 'result':
|
3383 |
3410 |
assert key in resp.json['data'].keys()
|
3384 |
3411 |
|
3385 |
3412 |
with mock.patch('passerelle.contrib.caluire_axel.schemas.set_paiement') as operation:
|
3386 |
3413 |
operation.return_value = OperationResult(
|
3387 |
3414 |
json_response={'DATA': {'PORTAIL': {'SETPAIEMENT': {'CODE': 'oups'}}}},
|
3388 |
3415 |
xml_request='',
|
3389 |
3416 |
xml_response='',
|
3390 |
3417 |
)
|
3391 |
3418 |
resp = app.post_json(
|
3392 |
3419 |
'/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pay?NameID=yyy',
|
3393 |
3420 |
params=payload,
|
3394 |
3421 |
status=500,
|
3395 |
3422 |
)
|
3396 |
3423 |
assert resp.json['err'] == 'pay-invoice-code-response-error'
|
3397 |
3424 |
assert resp.json['err_desc'] == 'Wrong pay-invoice response'
|
3398 |
|
for key in 'regie_id', 'family_id', 'invoice', 'post_data', 'kwargs', 'result':
|
|
3425 |
for key in 'regie_id', 'invoice_id', 'NameID', 'post_data', 'invoice', 'payload', 'result':
|
3399 |
3426 |
assert key in resp.json['data'].keys()
|
3400 |
3427 |
|
3401 |
3428 |
|
3402 |
3429 |
def test_pay_invoice_endpoint(app, resource):
|
3403 |
3430 |
payload = {
|
3404 |
3431 |
'transaction_date': '2021-06-15T12:00:00',
|
3405 |
3432 |
'transaction_id': 'foo',
|
3406 |
3433 |
}
|
... | ... | |
3433 |
3460 |
assert resp.json['created'] is True
|
3434 |
3461 |
|
3435 |
3462 |
|
3436 |
3463 |
def test_pay_invoice_providing_mode_reglement(app, resource):
|
3437 |
3464 |
payload = {
|
3438 |
3465 |
'transaction_date': '2021-06-15T12:00:00',
|
3439 |
3466 |
'transaction_id': 'foo',
|
3440 |
3467 |
}
|
|
3468 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
3441 |
3469 |
with mock.patch(
|
3442 |
3470 |
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_invoice',
|
3443 |
3471 |
return_value={'amount': '44.9'},
|
3444 |
3472 |
):
|
3445 |
3473 |
with mock.patch('passerelle.contrib.caluire_axel.schemas.set_paiement') as operation:
|
3446 |
3474 |
operation.return_value = OperationResult(
|
3447 |
3475 |
json_response={'DATA': {'PORTAIL': {'SETPAIEMENT': {'CODE': 0}}}},
|
3448 |
3476 |
xml_request='',
|
3449 |
|
-
|