Commit be124a78 authored by Tomáš Peterka's avatar Tomáš Peterka Committed by Tomáš Peterka

[renderjs_ui_test] Test multilist field with default value 0:int

parent 133b8ed7
"""(Re)Sets properties of chosen Fields in Foo_viewDummyMultiListFieldDialog.
Use this in your tests to alter for example Float Field configuration
instead of copy&pasting new form and changing such property manualy.
Usage: input parameters are supposed to have key <field-name>__<property_name> (please
note double underscore being separator). Those field/property combination will get
propagated into the view IF we already have default value for it.
To modify TALES expression, add "_tales" in the property name as shown in the example below.
Example: in your test, call ${base_url}/FooViewDummyMultiListFieldDialog_setFieldPropertyList?your_dummy__items=first%7CFirst%20second%7CSecond&your_dummy__default_tales=python%3A%20%5B%5D
"""
portal = context.getPortalObject()
form = portal.Foo_viewDummyMultiListFieldDialog
request = context.REQUEST
if not property_dict:
# script called via URL receives its parameters in REQUEST.form
property_dict.update(request.form)
field_default = {
'description': '',
'css_class': '',
'alternate_name': '',
'enabled': 'checked',
'editable': 'checked',
'required': '',
'unicode': '',
'hidden': '',
'external_validator': '',
}
default = {
'your_dummy': dict(
title='Your Dummy',
default="",
items="""A | a
B | b""",
view_separator='<br />',
size='5',
extra='',
extra_item='',
**field_default
)
}
# Copy structure of fields but set all TALES expressions to empty
"""
tales_default = {field_name: {} for field_name in default}
"""
tales_default = {}
for field_name in default:
tales_default[field_name] = {prop_name: '' for prop_name in default[field_name]}
# update defaults with user defined values
for composed_key, value in property_dict.items():
field_dict = default
field_name, property_name = composed_key.split('__')
if property_name.endswith('_tales'):
property_name = property_name[:-len('_tales')]
field_dict = tales_default
# to allow overriding only default values
# throw an exception in case of non-existence of the field/property
assert property_name in default[field_name], 'Uknown field {} and property {} for {!s}'.format(field_name, property_name, field_dict)
field_dict[field_name][property_name] = value
# update actual fields
for field_name in default:
field = form.get_field(field_name)
field.manage_edit(
{'field_' + key: value
for key, value in default[field_name].items()}
)
# update actual fields TALES expressions
for field_name in tales_default:
field = form.get_field(field_name)
field.manage_tales( # this function actually eats ValidationError exceptions
{'field_' + key: value
for key, value in tales_default[field_name].items()}
)
return 'Set Successfully.'
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>**property_dict</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>FooViewDummyMultiListFieldDialog_setFieldPropertyList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -22,6 +22,16 @@ ...@@ -22,6 +22,16 @@
<td>Reset Successfully.</td> <td>Reset Successfully.</td>
<td></td> <td></td>
</tr> </tr>
<tr>
<td>open</td>
<td>${base_url}/FooViewDummyMultiListFieldDialog_setFieldPropertyList</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Set Successfully.</td>
<td></td>
</tr>
<!-- Initialize --> <!-- Initialize -->
<tr> <tr>
......
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="ZopePageTemplate" module="Products.PageTemplates.ZopePageTemplate"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>content_type</string> </key>
<value> <string>text/html</string> </value>
</item>
<item>
<key> <string>expand</string> </key>
<value> <int>0</int> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>testIntegersMultiListField</string> </value>
</item>
<item>
<key> <string>output_encoding</string> </key>
<value> <string>utf-8</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <unicode></unicode> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
<html xmlns:tal="http://xml.zope.org/namespaces/tal"
xmlns:metal="http://xml.zope.org/namespaces/metal">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Test RenderJS UI MultiList</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">Test int:0 in items and as default</td></tr>
</thead><tbody>
<tal:block metal:use-macro="here/Zuite_CommonTemplate/macros/init" />
<!-- Clean Up -->
<tr>
<td>open</td>
<td>${base_url}/bar_module/ListBoxZuite_reset</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Reset Successfully.</td>
<td></td>
</tr>
<tr>
<td>open</td>
<td>${base_url}/foo_module/Foo_createObjects?num:int=1&amp;start:int=1</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Created Successfully.</td>
<td></td>
</tr>
<tr><th colspan="3">Set MultiList's items to python:[("0", 0), ("1", 1)] and default=python:0</th></tr>
<tr>
<td>open</td>
<td>${base_url}/FooViewDummyMultiListFieldDialog_setFieldPropertyList?your_dummy__default_tales=python%3A0&amp;your_dummy__items_tales=python%3A%20%5B(%220%22%2C%200)%2C(%221%22%2C1)%5D</td>
<td></td>
</tr>
<tr>
<td>assertTextPresent</td>
<td>Set Successfully.</td>
<td></td>
</tr>
<!-- Initialize -->
<tr>
<td>open</td>
<td>${base_url}/web_site_module/renderjs_runner/#/foo_module/1</td>
<td></td>
</tr>
<!-- Go to test form -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/go_to_foo_dummy_multilist_field_report_view" />
<tr><td cellspan="3">The option 1 must be selected</td></tr>
<tr>
<td>waitForElementPresent</td>
<td>//div[contains(@data-gadget-url, "gadget_erp5_field_multilist.html")]/div[1]//option[@value="0" and @selected="selected"]</td>
<td></td>
</tr>
<!-- Run test form & check -->
<tal:block metal:use-macro="here/Zuite_CommonTemplateForRenderjsUi/macros/submit_dialog" />
<tr>
<td>waitForTextPresent</td>
<td>repr [0]</td>
<td></td>
</tr>
</tbody></table>
</body>
</html>
\ No newline at end of file
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