opendatasoft: publish all fields (#43444)

This commit is contained in:
Frédéric Péters 2020-05-29 09:15:34 +02:00
parent f36a9f2a53
commit 5e08ded212
2 changed files with 32 additions and 44 deletions

View File

@ -80,15 +80,13 @@ class OpenDataSoft(BaseResource):
result = []
for record in result_response.json().get('records'):
data = {}
data['id'] = record.get('recordid')
context = {}
for key, value in record.get('fields').items():
context[key] = force_text(value)
data[key] = value
data['id'] = record.get('recordid')
template = Template(text_template)
data['text'] = template.render(Context(context)).strip()
data['text'] = template.render(Context(data)).strip()
result.append(data)
return {'data': result}
@endpoint(name='q',

View File

@ -212,19 +212,18 @@ def test_search_using_q(mocked_get, app, connector):
resp = app.get(endpoint, params=params, status=200)
assert not resp.json['err']
assert len(resp.json['data']) == 3
# order is keept
assert resp.json['data'][0] == {
'id': 'e00cf6161e52a4c8fe510b2b74d4952036cb3473',
'text': "33 RUE DE L'AUBEPINE Strasbourg"
}
assert resp.json['data'][1] == {
'id': '7cafcd5c692773e8b863587b2d38d6be82e023d8',
'text': "19 RUE DE L'AUBEPINE Lipsheim"
}
assert resp.json['data'][2] == {
'id': '0984a5e1745701f71c91af73ce764e1f7132e0ff',
'text': "29 RUE DE L'AUBEPINE Strasbourg"
}
# check order is kept
assert [x['id'] for x in resp.json['data']] == [
'e00cf6161e52a4c8fe510b2b74d4952036cb3473',
'7cafcd5c692773e8b863587b2d38d6be82e023d8',
'0984a5e1745701f71c91af73ce764e1f7132e0ff']
# check text results
assert [x['text'] for x in resp.json['data']] == [
"33 RUE DE L'AUBEPINE Strasbourg",
"19 RUE DE L'AUBEPINE Lipsheim",
"29 RUE DE L'AUBEPINE Strasbourg"]
# check additional attributes
assert [x['numero'] for x in resp.json['data']] == ['33', '19', '29']
@mock.patch('passerelle.utils.Request.get')
@ -238,12 +237,8 @@ def test_search_using_id(mocked_get, app, connector):
}
mocked_get.return_value = utils.FakedResponse(content=FAKED_CONTENT_ID_SEARCH, status_code=200)
resp = app.get(endpoint, params=params, status=200)
assert resp.json == {
'err': 0,
'data': [{
'id': '7cafcd5c692773e8b863587b2d38d6be82e023d8',
'text': "19 RUE DE L'AUBEPINE Lipsheim"
}]}
assert len(resp.json['data']) == 1
assert resp.json['data'][0]['text'] == "19 RUE DE L'AUBEPINE Lipsheim"
@mock.patch('passerelle.utils.Request.get')
@ -257,19 +252,18 @@ def test_query_q_using_q(mocked_get, app, query):
resp = app.get(endpoint, params=params, status=200)
assert not resp.json['err']
assert len(resp.json['data']) == 3
# order is keept
assert resp.json['data'][0] == {
'id': 'e00cf6161e52a4c8fe510b2b74d4952036cb3473',
'text': "33 RUE DE L'AUBEPINE Strasbourg"
}
assert resp.json['data'][1] == {
'id': '7cafcd5c692773e8b863587b2d38d6be82e023d8',
'text': "19 RUE DE L'AUBEPINE Lipsheim"
}
assert resp.json['data'][2] == {
'id': '0984a5e1745701f71c91af73ce764e1f7132e0ff',
'text': "29 RUE DE L'AUBEPINE Strasbourg"
}
# check order is kept
assert [x['id'] for x in resp.json['data']] == [
'e00cf6161e52a4c8fe510b2b74d4952036cb3473',
'7cafcd5c692773e8b863587b2d38d6be82e023d8',
'0984a5e1745701f71c91af73ce764e1f7132e0ff']
# check text results
assert [x['text'] for x in resp.json['data']] == [
"33 RUE DE L'AUBEPINE Strasbourg",
"19 RUE DE L'AUBEPINE Lipsheim",
"29 RUE DE L'AUBEPINE Strasbourg"]
# check additional attributes
assert [x['numero'] for x in resp.json['data']] == ['33', '19', '29']
@mock.patch('passerelle.utils.Request.get')
@ -280,9 +274,5 @@ def test_query_q_using_id(mocked_get, app, query):
}
mocked_get.return_value = utils.FakedResponse(content=FAKED_CONTENT_ID_SEARCH, status_code=200)
resp = app.get(endpoint, params=params, status=200)
assert resp.json == {
'err': 0,
'data': [{
'id': '7cafcd5c692773e8b863587b2d38d6be82e023d8',
'text': "19 RUE DE L'AUBEPINE Lipsheim"
}]}
assert len(resp.json['data']) == 1
assert resp.json['data'][0]['text'] == "19 RUE DE L'AUBEPINE Lipsheim"