0001-sivin-accept-and-translate-plate-numbers-in-FIN-form.patch
passerelle/apps/sivin/models.py | ||
---|---|---|
14 | 14 |
# You should have received a copy of the GNU Affero General Public License |
15 | 15 |
# along with this program. If not, see <http://www.gnu.org/licenses/>.xs |
16 | 16 | |
17 |
import re |
|
17 | 18 |
from urllib.parse import urljoin |
18 | 19 | |
19 | 20 |
from django.core.cache import cache |
... | ... | |
35 | 36 | |
36 | 37 |
ENVS = (('test', _('Test')), ('prod', _('Production'))) |
37 | 38 | |
39 |
FIN_PLATE_PATTERN = re.compile(r'(\d{2,4})([a-zA-Z]{2,3})(\d{2,3})') |
|
40 | ||
38 | 41 | |
39 | 42 |
class Resource(BaseResource): |
40 | 43 |
consumer_key = models.CharField(_('Consumer key'), max_length=128) |
... | ... | |
86 | 89 |
def get_infos_by_immat(self, endpoint, immat, codesra=None): |
87 | 90 |
# remove dashes / spaces in immat to avoid lookup issues |
88 | 91 |
immat = immat.strip().replace('-', '').replace(' ', '').upper() |
92 |
fin_match = FIN_PLATE_PATTERN.match(immat) |
|
93 |
if fin_match: |
|
94 |
immat = f'{fin_match.group(3)}{fin_match.group(2)}{fin_match.group(1).zfill(4)}' |
|
89 | 95 |
payload = {'immat': immat} |
90 | 96 |
if codesra is not None: |
91 | 97 |
payload['codesra'] = codesra |
tests/test_sivin.py | ||
---|---|---|
184 | 184 |
'generic-endpoint', |
185 | 185 |
kwargs={'connector': 'sivin', 'endpoint': 'consulterfinitiontheoriqueparimmat', 'slug': conn.slug}, |
186 | 186 |
) |
187 |
resp = app.get(url, params={'apikey': 'sivinkey', 'immat': '01-xT0 747'}).json
|
|
187 |
resp = app.get(url, params={'apikey': 'sivinkey', 'immat': '747-xT 01'}).json
|
|
188 | 188 |
assert mocked_post.call_count == 2 |
189 | 189 |
assert mocked_post.mock_calls[-1].kwargs['json'] == {'immat': '01XT0747'} |
190 | 190 |
assert not resp['err'] |
191 |
- |