0001-solis-handle-id-in-referential-query-32455.patch
passerelle/apps/solis/models.py | ||
---|---|---|
371 | 371 |
'codeCommune': {'example_value': '21'}, |
372 | 372 |
'q': {'description': _('Returns only items whose text matches'), |
373 | 373 |
'example_value': 'claudel'}, |
374 |
'id': {'description': _('Returns only item with this id (code)')}, |
|
374 | 375 |
'ignore': {'description': _('Do not return items with this id, ' |
375 | 376 |
'or multiple ids separated with commas'), |
376 | 377 |
'example_value': '9999'}, |
377 | 378 |
}) |
378 |
def referential(self, request, module, name, q=None, ignore=None, **kwargs): |
|
379 |
def referential(self, request, module, name, q=None, id=None, ignore=None, **kwargs):
|
|
379 | 380 |
endpoint = 'referentiels/%s/%s' % (module, name) |
380 | 381 |
args = [(code, value) for code, value in kwargs.items() if code.startswith('code')] |
381 | 382 |
if args: |
... | ... | |
405 | 406 |
q = simplify(q) |
406 | 407 | |
407 | 408 |
def condition(item): |
409 |
if id and item['id'] != id: |
|
410 |
return False |
|
408 | 411 |
if ignore and item['id'] in ignore_ids: |
409 | 412 |
return False |
410 | 413 |
if q and q not in simplify(item['text']): |
tests/test_solis.py | ||
---|---|---|
427 | 427 |
assert len(resp.json['data']) == 2 |
428 | 428 |
assert (resp.json['data'][0]['text'], resp.json['data'][1]['text']) == (u'Ardèche', 'Ardennes') |
429 | 429 | |
430 |
resp = app.get(url + '/trans/departement/?id=7', status=200) |
|
431 |
assert requests_get.call_args[0][0].endswith('/solisapi/referentiels/trans/departement') |
|
432 |
assert resp.json['err'] == 0 |
|
433 |
assert len(resp.json['data']) == 1 |
|
434 |
assert resp.json['data'][0]['text'] == u'Ardèche' |
|
435 | ||
436 |
resp = app.get(url + '/trans/departement/?id=99', status=200) |
|
437 |
assert requests_get.call_args[0][0].endswith('/solisapi/referentiels/trans/departement') |
|
438 |
assert resp.json['err'] == 0 |
|
439 |
assert len(resp.json['data']) == 0 |
|
440 | ||
430 | 441 |
resp = app.get(url + '/trans/departement/?q=arde&ignore=8', status=200) |
431 | 442 |
assert resp.json['err'] == 0 |
432 | 443 |
assert len(resp.json['data']) == 1 |
433 |
- |