Commit 43ea8c0d authored by Romain Courteaud's avatar Romain Courteaud

erp5_hal_json_style: keep group_by parameters in the select list

parent 2430e032
......@@ -1865,7 +1865,7 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
catalog_kw['group_by_list'] = [str(group_by)]
# Include select, as user may want to count
# For now, consider only functions, for example, count(column_name) or COUNT(column name) or count(*)
catalog_kw["select_list"] = [x for x in select_list if re.match(r"^\D+\(.*\)$", x)]
catalog_kw["select_list"] = [x for x in select_list if ((x in catalog_kw['group_by_list']) or re.match(r"^\D+\(.*\)$", x))]
if limit:
catalog_kw["limit"] = limit
......
......@@ -1455,6 +1455,34 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
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',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoas_select_list_keep_group_by(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(*)",
"indexation_timestamp"],
group_by="indexation_timestamp"
)
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(*)", "indexation_timestamp"])
self.assertNotEqual(result_dict['_embedded']['contents'][0]["indexation_timestamp"], None)
self.assertEqual(result_dict['_embedded']['contents'][0]["count(*)"], 1)
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@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