From 913b94b7db3343b0ed6d77e762e965be58c65c9b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Fri, 5 Aug 2022 13:12:15 +0200 Subject: [PATCH] sivin: accept and translate plate numbers in FIN format (#67925) --- passerelle/apps/sivin/models.py | 6 ++++++ tests/test_sivin.py | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/passerelle/apps/sivin/models.py b/passerelle/apps/sivin/models.py index be0544f6..96b01e55 100644 --- a/passerelle/apps/sivin/models.py +++ b/passerelle/apps/sivin/models.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see .xs +import re from urllib.parse import urljoin from django.core.cache import cache @@ -35,6 +36,8 @@ PLATFORMS = { ENVS = (('test', _('Test')), ('prod', _('Production'))) +FIN_PLATE_PATTERN = re.compile(r'(\d{2,4})([a-zA-Z]{2,3})(\d{2,3})') + class Resource(BaseResource): consumer_key = models.CharField(_('Consumer key'), max_length=128) @@ -86,6 +89,9 @@ class Resource(BaseResource): 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() + fin_match = FIN_PLATE_PATTERN.match(immat) + if fin_match: + immat = f'{fin_match.group(3)}{fin_match.group(2)}{fin_match.group(1).zfill(4)}' payload = {'immat': immat} if codesra is not None: payload['codesra'] = codesra diff --git a/tests/test_sivin.py b/tests/test_sivin.py index fecbbb4a..7a200410 100644 --- a/tests/test_sivin.py +++ b/tests/test_sivin.py @@ -184,7 +184,7 @@ 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': '01-xT0 747'}).json + resp = app.get(url, params={'apikey': 'sivinkey', 'immat': '747-xT 01'}).json assert mocked_post.call_count == 2 assert mocked_post.mock_calls[-1].kwargs['json'] == {'immat': '01XT0747'} assert not resp['err'] -- 2.35.1