matrix42: add filter possibility on fragment endpoint (#83103)
gitea/passerelle/pipeline/head This commit looks good
Details
gitea/passerelle/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ba58f183ed
commit
264550e363
|
@ -115,9 +115,12 @@ class Matrix42(BaseResource, HTTPResource):
|
|||
'example_value': '{{ ID }}',
|
||||
},
|
||||
'search_column': {
|
||||
'description': _('Column for "q" search'),
|
||||
'description': _('Search column: "where search_column LIKE \'%q%\'"'),
|
||||
},
|
||||
'q': {'description': _('Search text in search column')},
|
||||
'search_filter': {
|
||||
'description': _('Search filter: "where search_column LIKE \'%q%\' and search_filter"'),
|
||||
},
|
||||
'q': {'description': _('Search text (needs a search_column)')},
|
||||
'id': {'description': _('Get the whole fragment with this ID')},
|
||||
},
|
||||
)
|
||||
|
@ -129,6 +132,7 @@ class Matrix42(BaseResource, HTTPResource):
|
|||
template=None,
|
||||
id_template=None,
|
||||
search_column=None,
|
||||
search_filter=None,
|
||||
q=None,
|
||||
id=None,
|
||||
):
|
||||
|
@ -159,6 +163,8 @@ class Matrix42(BaseResource, HTTPResource):
|
|||
params['columns'] = columns
|
||||
if q is not None:
|
||||
params['where'] = "%s LIKE '%%%s%%'" % (search_column, q.replace("'", "''"))
|
||||
if search_filter:
|
||||
params['where'] += ' AND %s' % search_filter
|
||||
results = self.request(uri, params=params).get('Result') or []
|
||||
for result in results:
|
||||
add_id_and_text(result)
|
||||
|
|
|
@ -111,6 +111,26 @@ def test_matrix42_fragment(mocked_request, app, matrix42):
|
|||
assert resp.json['data'][0]['id'] == 'id:a9386c3e-cb7a-ed11-a3bb-000d3aaa0172'
|
||||
assert resp.json['data'][0]['text'] == 'ds:User1, Leo'
|
||||
|
||||
# filter more
|
||||
params['search_filter'] = '1=1'
|
||||
mocked_request.reset_mock()
|
||||
mocked_request.side_effect = [
|
||||
FakedResponse(content=TOKEN, status_code=200),
|
||||
FakedResponse(content=USERS, status_code=200),
|
||||
]
|
||||
resp = app.get(endpoint, params=params, status=200)
|
||||
_, get_users = mocked_request.call_args_list
|
||||
assert get_users[0] == (
|
||||
'GET',
|
||||
'https://matrix42.example.net/api/data/fragments/SPSUserClassBase/schema-info',
|
||||
)
|
||||
assert get_users[1]['params'] == {
|
||||
'columns': 'DisplayString',
|
||||
'where': "DisplayString LIKE '%User%' AND 1=1",
|
||||
}
|
||||
assert resp.json['err'] == 0
|
||||
assert len(resp.json['data']) == 2
|
||||
|
||||
# get one user
|
||||
del params['q']
|
||||
params['id'] = 'a9386c3e-cb7a-ed11-a3bb-000d3aaa0172'
|
||||
|
|
Loading…
Reference in New Issue