Commit 00958618 authored by Ayush Tiwari's avatar Ayush Tiwari

[hal_json_style]: Add tests for new JSON format and url value in hal_json_style

parent 53da1cd7
...@@ -1187,6 +1187,151 @@ return context.getPortalObject().foo_module.contentValues() ...@@ -1187,6 +1187,151 @@ return context.getPortalObject().foo_module.contentValues()
# There is a count method on this listbox # There is a count method on this listbox
self.assertEqual(result_dict['_embedded']['count'], 0) self.assertEqual(result_dict['_embedded']['count'], 0)
@simulate('Base_getRequestUrl', '*args, **kwargs',
'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', """
if url_dict:
jio_key = context.getRelativeUrl()
return {
'command': 'push_history',
'options': {
'jio_key': jio_key,
'editable': False
},
'view_kw': {
'view': 'metadata',
'jio_key': jio_key,
'extra_param_json': {'reset': 1},
}
}
return '%s/Base_viewMetadata?reset:int=1' % context.getRelativeUrl()
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_different_view(self):
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['modification_date | Base_getUrl',])
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
list_method='Test_listProducts',
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 URL value
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['url_value']['command'], 'push_history')
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['url_value']['options']['jio_key'], self.portal.foo_module.contentValues()[0].getRelativeUrl())
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['url_value']['options']['editable'], False)
self.assertIn('metadata', result_dict['_embedded']['contents'][0]['modification_date']['url_value']['options']['view'])
self.assertIn('extra_param_json', result_dict['_embedded']['contents'][0]['modification_date']['url_value']['options']['view'])
self.assertIn(self.portal.foo_module.contentValues()[0].getRelativeUrl().replace("/", "%2F"), result_dict['_embedded']['contents'][0]['modification_date']['url_value']['options']['view'])
# Test the field_gadget_param
self.assertTrue(result_dict['_embedded']['contents'][0]['modification_date']['field_gadget_param'])
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['field_gadget_param']['type'], 'DateTimeField')
# Reset the url_columns of the listbox
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_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', """
url = "https://officejs.com"
if url_dict:
return {'command': 'raw',
'options': {
'url': url
}
}
return url
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_absolute_url_with_field_rendering(self):
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['modification_date | Base_getUrl',])
fake_request = do_fake_request("GET")
result = self.portal.web_site_module.hateoas.ERP5Document_getHateoas(
REQUEST=fake_request,
mode="search",
list_method='objectValues',
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 URL value
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['url_value']['command'], 'raw')
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['url_value']['options']['url'], 'https://officejs.com')
# Test the field_gadget_param
self.assertTrue(result_dict['_embedded']['contents'][0]['modification_date']['field_gadget_param'])
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['field_gadget_param']['type'], 'DateTimeField')
# Reset the url_columns of the listbox
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = '')
@simulate('Base_getRequestUrl', '*args, **kwargs',
'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:
return {'command': 'raw',
'options': {
'url': url
}
}
return url
""")
@changeSkin('Hal')
def test_getHateoasDocument_listbox_check_url_column_absolute_url_without_field_rendering(self):
# pass custom list method which expect input arguments
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = ['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='Test_listProducts',
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 URL value
self.assertEqual(result_dict['_embedded']['contents'][0]['title']['url_value']['command'], 'raw')
self.assertEqual(result_dict['_embedded']['contents'][0]['title']['url_value']['options']['url'], 'https://officejs.com')
# Test if the value of the column is with right key
self.assertTrue(result_dict['_embedded']['contents'][0]['title']['default'])
# Test if the field_gadget_param even if there is no url_value
self.assertTrue(result_dict['_embedded']['contents'][0]['modification_date']['field_gadget_param'])
self.assertEqual(result_dict['_embedded']['contents'][0]['modification_date']['field_gadget_param']['type'], 'DateTimeField')
# Test that creation_date doesn't has `url_value` dict in it
self.assertNotIn('url_value', result_dict['_embedded']['contents'][0]['modification_date'])
# Reset the url_columns of the listbox
self.portal.foo_module.FooModule_viewFooList.listbox.ListBox_setPropertyList(
field_url_columns = '')
@simulate('Base_getRequestUrl', '*args, **kwargs', 'return "http://example.org/bar"') @simulate('Base_getRequestUrl', '*args, **kwargs', 'return "http://example.org/bar"')
@simulate('Base_getRequestHeader', '*args, **kwargs', 'return "application/hal+json"') @simulate('Base_getRequestHeader', '*args, **kwargs', 'return "application/hal+json"')
......
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