Commit 109e616f authored by Romain Courteaud's avatar Romain Courteaud

[erp5_hal_json_style] Add unit tests

Ensure that the data format returned is stable.
By default, imit the number of documents returned by the search.
Do not return document properties outside the form rendering.
Minor bug fixes.
parent 47e57367
...@@ -76,7 +76,7 @@ return context.ERP5Document_getHateoas(\n ...@@ -76,7 +76,7 @@ return context.ERP5Document_getHateoas(\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None, list_method=None</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, list_method=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
...@@ -377,7 +377,11 @@ def renderForm(form, response_dict):\n ...@@ -377,7 +377,11 @@ def renderForm(form, response_dict):\n
for field in form.get_fields_in_group(group[\'goid\']):\n for field in form.get_fields_in_group(group[\'goid\']):\n
# field_list.append((field.id, renderRawField(field)))\n # field_list.append((field.id, renderRawField(field)))\n
if field.get_value("enabled"):\n if field.get_value("enabled"):\n
try:\n
response_dict[field.id] = renderField(field)\n response_dict[field.id] = renderField(field)\n
except AttributeError:\n
# Do not crash if field configuration is wrong.\n
pass\n
\n \n
# for field_group in field.form.get_groups():\n # for field_group in field.form.get_groups():\n
# traversed_document.log("Field group: " + field_group)\n # traversed_document.log("Field group: " + field_group)\n
...@@ -658,6 +662,7 @@ elif (mode == \'root\') or (mode == \'traverse\'):\n ...@@ -658,6 +662,7 @@ elif (mode == \'root\') or (mode == \'traverse\'):\n
\n \n
# Include properties in document JSON\n # Include properties in document JSON\n
# XXX Extract from renderer form?\n # XXX Extract from renderer form?\n
"""\n
for group in renderer_form.Form_getGroupTitleAndId():\n for group in renderer_form.Form_getGroupTitleAndId():\n
for field in renderer_form.get_fields_in_group(group[\'goid\']):\n for field in renderer_form.get_fields_in_group(group[\'goid\']):\n
field_id = field.id\n field_id = field.id\n
...@@ -671,6 +676,7 @@ elif (mode == \'root\') or (mode == \'traverse\'):\n ...@@ -671,6 +676,7 @@ elif (mode == \'root\') or (mode == \'traverse\'):\n
# Serialize DateTime\n # Serialize DateTime\n
property_value = property_value.rfc822()\n property_value = property_value.rfc822()\n
result_dict[property_name] = property_value \n result_dict[property_name] = property_value \n
"""\n
\n \n
##############\n ##############\n
# XXX Custom slapos code\n # XXX Custom slapos code\n
...@@ -797,7 +803,9 @@ elif mode == \'search\':\n ...@@ -797,7 +803,9 @@ elif mode == \'search\':\n
# else:\n # else:\n
\n \n
# Cast to list if only one element is provided\n # Cast to list if only one element is provided\n
if same_type(select_list, ""):\n if select_list is None:\n
select_list = []\n
elif same_type(select_list, ""):\n
select_list = [select_list]\n select_list = [select_list]\n
\n \n
for sql_document in sql_list:\n for sql_document in sql_list:\n
...@@ -844,7 +852,7 @@ return json.dumps(result_dict, indent=2)\n ...@@ -844,7 +852,7 @@ return json.dumps(result_dict, indent=2)\n
</item> </item>
<item> <item>
<key> <string>_params</string> </key> <key> <string>_params</string> </key>
<value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=None, form=None, relative_url=None, restricted=0, list_method=None</string> </value> <value> <string>REQUEST=None, response=None, view=None, mode=\'root\', query=None, select_list=None, limit=10, form=None, relative_url=None, restricted=0, list_method=None</string> </value>
</item> </item>
<item> <item>
<key> <string>id</string> </key> <key> <string>id</string> </key>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="Test Component" module="erp5.portal_type"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_recorded_property_dict</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>default_reference</string> </key>
<value> <string>testHalJsonStyle</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testHalJsonStyle</string> </value>
</item>
<item>
<key> <string>portal_type</string> </key>
<value> <string>Test Component</string> </value>
</item>
<item>
<key> <string>sid</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>text_content_error_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple/>
</value>
</item>
<item>
<key> <string>version</string> </key>
<value> <string>erp5</string> </value>
</item>
<item>
<key> <string>workflow_history</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary/>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="PersistentMapping" module="Persistence.mapping"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>data</string> </key>
<value>
<dictionary>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAQ=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="4" aka="AAAAAAAAAAQ=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.patches.WorkflowTool"/>
</pickle>
<pickle>
<tuple>
<none/>
<list>
<dictionary>
<item>
<key> <string>action</string> </key>
<value> <string>validate</string> </value>
</item>
<item>
<key> <string>validation_state</string> </key>
<value> <string>validated</string> </value>
</item>
</dictionary>
</list>
</tuple>
</pickle>
</record>
</ZopeData>
test.erp5.testHalJsonStyle
\ No newline at end of file
erp5_ui_test_core
erp5_ui_test
\ No newline at end of file
...@@ -149,7 +149,8 @@ ...@@ -149,7 +149,8 @@
\n \n
return gadget.jio_allDocs({\n return gadget.jio_allDocs({\n
"query": \'meta_type:"ERP5 Folder" AND id:"%_module"\',\n "query": \'meta_type:"ERP5 Folder" AND id:"%_module"\',\n
"select_list": ["title", "business_application_title"]\n "select_list": ["title", "business_application_title"],\n
"limit": 1000\n
})\n })\n
.push(function (result) {\n .push(function (result) {\n
var result_list = [],\n var result_list = [],\n
...@@ -355,7 +356,7 @@ ...@@ -355,7 +356,7 @@
</item> </item>
<item> <item>
<key> <string>actor</string> </key> <key> <string>actor</string> </key>
<value> <string>super_sven</string> </value> <value> <string>romain</string> </value>
</item> </item>
<item> <item>
<key> <string>comment</string> </key> <key> <string>comment</string> </key>
...@@ -369,7 +370,7 @@ ...@@ -369,7 +370,7 @@
</item> </item>
<item> <item>
<key> <string>serial</string> </key> <key> <string>serial</string> </key>
<value> <string>940.1897.57739.49578</string> </value> <value> <string>940.11553.26313.55261</string> </value>
</item> </item>
<item> <item>
<key> <string>state</string> </key> <key> <string>state</string> </key>
...@@ -387,7 +388,7 @@ ...@@ -387,7 +388,7 @@
</tuple> </tuple>
<state> <state>
<tuple> <tuple>
<float>1420236486.36</float> <float>1425475569.42</float>
<string>GMT</string> <string>GMT</string>
</tuple> </tuple>
</state> </state>
......
...@@ -80,7 +80,7 @@ else:\n ...@@ -80,7 +80,7 @@ else:\n
response.setHeader("X-Content-Type-Options", "nosniff")\n response.setHeader("X-Content-Type-Options", "nosniff")\n
\n \n
# Only fetch code (html, js, css, image) and data from this ERP5, to prevent any data leak as the web site do not control the gadget\'s code\n # Only fetch code (html, js, css, image) and data from this ERP5, to prevent any data leak as the web site do not control the gadget\'s code\n
response.setHeader("Content-Security-Policy", "default-src \'none\'; img-src \'self\' data:; media-src \'self\'; connect-src \'self\'; script-src \'self\' \'unsafe-eval\'; font-src netdna.bootstrapcdn.com; style-src \'self\' netdna.bootstrapcdn.com \'unsafe-inline\' data:; frame-src \'self\' data:")\n response.setHeader("Content-Security-Policy", "default-src \'none\'; img-src \'self\' data:; media-src \'self\'; connect-src \'self\' mail.tiolive.com; script-src \'self\' \'unsafe-eval\'; font-src netdna.bootstrapcdn.com; style-src \'self\' netdna.bootstrapcdn.com \'unsafe-inline\' data:; frame-src \'self\' data:")\n
\n \n
response.setHeader(\'Content-Type\', \'text/html\')\n response.setHeader(\'Content-Type\', \'text/html\')\n
\n \n
......
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