Commit da8316f8 authored by Łukasz Nowak's avatar Łukasz Nowak

Fix local property detection condition.

Also extend test to cover code entries related to local property migration.
parent 97c4955d
...@@ -94,7 +94,7 @@ class PropertyTypeValidity(Constraint): ...@@ -94,7 +94,7 @@ class PropertyTypeValidity(Constraint):
if fixit and \ if fixit and \
property_id in [x['id'] for x in property_id in [x['id'] for x in
getattr(obj, '_local_properties', ())] and \ getattr(obj, '_local_properties', ())] and \
len([x for x in obj._propertyMap() if x['id'] == property_id]) > 1: len([x for x in obj._propertyMap() if x['id'] == property_id]) > 0:
obj._local_properties = tuple([x for x in obj._local_properties obj._local_properties = tuple([x for x in obj._local_properties
if x['id'] != property_id]) if x['id'] != property_id])
error_list.append(self._generateError(obj, error_list.append(self._generateError(obj,
...@@ -147,6 +147,6 @@ class PropertyTypeValidity(Constraint): ...@@ -147,6 +147,6 @@ class PropertyTypeValidity(Constraint):
error_list.append(self._generateError(obj, error_list.append(self._generateError(obj,
self._getMessage('message_local_property_modified'), dict( self._getMessage('message_local_property_modified'), dict(
property_id=property_id, old_value=oldvalue, new_value=value))) property_id=property_id, old_value=oldvalue, new_value=value)))
obj.setProperty(property_id, value) obj.setProperty(property_id, oldvalue)
return error_list return error_list
...@@ -1272,10 +1272,13 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1272,10 +1272,13 @@ class TestConstraint(PropertySheetTestCase):
ti._setTypeAllowedContentTypeList(allowed_types + ['Organisation']) ti._setTypeAllowedContentTypeList(allowed_types + ['Organisation'])
transaction.commit() transaction.commit()
try: try:
constraint.fixConsistency(obj) self.assertEqual(sorted([
self.assertEqual(0, len(obj._local_properties)) 'Property default_organisation_title was migrated from local properties.',
'Property default_organisation_title was modified from foo to None.']),
sorted([str(q.getMessage()) for q in constraint.fixConsistency(obj)]))
self.assertEquals('foo', obj.getDefaultOrganisationTitle()) self.assertEquals('foo', obj.getDefaultOrganisationTitle())
self.assertEquals('foo', obj.default_organisation.getTitle()) self.assertEquals('foo', obj.default_organisation.getTitle())
self.assertEqual(0, len(obj._local_properties))
finally: finally:
ti._setTypeAllowedContentTypeList(allowed_types) ti._setTypeAllowedContentTypeList(allowed_types)
...@@ -1298,7 +1301,10 @@ class TestConstraint(PropertySheetTestCase): ...@@ -1298,7 +1301,10 @@ class TestConstraint(PropertySheetTestCase):
portal_type="Category Property", portal_type="Category Property",
property_id="testing_category") property_id="testing_category")
# fix consistency # fix consistency
constraint.fixConsistency(obj) self.assertEqual(sorted([
'Property testing_category was migrated from local properties.',
'Property testing_category was modified from organisation_module/%s to None.' % obj.getId()]),
sorted([str(q.getMessage()) for q in constraint.fixConsistency(obj)]))
# now we can use testing_category as any category accessor # now we can use testing_category as any category accessor
self.assertEqual(0, len(obj._local_properties)) self.assertEqual(0, len(obj._local_properties))
self.assertEquals(obj, obj.getTestingCategoryValue()) 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