Commit b694e729 authored by Nicolas Dumazet's avatar Nicolas Dumazet

convert most of this test to ZODB property sheets


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@42896 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 20085384
...@@ -1191,8 +1191,10 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1191,8 +1191,10 @@ class TestConstraint(PropertySheetTestCase):
self.assertEquals(1, len(obj._local_properties)) self.assertEquals(1, len(obj._local_properties))
self.assertEquals([], constraint.checkConsistency(obj)) self.assertEquals([], constraint.checkConsistency(obj))
# now add a 'local_property' property defined on a property sheet # now add a 'local_property' property defined on a property sheet
self._addProperty(obj.getPortalType(), self._addProperty(obj.getPortalType(), "FixLocalPropertiesString",
"{'id': 'local_property', 'type': 'string'}") portal_type="Standard Property",
property_id="local_property",
elementary_type="string")
constraint.fixConsistency(obj) constraint.fixConsistency(obj)
self.assertEquals((), obj._local_properties) self.assertEquals((), obj._local_properties)
self.assertEquals('1', obj.getLocalProperty()) self.assertEquals('1', obj.getLocalProperty())
...@@ -1211,8 +1213,10 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1211,8 +1213,10 @@ class TestConstraint(PropertySheetTestCase):
self.assertEquals(1, len(obj._local_properties)) self.assertEquals(1, len(obj._local_properties))
#self.assertEquals([], constraint.checkConsistency(obj)) #self.assertEquals([], constraint.checkConsistency(obj))
# now add a 'local_property' property defined on a property sheet # now add a 'local_property' property defined on a property sheet
self._addProperty(obj.getPortalType(), self._addProperty(obj.getPortalType(), "FixLocalPropertiesFloat",
"{'id': 'local_property', 'type': 'float'}") portal_type="Standard Property",
property_id="local_property",
elementary_type="float")
constraint.fixConsistency(obj) constraint.fixConsistency(obj)
self.assertEquals((), obj._local_properties) self.assertEquals((), obj._local_properties)
self.assertEquals(1.234, obj.getLocalProperty()) self.assertEquals(1.234, obj.getLocalProperty())
...@@ -1230,18 +1234,20 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1230,18 +1234,20 @@ class TestConstraint(PropertySheetTestCase):
obj.edit(default_organisation_title='foo') obj.edit(default_organisation_title='foo')
self.assertEquals([], constraint.checkConsistency(obj)) self.assertEquals([], constraint.checkConsistency(obj))
# now add a 'local_property' property defined on a property sheet # now add a 'local_property' property defined on a property sheet
self._addProperty(obj.getPortalType(), self._addProperty(obj.getPortalType(), "FixLocalPropertiesContent",
''' { 'id': 'organisation', portal_type="Acquired Property",
'storage_id': 'default_organisation', commit=False,
'type': 'content', property_id="organisation",
'portal_type': ('Organisation', ), storage_id="default_organisation",
'acquired_property_id': ('title', ), elementary_type="content",
'mode': 'w', }''') content_portal_type="python: ('Organisation', )",
content_acquired_property_id= ('title',))
# this property suppose that we can add some Organisation inside # this property suppose that we can add some Organisation inside
# Organisation, so we temporary patch the type information. # Organisation, so we temporary patch the type information.
ti = self.getTypesTool().getTypeInfo(obj) ti = self.getTypesTool().getTypeInfo(obj)
allowed_types = ti.getTypeAllowedContentTypeList() allowed_types = ti.getTypeAllowedContentTypeList()
ti._setTypeAllowedContentTypeList(allowed_types + ['Organisation']) ti._setTypeAllowedContentTypeList(allowed_types + ['Organisation'])
transaction.commit()
try: try:
constraint.fixConsistency(obj) constraint.fixConsistency(obj)
self.assertEquals('foo', obj.getDefaultOrganisationTitle()) self.assertEquals('foo', obj.getDefaultOrganisationTitle())
...@@ -1263,9 +1269,9 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1263,9 +1269,9 @@ class TestConstraint(PropertySheetTestCase):
obj.edit(testing_category=obj.getRelativeUrl()) obj.edit(testing_category=obj.getRelativeUrl())
self.assertEquals([], constraint.checkConsistency(obj)) self.assertEquals([], constraint.checkConsistency(obj))
# now add a 'local_property' property defined on a property sheet # now add a 'local_property' property defined on a property sheet
self._addPropertySheet(obj.getPortalType(), self._addProperty(obj.getPortalType(), "FixForCategories",
property_sheet_code=\ portal_type="Category Property",
'''class TestPropertySheet: _categories=('testing_category',)''') property_id="testing_category")
# fix consistency # fix consistency
constraint.fixConsistency(obj) constraint.fixConsistency(obj)
# now we can use testing_category as any category accessor # now we can use testing_category as any category accessor
...@@ -1429,23 +1435,17 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1429,23 +1435,17 @@ class TestConstraint(PropertySheetTestCase):
person = self.portal.person_module.newContent(portal_type='Person') person = self.portal.person_module.newContent(portal_type='Person')
assignment = person.newContent(portal_type='Assignment') assignment = person.newContent(portal_type='Assignment')
# add a source_title property on Assignment. # add a source_title property on Assignment.
self._addPropertySheet('Assignment', self._addProperty('Assignment', "UnauthorizedCategory",
property_sheet_code=\ commit=False,
'''class TestPropertySheet: portal_type="Acquired Property",
_properties = ( property_id="source_title",
{'id':'source_title', elementary_type="string",
'description':'The title of the source of this movement', acquisition_base_category=('source',),
'type':'string', acquisition_portal_type="python: ('Category',)",
'acquisition_base_category':('source',), acquisition_accessor_id="getTitle")
'acquisition_portal_type':('Category'), self._addProperty('Assignment', "UnauthorizedCategory",
'acquisition_accessor_id':'getTitle', portal_type="Property Type Validity Constraint",
'mode':''},) property_id="type_check")
_constraints = (
{ 'type': 'PropertyTypeValidity',
'id': 'type_check',
'description': "Type Validity Check Error",
}, )
''')
self.assertEquals([], person.checkConsistency()) self.assertEquals([], person.checkConsistency())
group3 = self.category_tool.restrictedTraverse( group3 = self.category_tool.restrictedTraverse(
'group/testGroup3', self.category_tool.group.newContent( 'group/testGroup3', self.category_tool.group.newContent(
...@@ -1479,11 +1479,11 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1479,11 +1479,11 @@ class TestConstraint(PropertySheetTestCase):
klass_name='PropertyTypeValidity', klass_name='PropertyTypeValidity',
id='multi_valuated_property', ) id='multi_valuated_property', )
obj = self._makeOne() obj = self._makeOne()
self._addProperty(obj.getPortalType(), self._addProperty(obj.getPortalType(), "ForMultivalued",
'''{'id': 'multi_valuated_property', property_id="multi_valuated_property",
'type': 'float', portal_type="Standard Property",
'multivalued': 1, elementary_type="float",
'mode': 'w', }''') multivalued=1)
obj.edit(multi_valuated_property=[1.0, 2.0, 3.0, ]) obj.edit(multi_valuated_property=[1.0, 2.0, 3.0, ])
self.assertEquals([], constraint.checkConsistency(obj)) self.assertEquals([], constraint.checkConsistency(obj))
......
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