sivin: normalize immat to avoid lookup issues with remote API (#67359)

This commit is contained in:
Agate 2022-07-13 12:08:05 +02:00
parent 3cec274259
commit a9449c0e51
2 changed files with 5 additions and 1 deletions

View File

@ -84,6 +84,8 @@ class Resource(BaseResource):
return resp.json()
def get_infos_by_immat(self, endpoint, immat, codesra=None):
# remove dashes / spaces in immat to avoid lookup issues
immat = immat.strip().replace('-', '').replace(' ', '').upper()
payload = {'immat': immat}
if codesra is not None:
payload['codesra'] = codesra

View File

@ -146,6 +146,7 @@ def test_get_details_by_vin(mocked_post, app, conn):
kwargs={'connector': 'sivin', 'endpoint': 'consultervehiculeparvin', 'slug': conn.slug},
)
resp = app.get(url, params={'apikey': 'sivinkey', 'vin': 'VF1BA0E0514143067'}).json
assert mocked_post.call_count == 2
assert not resp['err']
assert resp['data'] == VEHICLE_DETAILS
@ -183,8 +184,9 @@ def test_get_vehicle_theorical_finition(mocked_post, app, conn):
'generic-endpoint',
kwargs={'connector': 'sivin', 'endpoint': 'consulterfinitiontheoriqueparimmat', 'slug': conn.slug},
)
resp = app.get(url, params={'apikey': 'sivinkey', 'immat': '01XT0747'}).json
resp = app.get(url, params={'apikey': 'sivinkey', 'immat': '01-xT0 747'}).json
assert mocked_post.call_count == 2
assert mocked_post.mock_calls[-1].kwargs['json'] == {'immat': '01XT0747'}
assert not resp['err']
assert resp['data'] == VEHICLE_THEORICAL_FINITION