Commit f1507866 authored by Romain Courteaud's avatar Romain Courteaud

erp5_hal_json_style: cast select_list before handling group_by

parent c10ed1da
...@@ -1641,6 +1641,12 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1641,6 +1641,12 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
count_method = source_field.get_value('count_method') count_method = source_field.get_value('count_method')
has_listbox_a_count_method = (count_method != "") and (count_method.getMethodName() != list_method) has_listbox_a_count_method = (count_method != "") and (count_method.getMethodName() != list_method)
# Cast to list if only one element is provided
if select_list is None:
select_list = []
elif same_type(select_list, ""):
select_list = [select_list]
# hardcoded responses for site and portal objects (which are not Documents!) # hardcoded responses for site and portal objects (which are not Documents!)
# we let the flow to continue because the result of a list_method call can # we let the flow to continue because the result of a list_method call can
# be similar - they can in practice return anything # be similar - they can in practice return anything
...@@ -1777,12 +1783,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -1777,12 +1783,6 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
REQUEST.set(k, v) REQUEST.set(k, v)
search_result_iterable = callable_list_method(**catalog_kw) search_result_iterable = callable_list_method(**catalog_kw)
# Cast to list if only one element is provided
if select_list is None:
select_list = []
elif same_type(select_list, ""):
select_list = [select_list]
# extract form field definition into `editable_field_dict` # extract form field definition into `editable_field_dict`
editable_field_dict = {} editable_field_dict = {}
url_column_dict = {} url_column_dict = {}
......
...@@ -1461,9 +1461,9 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin): ...@@ -1461,9 +1461,9 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
def test_getHateoas_group_by_param(self): def test_getHateoas_group_by_param(self):
fake_request = do_fake_request("GET") fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="search", result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(REQUEST=fake_request, mode="search",
select_list=['count(*)'], select_list='count(*)',
query='portal_type:"Base Category"', query='portal_type:"Base Category"',
group_by=["portal_type"]) group_by="portal_type")
self.assertEquals(fake_request.RESPONSE.status, 200) self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'), self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json" "application/hal+json"
...@@ -1476,7 +1476,7 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin): ...@@ -1476,7 +1476,7 @@ class TestERP5Document_getHateoas_mode_search(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_query'], 'portal_type:"Base Category"') self.assertEqual(result_dict['_query'], 'portal_type:"Base Category"')
self.assertEqual(result_dict['_local_roles'], None) self.assertEqual(result_dict['_local_roles'], None)
self.assertEqual(result_dict['_select_list'], ['count(*)']) self.assertEqual(result_dict['_select_list'], ['count(*)'])
self.assertEqual(result_dict['_group_by'], ["portal_type"]) self.assertEqual(result_dict['_group_by'], "portal_type")
self.assertEqual(result_dict['_sort_on'], None) self.assertEqual(result_dict['_sort_on'], None)
self.assertEqual(len(result_dict['_embedded']['contents']), 1) self.assertEqual(len(result_dict['_embedded']['contents']), 1)
......
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