Commit 4cb13be9 authored by Romain Courteaud's avatar Romain Courteaud

erp5_hal_json_style: add compatibility with URL columns returning None value

parent 5f3489f5
Pipeline #10877 failed with stage
in 0 seconds
...@@ -2039,6 +2039,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None, ...@@ -2039,6 +2039,10 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
selection=catalog_kw['selection'], selection=catalog_kw['selection'],
selection_name=catalog_kw['selection_name'], selection_name=catalog_kw['selection_name'],
column_id=select) column_id=select)
if url_parameter_dict is None:
# url method want to disable URL in xhtml
# Keep compatibility with this simple case
url_parameter_dict = {}
else: else:
if not is_getListItemUrlDict_calculated: if not is_getListItemUrlDict_calculated:
# XXX If only available on brains, maybe better to call on aq_self # XXX If only available on brains, maybe better to call on aq_self
......
...@@ -1874,6 +1874,44 @@ return url ...@@ -1874,6 +1874,44 @@ return url
# Reset the url_columns of the listbox # Reset the url_columns of the listbox
self.portal.foo_module.FooModule_viewFooList.listbox.manage_tales_xmlrpc(dict(url_columns='')) self.portal.foo_module.FooModule_viewFooList.listbox.manage_tales_xmlrpc(dict(url_columns=''))
@simulate('Base_getRequestUrl', '*args, **kwargs',
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Base_getUrl', 'url_dict=False, *args, **kwargs', """
return None
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_returning_None(self):
# variation of test_getHateoasDocument_listbox_check_url_column_no_url here the
# "no url" is done by setting `None` in TALES expression, instead of '' that get
# set by formulator `key | value` syntax.
self._makeDocument()
self.portal.foo_module.FooModule_viewFooList.listbox.manage_tales_xmlrpc(
dict(url_columns='python: [("title", "Base_getUrl"), ]'))
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
list_method='contentValues',
relative_url='foo_module',
select_list=['id', 'title', 'creation_date', 'modification_date'],
form_relative_url='portal_skins/erp5_ui_test/FooModule_viewFooList/listbox')
result_dict = json.loads(result)
# Test the listbox_uid parameter
self.assertEqual(result_dict['_embedded']['contents'][0]['listbox_uid:list']['key'], 'listbox_uid:list')
# Test the URL value
self.assertEqual(result_dict['_embedded']['contents'][0]['title']['url_value'], {})
# Test if the value of the column is with right key
self.assertTrue(result_dict['_embedded']['contents'][0]['title']['default'])
# Reset the url_columns of the listbox
self.portal.foo_module.FooModule_viewFooList.listbox.manage_tales_xmlrpc(dict(url_columns=''))
@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