From 33b4197ea5c017beefc011f71090bbd9d9c7de25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 19 Jun 2019 09:57:46 +0200 Subject: [PATCH] wcs: ignore case/spaces in tracking code (#34156) --- combo/apps/wcs/views.py | 2 ++ tests/test_wcs.py | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/combo/apps/wcs/views.py b/combo/apps/wcs/views.py index 80d470a0..09d4660c 100644 --- a/combo/apps/wcs/views.py +++ b/combo/apps/wcs/views.py @@ -42,6 +42,7 @@ class TrackingCodeView(View): @classmethod def search(self, code, wcs_site=None): + code = code.strip().upper() if wcs_site: wcs_sites = [get_wcs_services().get(wcs_site)] else: @@ -86,6 +87,7 @@ class TrackingCodeView(View): def tracking_code_search(request): hits = [] query = request.GET.get('q') or '' + query = query.strip().upper() if re.match(r'^[BCDFGHJKLMNPQRSTVWXZ]{8}$', query): url = TrackingCodeView.search(query) if url: diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 244bbb4b..5f173450 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -636,6 +636,13 @@ def test_tracking_code_cell(app): assert resp.status_code == 302 assert resp.location == 'http://127.0.0.2:8999/code/CNPHNTFB/load' + # space/case + resp = app.get('/') + resp.form['code'] = ' cnphntfb' + resp = resp.form.submit() + assert resp.status_code == 302 + assert resp.location == 'http://127.0.0.2:8999/code/CNPHNTFB/load' + # lock cell to a single site cell.wcs_site = 'default' cell.save() @@ -711,6 +718,7 @@ def test_tracking_code_search(app): assert len(app.get('/api/search/tracking-code/?q=BBCCDDFF').json.get('data')) == 0 assert len(app.get('/api/search/tracking-code/?q=CNPHNTFB').json.get('data')) == 1 assert len(app.get('/api/search/tracking-code/?q=BBCCDDFFG').json.get('data')) == 0 + assert len(app.get('/api/search/tracking-code/?q= cnphntfb').json.get('data')) == 1 @wcsctl_present def test_wcs_search_engines(app):