Commit adfe6e53 authored by Gabriel Monnerat's avatar Gabriel Monnerat

erp5_hal_json_style: consider only functions and avoid methods in select_list

parent ccdf3ddb
Pipeline #15582 failed with stage
in 0 seconds
...@@ -1864,7 +1864,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1864,7 +1864,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
else: else:
catalog_kw['group_by_list'] = [str(group_by)] catalog_kw['group_by_list'] = [str(group_by)]
# Include select, as user may want to count # Include select, as user may want to count
catalog_kw["select_list"] = select_list # For now, consider only functions, for example, count(column_name) or COUNT(column name)
catalog_kw["select_list"] = [x for x in select_list if re.match(r"^\D+\(\w+\)$", x)]
if limit: if limit:
catalog_kw["limit"] = limit catalog_kw["limit"] = limit
......
...@@ -1427,6 +1427,34 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin): ...@@ -1427,6 +1427,34 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
# No count if not in the listbox context currently # No count if not in the listbox context currently
self.assertEqual(result_dict['_embedded'].get('count', None), None) self.assertEqual(result_dict['_embedded'].get('count', None), None)
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_select_list_avoid_accessor(self):
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
query="id:=hateoas AND uid:=%s" % self.portal.web_site_module.hateoas.getUid(),
select_list=["count(validation_state)",
"getTranslatedValidationStateTitle",],
group_by="validation_state"
)
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
self.assertEqual(result_dict['_links']['self'], {"href": "http://example.org/bar"})
self.assertEqual(result_dict['_select_list'],
["count(validation_state)", "getTranslatedValidationStateTitle"])
self.assertEqual(result_dict['_embedded']['contents'][0]["getTranslatedValidationStateTitle"], "Published")
self.assertEqual(result_dict['_embedded']['contents'][0]["count(validation_state)"], 1)
@simulate('Base_getRequestUrl', '*args, **kwargs', @simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"') 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', @simulate('Base_getRequestHeader', '*args, **kwargs',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment