2815 |
2815 |
</GETFACTURESAPAYER>
|
2816 |
2816 |
</PORTAIL>'''
|
2817 |
2817 |
with mock_data(content, 'GetFacturesaPayer'):
|
2818 |
2818 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoices?NameID=yyy')
|
2819 |
2819 |
assert resp.json['err'] == 0
|
2820 |
2820 |
assert resp.json['data'] == []
|
2821 |
2821 |
|
2822 |
2822 |
|
2823 |
|
@freezegun.freeze_time('2019-12-05')
|
|
2823 |
@freezegun.freeze_time('2019-12-12')
|
2824 |
2824 |
def test_invoices_endpoint(app, resource):
|
2825 |
2825 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
2826 |
2826 |
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
|
2827 |
2827 |
with open(filepath) as xml:
|
2828 |
2828 |
content = (
|
2829 |
2829 |
'''
|
2830 |
2830 |
<PORTAIL>
|
2831 |
2831 |
<GETFACTURESAPAYER>
|
... | ... | |
2933 |
2933 |
</GETLISTFACTURES>
|
2934 |
2934 |
</PORTAIL>'''
|
2935 |
2935 |
with mock_data(content, 'GetListFactures'):
|
2936 |
2936 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoices/history?NameID=yyy')
|
2937 |
2937 |
assert resp.json['err'] == 0
|
2938 |
2938 |
assert resp.json['data'] == []
|
2939 |
2939 |
|
2940 |
2940 |
|
|
2941 |
@freezegun.freeze_time('2019-12-12')
|
2941 |
2942 |
def test_invoices_history_endpoint(app, resource):
|
2942 |
2943 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
2943 |
2944 |
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
|
2944 |
2945 |
with open(filepath) as xml:
|
2945 |
2946 |
content = (
|
2946 |
2947 |
'''<PORTAIL>
|
2947 |
2948 |
<GETLISTFACTURES>
|
2948 |
2949 |
%s
|
... | ... | |
3038 |
3039 |
</GETLISTFACTURES>
|
3039 |
3040 |
</PORTAIL>'''
|
3040 |
3041 |
with mock_data(content, 'GetListFactures'):
|
3041 |
3042 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/historical-XXX-42?NameID=yyy')
|
3042 |
3043 |
assert resp.json['err_desc'] == "Wrong get-historical-invoices status"
|
3043 |
3044 |
assert resp.json['err'] == 'get-historical-invoices-code-error--3'
|
3044 |
3045 |
|
3045 |
3046 |
|
|
3047 |
@freezegun.freeze_time('2019-12-12')
|
3046 |
3048 |
def test_invoice_endpoint_no_result(app, resource):
|
3047 |
3049 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/XXX-42?NameID=yyy')
|
3048 |
3050 |
assert resp.json['err_desc'] == "Person not found"
|
3049 |
3051 |
assert resp.json['err'] == 'not-found'
|
3050 |
3052 |
|
3051 |
3053 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
3052 |
3054 |
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
|
3053 |
3055 |
with open(filepath) as xml:
|
... | ... | |
3059 |
3061 |
</GETFACTURESAPAYER>
|
3060 |
3062 |
</PORTAIL>'''
|
3061 |
3063 |
% invoices
|
3062 |
3064 |
)
|
3063 |
3065 |
with mock_data(content, 'GetFacturesaPayer'):
|
3064 |
3066 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/XXX-35?NameID=yyy')
|
3065 |
3067 |
assert resp.json['err_desc'] == "Invoice not found"
|
3066 |
3068 |
assert resp.json['err'] == 'not-found'
|
|
3069 |
|
|
3070 |
with mock_data(content, 'GetFacturesaPayer'):
|
|
3071 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/XXX-44?NameID=yyy')
|
|
3072 |
assert resp.json['err_desc'] == "Invoice not found"
|
|
3073 |
assert resp.json['err'] == 'not-found'
|
|
3074 |
|
3067 |
3075 |
content = (
|
3068 |
3076 |
'''<PORTAIL>
|
3069 |
3077 |
<GETLISTFACTURES>
|
3070 |
3078 |
%s
|
3071 |
3079 |
</GETLISTFACTURES>
|
3072 |
3080 |
</PORTAIL>'''
|
3073 |
3081 |
% invoices
|
3074 |
3082 |
)
|
|
3083 |
with mock_data(content, 'GetListFactures'):
|
|
3084 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/historical-XXX-35?NameID=yyy')
|
|
3085 |
assert resp.json['err_desc'] == "Invoice not found"
|
|
3086 |
assert resp.json['err'] == 'not-found'
|
|
3087 |
|
3075 |
3088 |
with mock_data(content, 'GetListFactures'):
|
3076 |
3089 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/historical-XXX-44?NameID=yyy')
|
3077 |
3090 |
assert resp.json['err_desc'] == "Invoice not found"
|
3078 |
3091 |
assert resp.json['err'] == 'not-found'
|
3079 |
3092 |
|
3080 |
3093 |
|
3081 |
3094 |
@freezegun.freeze_time('2019-12-04')
|
3082 |
3095 |
def test_invoice_endpoint(app, resource):
|
... | ... | |
3188 |
3201 |
resp = app.get(
|
3189 |
3202 |
'/caluire-axel/test/regie/MAREGIE/invoice/historical-XXX-42/pdf?NameID=yyy&nb_mounts_limit=not_a_number',
|
3190 |
3203 |
status=404,
|
3191 |
3204 |
)
|
3192 |
3205 |
assert resp.json['err_desc'] == "nb_mounts_limit must be an integer"
|
3193 |
3206 |
assert resp.json['err'] == 'bad-request'
|
3194 |
3207 |
|
3195 |
3208 |
|
|
3209 |
@freezegun.freeze_time('2019-12-13')
|
3196 |
3210 |
def test_invoice_pdf_endpoint_no_result(app, resource):
|
3197 |
3211 |
resp = app.get('/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pdf?NameID=yyy', status=404)
|
3198 |
3212 |
assert resp.json['err_desc'] == "Person not found"
|
3199 |
3213 |
assert resp.json['err'] == 'not-found'
|
3200 |
3214 |
|
3201 |
3215 |
Link.objects.create(resource=resource, name_id='yyy', family_id='XXX', person_id='42')
|
3202 |
3216 |
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
|
3203 |
3217 |
with open(filepath) as xml:
|
... | ... | |
3311 |
3325 |
|
3312 |
3326 |
def test_pay_invoice_endpoint_bad_request(app, resource):
|
3313 |
3327 |
resp = app.post_json(
|
3314 |
3328 |
'/caluire-axel/test/regie/MAREGIE/invoice/XXX-42/pay?NameID=yyy', params={}, status=400
|
3315 |
3329 |
)
|
3316 |
3330 |
assert resp.json['err_desc'] == "'transaction_date' is a required property"
|
3317 |
3331 |
|
3318 |
3332 |
|
|
3333 |
@freezegun.freeze_time('2019-12-04')
|
3319 |
3334 |
def test_pay_invoice_endpoint_no_result(app, resource):
|
3320 |
3335 |
payload = {
|
3321 |
3336 |
'transaction_date': '2021-06-15T12:00:00',
|
3322 |
3337 |
'transaction_id': 'foo',
|
3323 |
3338 |
}
|
3324 |
3339 |
filepath = os.path.join(os.path.dirname(__file__), 'data/caluire_axel/invoices.xml')
|
3325 |
3340 |
with open(filepath) as xml:
|
3326 |
3341 |
content = (
|
... | ... | |
3331 |
3346 |
</PORTAIL>'''
|
3332 |
3347 |
% xml.read()
|
3333 |
3348 |
)
|
3334 |
3349 |
with mock_data(content, 'GetFacturesaPayer'):
|
3335 |
3350 |
resp = app.post_json('/caluire-axel/test/regie/MAREGIE/invoice/XXX-35/pay?NameID=yyy', params=payload)
|
3336 |
3351 |
assert resp.json['err_desc'] == "Invoice not found"
|
3337 |
3352 |
assert resp.json['err'] == 'not-found'
|
3338 |
3353 |
|
|
3354 |
with mock_data(content, 'GetFacturesaPayer'):
|
|
3355 |
resp = app.post_json('/caluire-axel/test/regie/MAREGIE/invoice/XXX-44/pay?NameID=yyy', params=payload)
|
|
3356 |
assert resp.json['err_desc'] == "Invoice not found"
|
|
3357 |
assert resp.json['err'] == 'not-found'
|
|
3358 |
|
3339 |
3359 |
|
3340 |
3360 |
def test_pay_invoice_endpoint_wrong_response(app, resource):
|
3341 |
3361 |
payload = {
|
3342 |
3362 |
'transaction_date': '2021-06-15T12:00:00',
|
3343 |
3363 |
'transaction_id': 'foo',
|
3344 |
3364 |
}
|
3345 |
3365 |
with mock.patch(
|
3346 |
3366 |
'passerelle.contrib.caluire_axel.models.CaluireAxel.get_invoice',
|
3347 |
|
-
|