astech: add endpoint to get view data (#82416)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
2bbc835787
commit
4789f1e1ff
|
@ -475,3 +475,29 @@ class ASTech(BaseResource, HTTPResource):
|
|||
column['id'] = column['code']
|
||||
column['text'] = column['des']
|
||||
return {'data': columns}
|
||||
|
||||
@endpoint(
|
||||
name='get-view-data',
|
||||
display_order=3,
|
||||
description=_('Get view data'),
|
||||
display_category=_('Referential'),
|
||||
datasource=True,
|
||||
parameters={
|
||||
'code': {
|
||||
'description': _('View code'),
|
||||
'example_value': 'ASTECH_BIENS',
|
||||
},
|
||||
'id_column': {'description': _('Name of column contaning the id'), 'example_value': 'BIEN_ID'},
|
||||
'text_column': {
|
||||
'description': _('Name of column contaning the label'),
|
||||
'example_value': 'DESIGNATION',
|
||||
},
|
||||
},
|
||||
)
|
||||
def get_view_data(self, request, code, id_column, text_column):
|
||||
endpoint = 'apicli/data/%s/results' % code
|
||||
results = self.call(endpoint, json={'data': {'filters': []}})
|
||||
for result in results:
|
||||
result['id'] = result[id_column]
|
||||
result['text'] = result[text_column]
|
||||
return {'data': results}
|
||||
|
|
|
@ -88,6 +88,11 @@ COLUMNS_RESPONSE = """
|
|||
{"code":"ANCETREID","des":"Identifiant de l\u0027anc\u00eatre du bien","type":"NUM","length":""}]}
|
||||
"""
|
||||
|
||||
RESULTS_RESPONSE = """[{"BIEN_ID": "2219", "CODE_BIEN": "AC-849-YE", "DESIGNATION": "RENAULT KANGOO"},
|
||||
{"BIEN_ID": "2220", "CODE_BIEN": "AC-933-EA", "DESIGNATION": "RENAULT MASTER"},
|
||||
{"BIEN_ID": "2221", "CODE_BIEN": "AC-955-SE", "DESIGNATION": "RENAULT KANGOO"}]
|
||||
"""
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.request')
|
||||
def test_connections(mocked_request, app, setup):
|
||||
|
@ -483,3 +488,36 @@ def test_view_columns(mocked_auth, mocked_request, app, setup):
|
|||
for r in response.json['data']:
|
||||
assert 'id' in r
|
||||
assert 'text' in r
|
||||
|
||||
|
||||
@mock.patch('passerelle.utils.Request.request')
|
||||
@mock.patch('passerelle.apps.astech.models.ASTech.get_authorization')
|
||||
def test_view_data(mocked_auth, mocked_request, app, setup):
|
||||
mocked_auth.return_value = {'access_token': '4242', 'connection_id': 'TEST'}
|
||||
|
||||
endpoint = reverse(
|
||||
'generic-endpoint',
|
||||
kwargs={'connector': 'astech', 'slug': setup.slug, 'endpoint': 'get-view-data'},
|
||||
)
|
||||
mocked_request.return_value = tests.utils.FakedResponse(content=RESULTS_RESPONSE, status_code=200)
|
||||
response = app.get(
|
||||
endpoint, params={'code': 'ASTECH_BIENS', 'id_column': 'BIEN_ID', 'text_column': 'DESIGNATION'}
|
||||
)
|
||||
assert mocked_request.call_args[0][0] == 'post'
|
||||
assert mocked_request.call_args[0][1].endswith('apicli/data/ASTECH_BIENS/results')
|
||||
assert response.json['data']
|
||||
for r in response.json['data']:
|
||||
assert 'id' in r
|
||||
assert 'text' in r
|
||||
|
||||
response = app.get(
|
||||
endpoint,
|
||||
params={'code': 'ASTECH_BIENS', 'id_column': 'BIEN_ID', 'text_column': 'DESIGNATION', 'id': 2221},
|
||||
)
|
||||
assert len(response.json['data']) == 1
|
||||
|
||||
response = app.get(
|
||||
endpoint,
|
||||
params={'code': 'ASTECH_BIENS', 'id_column': 'BIEN_ID', 'text_column': 'DESIGNATION', 'q': 'KANGOO'},
|
||||
)
|
||||
assert len(response.json['data']) == 2
|
||||
|
|
Loading…
Reference in New Issue