239 |
239 |
'q': "rue de l'aubepine",
|
240 |
240 |
}
|
241 |
241 |
mocked_get.return_value = tests.utils.FakedResponse(content=FAKED_CONTENT_Q_SEARCH, status_code=200)
|
242 |
242 |
resp = app.get(endpoint, params=params, status=200)
|
243 |
243 |
assert mocked_get.call_args[1]['params'] == {
|
244 |
244 |
'apikey': 'my_secret',
|
245 |
245 |
'dataset': 'referentiel-adresse-test',
|
246 |
246 |
'rows': '3',
|
247 |
|
'q': "rue de l'aubepine",
|
|
247 |
'q': "rue de aubepine",
|
248 |
248 |
}
|
249 |
249 |
assert not resp.json['err']
|
250 |
250 |
assert len(resp.json['data']) == 3
|
251 |
251 |
# check order is kept
|
252 |
252 |
assert [x['id'] for x in resp.json['data']] == [
|
253 |
253 |
'e00cf6161e52a4c8fe510b2b74d4952036cb3473',
|
254 |
254 |
'7cafcd5c692773e8b863587b2d38d6be82e023d8',
|
255 |
255 |
'0984a5e1745701f71c91af73ce764e1f7132e0ff',
|
... | ... | |
258 |
258 |
assert [x['text'] for x in resp.json['data']] == [
|
259 |
259 |
"33 RUE DE L'AUBEPINE Strasbourg",
|
260 |
260 |
"19 RUE DE L'AUBEPINE Lipsheim",
|
261 |
261 |
"29 RUE DE L'AUBEPINE Strasbourg",
|
262 |
262 |
]
|
263 |
263 |
# check additional attributes
|
264 |
264 |
assert [x['numero'] for x in resp.json['data']] == ['33', '19', '29']
|
265 |
265 |
|
|
266 |
# check operators are removed
|
|
267 |
params['q'] = 'please, do NOT send boolean operators like And, OR and nOt'
|
|
268 |
resp = app.get(endpoint, params=params, status=200)
|
|
269 |
assert mocked_get.call_args[1]['params']['q'] == 'please do send boolean operators like'
|
|
270 |
|
|
271 |
params['q'] = 'field operators are almost ignored too:, -, ==, >, <, >=, <=, [start_date TO end_date]'
|
|
272 |
resp = app.get(endpoint, params=params, status=200)
|
|
273 |
assert (
|
|
274 |
mocked_get.call_args[1]['params']['q']
|
|
275 |
== 'field operators are almost ignored too start_date TO end_date'
|
|
276 |
)
|
|
277 |
|
266 |
278 |
|
267 |
279 |
@mock.patch('passerelle.utils.Request.get')
|
268 |
280 |
def test_search_using_id(mocked_get, app, connector):
|
269 |
281 |
endpoint = tests.utils.generic_endpoint_url('opendatasoft', 'search', slug=connector.slug)
|
270 |
282 |
assert endpoint == '/opendatasoft/my_connector/search'
|
271 |
283 |
params = {
|
272 |
284 |
'dataset': 'referentiel-adresse-test',
|
273 |
285 |
'text_template': '{{numero}} {{nom_rue}} {{nom_commun}}',
|
... | ... | |
327 |
339 |
mocked_get.return_value = tests.utils.FakedResponse(content=FAKED_CONTENT_Q_SEARCH, status_code=200)
|
328 |
340 |
resp = app.get(endpoint, params=params, status=200)
|
329 |
341 |
assert mocked_get.call_args[1]['params'] == {
|
330 |
342 |
'apikey': 'my_secret',
|
331 |
343 |
'dataset': 'referentiel-adresse-test',
|
332 |
344 |
'refine.source': ['Ville et Eurométropole de Strasbourg'],
|
333 |
345 |
'exclude.numero': ['42', '43'],
|
334 |
346 |
'rows': 3,
|
335 |
|
'q': "rue de l'aubepine",
|
|
347 |
'q': "rue de aubepine",
|
336 |
348 |
}
|
337 |
349 |
assert not resp.json['err']
|
338 |
350 |
assert len(resp.json['data']) == 3
|
339 |
351 |
# check order is kept
|
340 |
352 |
assert [x['id'] for x in resp.json['data']] == [
|
341 |
353 |
'e00cf6161e52a4c8fe510b2b74d4952036cb3473',
|
342 |
354 |
'7cafcd5c692773e8b863587b2d38d6be82e023d8',
|
343 |
355 |
'0984a5e1745701f71c91af73ce764e1f7132e0ff',
|
344 |
|
-
|