[Erp5-report] r43199 nicolas.dumazet - in /erp5/trunk/products/ERP5Type: ./ tests/
nobody at svn.erp5.org
nobody at svn.erp5.org
Wed Feb 9 04:47:20 CET 2011
Author: nicolas.dumazet
Date: Wed Feb 9 04:47:19 2011
New Revision: 43199
URL: http://svn.erp5.org?rev=43199&view=rev
Log:
Add a testcase and fix the usage when one adds an empty, or invalid, or
incorrect property to a propertysheet.
It was okay, with filesystem property sheets to raise an error: worst case
scenario, the developer would have to fix the property sheet and restart the
instance. But with ZODB property sheets, raising an error can potentially
break the instance. We replace the error by a LOG: you're likely to see this
when editing properties.
This is not a "dirty quickfix", this is not a workaround to go faster: this
behavior will stay. If you feel that it's a wrong way to do, do tell us.
Modified:
erp5/trunk/products/ERP5Type/Utils.py
erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py
Modified: erp5/trunk/products/ERP5Type/Utils.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/Utils.py?rev=43199&r1=43198&r2=43199&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/Utils.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/Utils.py [utf8] Wed Feb 9 04:47:19 2011
@@ -1499,6 +1499,12 @@ def setDefaultProperties(property_holder
converted_prop_list = []
converted_prop_set = set()
for prop in prop_list:
+ if prop['type'] not in type_definition:
+ LOG("ERP5Type.Utils", INFO,
+ "Invalid type '%s' of property '%s' for Property Sheet '%s'" % \
+ (prop['type'], prop['id'], property_holder.__name__))
+ continue
+
read_permission = prop.get('read_permission',
Permissions.AccessContentsInformation)
if isinstance(read_permission, Expression):
@@ -1507,9 +1513,7 @@ def setDefaultProperties(property_holder
Permissions.ModifyPortalContent)
if isinstance(write_permission, Expression):
write_permission = write_permission(econtext)
- if prop['type'] not in type_definition:
- raise TypeError, '"%s" is invalid type for propertysheet' % \
- prop['type']
+
if 'base_id' in prop:
continue
if prop['id'] not in converted_prop_set:
Modified: erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py?rev=43199&r1=43198&r2=43199&view=diff
==============================================================================
--- erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py [utf8] (original)
+++ erp5/trunk/products/ERP5Type/tests/testDynamicClassGeneration.py [utf8] Wed Feb 9 04:47:19 2011
@@ -999,6 +999,32 @@ class TestZodbPropertySheet(ERP5TypeTest
self.test_module.setTitle,
'my_property_type_validity_constraint_title')
+ def testAddEmptyProperty(self):
+ """
+ When users create properties in a PropertySheet, the property
+ is first empty.
+ Check that accessor generation can cope with such invalid
+ properties
+ """
+ property_sheet_tool = self.portal.portal_property_sheets
+ arrow = property_sheet_tool.Arrow
+
+ # Action -> add Acquired Property
+ arrow.newContent(portal_type="Acquired Property")
+ # a user is doing this, so commit after each request
+ transaction.commit()
+
+ accessor = getattr(property_sheet_tool, "setTitle", None)
+ # sites used to break at this point
+ self.assertNotEquals(None, accessor)
+ # try to create a Career, which uses Arrow Property Sheet
+ person_module = self.portal.person_module
+ person = person_module.newContent(portal_type="Person")
+ try:
+ person.newContent(portal_type="Career")
+ except TypeError:
+ self.fail("Arrow Property Sheet could not be generated")
+
from Products.CMFCore.Expression import Expression
class TestZodbImportFilesystemPropertySheet(ERP5TypeTestCase):
More information about the Erp5-report
mailing list