solis: handle id in referential query (#32455)
This commit is contained in:
parent
a52c914e8f
commit
d5929e6958
|
@ -371,11 +371,12 @@ class Solis(BaseResource):
|
|||
'codeCommune': {'example_value': '21'},
|
||||
'q': {'description': _('Returns only items whose text matches'),
|
||||
'example_value': 'claudel'},
|
||||
'id': {'description': _('Returns only item with this id (code)')},
|
||||
'ignore': {'description': _('Do not return items with this id, '
|
||||
'or multiple ids separated with commas'),
|
||||
'example_value': '9999'},
|
||||
})
|
||||
def referential(self, request, module, name, q=None, ignore=None, **kwargs):
|
||||
def referential(self, request, module, name, q=None, id=None, ignore=None, **kwargs):
|
||||
endpoint = 'referentiels/%s/%s' % (module, name)
|
||||
args = [(code, value) for code, value in kwargs.items() if code.startswith('code')]
|
||||
if args:
|
||||
|
@ -405,6 +406,8 @@ class Solis(BaseResource):
|
|||
q = simplify(q)
|
||||
|
||||
def condition(item):
|
||||
if id and item['id'] != id:
|
||||
return False
|
||||
if ignore and item['id'] in ignore_ids:
|
||||
return False
|
||||
if q and q not in simplify(item['text']):
|
||||
|
|
|
@ -427,6 +427,17 @@ def test_solis_referentiels(app, solis):
|
|||
assert len(resp.json['data']) == 2
|
||||
assert (resp.json['data'][0]['text'], resp.json['data'][1]['text']) == (u'Ardèche', 'Ardennes')
|
||||
|
||||
resp = app.get(url + '/trans/departement/?id=7', status=200)
|
||||
assert requests_get.call_args[0][0].endswith('/solisapi/referentiels/trans/departement')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 1
|
||||
assert resp.json['data'][0]['text'] == u'Ardèche'
|
||||
|
||||
resp = app.get(url + '/trans/departement/?id=99', status=200)
|
||||
assert requests_get.call_args[0][0].endswith('/solisapi/referentiels/trans/departement')
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 0
|
||||
|
||||
resp = app.get(url + '/trans/departement/?q=arde&ignore=8', status=200)
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 1
|
||||
|
|
Loading…
Reference in New Issue