Commit 6cf2326c authored by Tomáš Peterka's avatar Tomáš Peterka

[hal_json_style] Add test for incosistent rendering of search-enabled gadgets

parent 5619e751
...@@ -402,6 +402,9 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key ...@@ -402,6 +402,9 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
for name, title in (selection_params.get('selection_sort_order', []) for name, title in (selection_params.get('selection_sort_order', [])
or field.get_value("sort_columns")) or field.get_value("sort_columns"))
if sql_catalog.isValidColumn(name)] or search_column_list if sql_catalog.isValidColumn(name)] or search_column_list
# portal_type list can be overriden by selection too
# since it can be intentionally empty we don't override with non-empty field value
portal_type_list = selection_params.get("portal_type", field.get_value('portal_types'))
# requirement: get only sortable/searchable columns which are already displayed in listbox # requirement: get only sortable/searchable columns which are already displayed in listbox
# see https://lab.nexedi.com/nexedi/erp5/blob/HEAD/product/ERP5Form/ListBox.py#L1004 # see https://lab.nexedi.com/nexedi/erp5/blob/HEAD/product/ERP5Form/ListBox.py#L1004
...@@ -410,10 +413,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key ...@@ -410,10 +413,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
default_params = dict(field.get_value('default_params')) # default_params is a list of tuples default_params = dict(field.get_value('default_params')) # default_params is a list of tuples
default_params['ignore_unknown_columns'] = True default_params['ignore_unknown_columns'] = True
# we abandoned Selections in RJS thus we mix selection query parameters into # we abandoned Selections in RJS thus we mix selection query parameters into
# listbox's default parameters # listbox's default parameters
if selection_params is not None:
default_params.update(selection_params) default_params.update(selection_params)
lines = field.get_value('lines') lines = field.get_value('lines')
...@@ -423,9 +424,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key ...@@ -423,9 +424,8 @@ def renderField(traversed_document, field, form, value=None, meta_type=None, key
# in that case we prefer non_empty version # in that case we prefer non_empty version
list_method_query_dict = default_params.copy() list_method_query_dict = default_params.copy()
if not list_method_query_dict.get("portal_type", []): if not list_method_query_dict.get("portal_type", []):
list_method_query_dict["portal_type"] = [x for x, _ in field.get_value('portal_types')] list_method_query_dict["portal_type"] = [x for x, _ in portal_type_list]
list_method_custom = None list_method_custom = None
portal_type_list = list_method_query_dict["portal_type"]
# Search for non-editable documents - all reports goes here # Search for non-editable documents - all reports goes here
# Reports have custom search scripts which wants parameters from the form # Reports have custom search scripts which wants parameters from the form
......
...@@ -630,6 +630,42 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin): ...@@ -630,6 +630,42 @@ class TestERP5Document_getHateoas_mode_traverse(ERP5HALJSONStyleSkinsMixin):
self.assertEqual(result_dict['_embedded']['_view']['_actions']['put']['method'], 'POST') self.assertEqual(result_dict['_embedded']['_view']['_actions']['put']['method'], 'POST')
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@changeSkin('Hal')
def test_getHateoasDocument_listbox_vs_relation_inconsistency(self):
"""Purpose of this test is to point to inconsistencies in search-enabled field rendering.
ListBox gets its Portal Types in `portal_type` as list of tuples whether
Relation Input receives `portal_types` and `translated_portal_types`
"""
document = self._makeDocument()
# Drop editable permission
document.manage_permission('Modify portal content', [], 0)
document.Foo_view.listbox.ListBox_setPropertyList(
field_title = 'Foo Lines',
field_list_method = 'objectValues',
field_portal_types = 'Foo Line | Foo Line',
)
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="traverse",
relative_url=document.getRelativeUrl(),
view="view")
self.assertEquals(fake_request.RESPONSE.status, 200)
self.assertEquals(fake_request.RESPONSE.getHeader('Content-Type'),
"application/hal+json"
)
result_dict = json.loads(result)
# ListBox rendering of allowed Portal Types
self.assertEqual(result_dict['_embedded']['_view']['listbox']['portal_type'], [['Foo Line', 'Foo Line']])
# Relation Input rendering of allowed Portal Types
self.assertEqual(result_dict['_embedded']['_view']['my_foo_category_title']['portal_types'], ['Category'])
self.assertEqual(result_dict['_embedded']['_view']['my_foo_category_title']['translated_portal_types'], ['Category'])
@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