Commit 3b935ad2 authored by Łukasz Nowak's avatar Łukasz Nowak

Fix a local property fixing fix.

Also extend test case to cover exactly what is expected to happen.
parent 3dab2e92
No related merge requests found
......@@ -73,7 +73,8 @@ class PropertyTypeValidity(Constraint):
" (Type cast failed with error ${type_cast_error})"
message_incorrect_type_fixed = "Attribute ${attribute_name}"\
" should be of type ${expected_type} but is of type ${actual_type} (Fixed)"
message_value_modified = "Value of '${key}' was modified from '${old}' to '${new}'."
message_local_property_migrated = "Property ${property_id} was migrated from local properties."
message_local_property_modified = "Property ${property_id} was modified from ${old_value} to ${new_value}."
def _checkConsistency(self, obj, fixit=0):
"""Check the object's consistency.
......@@ -96,6 +97,9 @@ class PropertyTypeValidity(Constraint):
len([x for x in obj._propertyMap() if x['id'] == property_id]) > 1:
obj._local_properties = tuple([x for x in obj._local_properties
if x['id'] != property_id])
error_list.append(self._generateError(obj,
self._getMessage('message_local_property_migrated'), dict(
property_id=property_id)))
property_was_local = True
if property_type in self._permissive_type_list:
......@@ -141,8 +145,8 @@ class PropertyTypeValidity(Constraint):
oldvalue = getattr(obj, property_id, value)
if oldvalue != value:
error_list.append(self._generateError(obj,
self._getMessage('message_value_modified'), dict(
key=property_id, old=oldvalue, new=value)))
self._getMessage('message_local_property_modified'), dict(
property_id=property_id, old_value=oldvalue, new_value=value)))
obj.setProperty(property_id, value)
return error_list
......@@ -1215,7 +1215,8 @@ class TestConstraint(PropertySheetTestCase):
portal_type="Standard Property",
property_id="local_property",
elementary_type="string")
constraint.fixConsistency(obj)
self.assertEqual(['Property local_property was migrated from local properties.'],
[str(q.getMessage()) for q in constraint.fixConsistency(obj)])
self.assertEquals((), obj._local_properties)
self.assertEquals('1', obj.getLocalProperty())
obj.edit(local_property='something else')
......@@ -1237,7 +1238,8 @@ class TestConstraint(PropertySheetTestCase):
portal_type="Standard Property",
property_id="local_property",
elementary_type="float")
constraint.fixConsistency(obj)
self.assertEqual(['Property local_property was migrated from local properties.'],
[str(q.getMessage()) for q in constraint.fixConsistency(obj)])
self.assertEquals((), obj._local_properties)
self.assertEquals(1.234, obj.getLocalProperty())
obj.edit(local_property=3)
......@@ -1269,7 +1271,8 @@ class TestConstraint(PropertySheetTestCase):
ti._setTypeAllowedContentTypeList(allowed_types + ['Organisation'])
transaction.commit()
try:
constraint.fixConsistency(obj)
self.assertEqual(['Property local_property was migrated from local properties.'],
[str(q.getMessage()) for q in constraint.fixConsistency(obj)])
self.assertEquals('foo', obj.getDefaultOrganisationTitle())
self.assertEquals('foo', obj.default_organisation.getTitle())
finally:
......@@ -1293,7 +1296,8 @@ class TestConstraint(PropertySheetTestCase):
portal_type="Category Property",
property_id="testing_category")
# fix consistency
constraint.fixConsistency(obj)
self.assertEqual(['Property local_property was migrated from local properties.'],
[str(q.getMessage()) for q in constraint.fixConsistency(obj)])
# now we can use testing_category as any category accessor
self.assertEquals(obj, obj.getTestingCategoryValue())
......
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