Commit 342f85b7 authored by Arnaud Fontaine's avatar Arnaud Fontaine

ZODB Components: erp5_core_test: Migrate Unit Tests.

parent b22b277f
...@@ -66,16 +66,16 @@ class TestFieldValueCache(ERP5TypeTestCase): ...@@ -66,16 +66,16 @@ class TestFieldValueCache(ERP5TypeTestCase):
form() form()
# Get form value # Get form value
field = form.my_first_name field = form.my_first_name
id = 'title' id_ = 'title'
from Products.ERP5Form.Form import field_value_cache from Products.ERP5Form.Form import field_value_cache
cache_id = ('ProxyField.get_value', cache_id = ('ProxyField.get_value',
field._p_oid, field._p_oid,
field._p_oid, field._p_oid,
id) id_)
# Make sure cache has field # Make sure cache has field
self.assertTrue(field_value_cache.has_key(cache_id)) self.assertTrue(field_value_cache.has_key(cache_id))
# Make sure cache and field are equal # Make sure cache and field are equal
self.assertEqual(field.get_value(id), field_value_cache[cache_id]) self.assertEqual(field.get_value(id_), field_value_cache[cache_id])
# Call manage_renameObject # Call manage_renameObject
form.manage_renameObject('my_first_name', 'my_first_name2') form.manage_renameObject('my_first_name', 'my_first_name2')
form.manage_renameObject('my_first_name2', 'my_first_name') form.manage_renameObject('my_first_name2', 'my_first_name')
...@@ -86,4 +86,4 @@ class TestFieldValueCache(ERP5TypeTestCase): ...@@ -86,4 +86,4 @@ class TestFieldValueCache(ERP5TypeTestCase):
# Make sure cache has field # Make sure cache has field
self.assertTrue(field_value_cache.has_key(cache_id)) self.assertTrue(field_value_cache.has_key(cache_id))
# Make sure cache and field are equal # Make sure cache and field are equal
self.assertEqual(field.get_value(id), field_value_cache[cache_id]) self.assertEqual(field.get_value(id_), field_value_cache[cache_id])
<?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>default_reference</string> </key>
<value> <string>testFieldValueCache</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5Form.tests.testFieldValueCache</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testFieldValueCache</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">AAAAAAAAAAI=</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>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<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>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -34,13 +34,12 @@ import unittest ...@@ -34,13 +34,12 @@ import unittest
# Initialize ERP5Form Product to load monkey patches # Initialize ERP5Form Product to load monkey patches
from Acquisition import aq_base
from Products.Formulator.FieldRegistry import FieldRegistry from Products.Formulator.FieldRegistry import FieldRegistry
from Products.Formulator.Validator import ValidationError from Products.Formulator.Validator import ValidationError
from Products.Formulator.StandardFields import FloatField, StringField,\ from Products.Formulator.StandardFields import FloatField, StringField,\
DateTimeField, TextAreaField, CheckBoxField, ListField, LinesField, \ DateTimeField, TextAreaField, CheckBoxField, ListField, LinesField, \
MultiListField, IntegerField MultiListField, IntegerField
from Products.Formulator.MethodField import Method, BoundMethod from Products.Formulator.MethodField import Method
from Products.Formulator.TALESField import TALESMethod from Products.Formulator.TALESField import TALESMethod
from Products.ERP5Type.Core.Folder import Folder from Products.ERP5Type.Core.Folder import Folder
...@@ -61,7 +60,7 @@ class TestRenderViewAPI(ERP5TypeTestCase): ...@@ -61,7 +60,7 @@ class TestRenderViewAPI(ERP5TypeTestCase):
return "{Field,Widget}.render_view" return "{Field,Widget}.render_view"
def test_signature(self): def test_signature(self):
for field in FieldRegistry.get_field_classes().itervalues(): for field in FieldRegistry.get_field_classes().itervalues(): # pylint: disable=no-value-for-parameter
self.assertEqual(('self', 'value', 'REQUEST', 'render_prefix'), self.assertEqual(('self', 'value', 'REQUEST', 'render_prefix'),
field.render_view.im_func.func_code.co_varnames) field.render_view.im_func.func_code.co_varnames)
if field is not ProxyField.ProxyField: if field is not ProxyField.ProxyField:
...@@ -643,9 +642,9 @@ class TestProxyField(ERP5TypeTestCase): ...@@ -643,9 +642,9 @@ class TestProxyField(ERP5TypeTestCase):
_setUpDefaultTraversable() _setUpDefaultTraversable()
def addField(self, form, id, title, field_type): def addField(self, form, id_, title, field_type):
form.manage_addField(id, title, field_type) form.manage_addField(id_, title, field_type)
field = getattr(form, id) field = getattr(form, id_)
field._p_oid = makeDummyOid() field._p_oid = makeDummyOid()
return field return field
...@@ -692,8 +691,8 @@ class TestProxyField(ERP5TypeTestCase): ...@@ -692,8 +691,8 @@ class TestProxyField(ERP5TypeTestCase):
def test_get_value_default(self): def test_get_value_default(self):
# If the proxy field is named 'my_id', it will get 'id' # If the proxy field is named 'my_id', it will get 'id'
# property on the context, regardless of the id of the proxified field # property on the context, regardless of the id of the proxified field
original_field = self.addField(self.container.Base_viewProxyFieldLibrary, self.addField(self.container.Base_viewProxyFieldLibrary,
'my_title', 'Title', 'StringField') 'my_title', 'Title', 'StringField')
proxy_field = self.addField(self.container.Base_view, proxy_field = self.addField(self.container.Base_view,
'my_id', 'ID', 'ProxyField') 'my_id', 'ID', 'ProxyField')
proxy_field.manage_edit_xmlrpc(dict(form_id='Base_viewProxyFieldLibrary', proxy_field.manage_edit_xmlrpc(dict(form_id='Base_viewProxyFieldLibrary',
...@@ -789,8 +788,8 @@ class TestProxyField(ERP5TypeTestCase): ...@@ -789,8 +788,8 @@ class TestProxyField(ERP5TypeTestCase):
def test_manage_edit_surcharged_xmlrpc(self): def test_manage_edit_surcharged_xmlrpc(self):
# manage_edit_surcharged_xmlrpc is a method to edit proxyfields # manage_edit_surcharged_xmlrpc is a method to edit proxyfields
# programmatically # programmatically
original_field = self.addField(self.container.Base_viewProxyFieldLibrary, self.addField(self.container.Base_viewProxyFieldLibrary,
'my_string', 'String', 'StringField') 'my_string', 'String', 'StringField')
proxy_field = self.addField(self.container.Base_view, proxy_field = self.addField(self.container.Base_view,
'my_String', '', 'ProxyField') 'my_String', '', 'ProxyField')
proxy_field.manage_edit_xmlrpc(dict(form_id='Base_viewProxyFieldLibrary', proxy_field.manage_edit_xmlrpc(dict(form_id='Base_viewProxyFieldLibrary',
...@@ -809,8 +808,8 @@ class TestProxyField(ERP5TypeTestCase): ...@@ -809,8 +808,8 @@ class TestProxyField(ERP5TypeTestCase):
""" """
Test a case that if proxy field id is same as template field id. Test a case that if proxy field id is same as template field id.
""" """
original_field = self.addField(self.container.Base_viewProxyFieldLibrary, self.addField(self.container.Base_viewProxyFieldLibrary,
'my_string', 'String', 'StringField') 'my_string', 'String', 'StringField')
# Use different id to the template field. # Use different id to the template field.
proxy_field2 = self.addField(self.container.Base_view, proxy_field2 = self.addField(self.container.Base_view,
'my_another_string', '', 'ProxyField') 'my_another_string', '', 'ProxyField')
...@@ -842,8 +841,8 @@ class TestProxyField(ERP5TypeTestCase): ...@@ -842,8 +841,8 @@ class TestProxyField(ERP5TypeTestCase):
not surcharged. not surcharged.
""" """
# create a field # create a field
original_field = self.addField(self.container.Base_viewProxyFieldLibrary, self.addField(self.container.Base_viewProxyFieldLibrary,
'my_title', 'OrigTitle', 'StringField') 'my_title', 'OrigTitle', 'StringField')
field = self.addField(self.container.Base_view, field = self.addField(self.container.Base_view,
'my_dict_test', '', 'ProxyField') 'my_dict_test', '', 'ProxyField')
field.manage_edit_xmlrpc(dict(form_id='Base_viewProxyFieldLibrary', field.manage_edit_xmlrpc(dict(form_id='Base_viewProxyFieldLibrary',
...@@ -961,9 +960,9 @@ class TestFieldValueCache(ERP5TypeTestCase): ...@@ -961,9 +960,9 @@ class TestFieldValueCache(ERP5TypeTestCase):
def test_method_field(self): def test_method_field(self):
field = self.root.form.field field = self.root.form.field
value, cacheable = getFieldValue(field, field, 'external_validator') value, _ = getFieldValue(field, field, 'external_validator')
self.assertEqual(False, value.value is field.values['external_validator']) self.assertEqual(False, value.value is field.values['external_validator'])
self.assertEqual(True, type(value.value) is Method) self.assertEqual(True, isinstance(value.value, Method))
def _getCacheSize(self, cache_id): def _getCacheSize(self, cache_id):
count = 0 count = 0
......
<?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>default_reference</string> </key>
<value> <string>testFields</string> </value>
</item>
<item>
<key> <string>default_source_reference</string> </key>
<value> <string>Products.ERP5Form.tests.testFields</string> </value>
</item>
<item>
<key> <string>description</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>test.erp5.testFields</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">AAAAAAAAAAI=</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>
<item>
<key> <string>component_validation_workflow</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAM=</string> </persistent>
</value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="3" aka="AAAAAAAAAAM=">
<pickle>
<global name="WorkflowHistoryList" module="Products.ERP5Type.Workflow"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_log</string> </key>
<value>
<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>
</value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
erp5_full_text_mroonga_catalog erp5_full_text_mroonga_catalog
erp5_base erp5_base
erp5_csv_style erp5_csv_style
\ No newline at end of file erp5_core_proxy_field_legacy
\ No newline at end of file
...@@ -17,6 +17,8 @@ test.erp5.testERP5Base ...@@ -17,6 +17,8 @@ test.erp5.testERP5Base
test.erp5.testERP5Category test.erp5.testERP5Category
test.erp5.testERP5Coordinate test.erp5.testERP5Coordinate
test.erp5.testERP5Core test.erp5.testERP5Core
test.erp5.testFieldValueCache
test.erp5.testFields
test.erp5.testFolder test.erp5.testFolder
test.erp5.testFolderMigration test.erp5.testFolderMigration
test.erp5.testGeographicalAddress test.erp5.testGeographicalAddress
......
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