Commit c2c28029 authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Do not generate link for empty value, as it will not be clickable in UI

Tests: do not depend on previous test executions.
parent 082712a1
......@@ -1814,6 +1814,8 @@ def calculateHateoas(is_portal=None, is_site_root=None, traversed_document=None,
key='field_%s_%s' % (editable_field.id, brain_uid))
# Do not generate link for empty value, as it will not be clickable in UI
if default_field_value not in ('', None):
# By default, we won't be generating views in the URL
url_parameter_dict = None
if select in url_column_dict:
......
......@@ -66,8 +66,9 @@ def simulate(script_id, params_string, code_string):
return decorated
return upperWrap
def wipeFolder(folder):
def wipeFolder(folder, commit=True):
folder.deleteContent(list(folder.objectIds()))
if commit:
transaction.commit()
def createIndexedDocument(quantity=1):
......@@ -136,6 +137,8 @@ from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
class ERP5HALJSONStyleSkinsMixin(ERP5TypeTestCase):
def afterSetUp(self):
self.login()
wipeFolder(self.portal.foo_module, commit=False)
def beforeTearDown(self):
transaction.abort()
......@@ -1384,6 +1387,7 @@ return '%s/Base_viewMetadata?reset:int=1' % context.getRelativeUrl()
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_different_view(self):
self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['modification_date | Base_getUrl',])
......@@ -1466,9 +1470,6 @@ return url
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Test_listProducts', '*args, **kwargs', """
return context.getPortalObject().foo_module.contentValues()
""")
@simulate('Base_getUrl', 'url_dict=False, *args, **kwargs', """
url = "https://officejs.com"
if url_dict:
......@@ -1481,6 +1482,7 @@ return url
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_absolute_url_without_field_rendering(self):
self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['title | Base_getUrl',])
......@@ -1489,7 +1491,8 @@ return url
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
list_method='Test_listProducts',
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)
......@@ -1519,11 +1522,9 @@ return url
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Test_listProducts', '*args, **kwargs', """
return context.getPortalObject().foo_module.contentValues()
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_no_url(self):
self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['title|',])
......@@ -1532,7 +1533,8 @@ return context.getPortalObject().foo_module.contentValues()
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
list_method='Test_listProducts',
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)
......@@ -1554,9 +1556,6 @@ return context.getPortalObject().foo_module.contentValues()
'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs',
'return "application/hal+json"')
@simulate('Test_listProducts', '*args, **kwargs', """
return context.getPortalObject().foo_module.contentValues()
""")
@simulate('Base_getUrl', 'url_dict=False, *args, **kwargs', """
url = "https://officejs.com"
if url_dict:
......@@ -1570,6 +1569,7 @@ return url
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_option_parameters(self):
self._makeDocument()
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['title | Base_getUrl',])
......@@ -1578,7 +1578,8 @@ return url
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
list_method='Test_listProducts',
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)
......
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