Commit 7a03b5ee authored by Nicolas Delaby's avatar Nicolas Delaby

Fix tester accessor generation for acquired properties

Tester accessors was not generated for acquired properties,
only content accessor was generated.

Extend test to prove the fix.
parent 5be21a28
...@@ -276,7 +276,7 @@ class Tester(Method): ...@@ -276,7 +276,7 @@ class Tester(Method):
func_defaults = () func_defaults = ()
def __init__(self, id, key, property_type, acquired_property, def __init__(self, id, key, property_type, acquired_property,
storage_id=None): portal_type=None, storage_id=None):
self._id = id self._id = id
self.__name__ = id self.__name__ = id
self._key = key self._key = key
...@@ -284,9 +284,19 @@ class Tester(Method): ...@@ -284,9 +284,19 @@ class Tester(Method):
self._null = type_definition[property_type]['null'] self._null = type_definition[property_type]['null']
if storage_id is None: if storage_id is None:
storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key) storage_id = "%s%s" % (ATTRIBUTE_PREFIX, key)
self._storage_id = storage_id elif type(storage_id) is not list:
storage_id = [storage_id]
self._storage_id_list = storage_id
if type(portal_type) is str:
portal_type = (portal_type,)
self._portal_type = portal_type
self._acquired_property = acquired_property self._acquired_property = acquired_property
def __call__(self, instance, *args, **kw): def __call__(self, instance, *args, **kw):
return getattr(instance, self._storage_id, None) is not None o = None
for k in self._storage_id_list:
o = getattr(instance, k, None)
if o is not None and o.portal_type in self._portal_type:
return o.hasProperty(self._acquired_property)
return False
...@@ -314,10 +314,11 @@ class AcquiredProperty(StandardProperty): ...@@ -314,10 +314,11 @@ class AcquiredProperty(StandardProperty):
if property_dict['elementary_type'] == 'content': if property_dict['elementary_type'] == 'content':
argument_list = (property_dict['elementary_type'], argument_list = (property_dict['elementary_type'],
property_dict['storage_id']) property_dict['storage_id'])
reference = property_dict['reference']
cls._applyDefinitionFormatDictOnAccessorHolder( for composed_id in (reference, 'default_' + reference,):
property_dict['reference'], cls._content_type_tester_definition_dict, cls._applyDefinitionFormatDictOnAccessorHolder(
accessor_holder, argument_list, property_dict['read_permission']) composed_id, cls._content_type_tester_definition_dict,
accessor_holder, argument_list, property_dict['read_permission'])
else: else:
super(AcquiredProperty, cls)._applyTesterDefinitionDictOnAccessorHolder( super(AcquiredProperty, cls)._applyTesterDefinitionDictOnAccessorHolder(
...@@ -484,6 +485,10 @@ class AcquiredProperty(StandardProperty): ...@@ -484,6 +485,10 @@ class AcquiredProperty(StandardProperty):
'_set%s': ContentProperty.Setter '_set%s': ContentProperty.Setter
} }
_content_type_acquired_property_id_tester_definition_dict = {
'has%s': ContentProperty.Tester
}
@classmethod @classmethod
def _applyContentTypeAcquiredPropertyOnAccessorHolder(cls, def _applyContentTypeAcquiredPropertyOnAccessorHolder(cls,
aq_id, aq_id,
...@@ -515,6 +520,13 @@ class AcquiredProperty(StandardProperty): ...@@ -515,6 +520,13 @@ class AcquiredProperty(StandardProperty):
acquired_property_id_argument_list, acquired_property_id_argument_list,
property_dict['write_permission']) property_dict['write_permission'])
cls._applyDefinitionFormatDictOnAccessorHolder(
composed_id,
cls._content_type_acquired_property_id_tester_definition_dict,
accessor_holder,
acquired_property_id_argument_list,
property_dict['read_permission'])
cls._applyDefinitionFormatDictOnAccessorHolder( cls._applyDefinitionFormatDictOnAccessorHolder(
composed_id + '_list', composed_id + '_list',
cls._content_type_acquired_property_id_getter_definition_dict, cls._content_type_acquired_property_id_getter_definition_dict,
...@@ -529,6 +541,13 @@ class AcquiredProperty(StandardProperty): ...@@ -529,6 +541,13 @@ class AcquiredProperty(StandardProperty):
acquired_property_id_list_argument_list, acquired_property_id_list_argument_list,
property_dict['write_permission']) property_dict['write_permission'])
cls._applyDefinitionFormatDictOnAccessorHolder(
composed_id + '_list',
cls._content_type_acquired_property_id_tester_definition_dict,
accessor_holder,
acquired_property_id_argument_list,
property_dict['read_permission'])
@classmethod @classmethod
def applyDefinitionOnAccessorHolder(cls, def applyDefinitionOnAccessorHolder(cls,
property_dict, property_dict,
...@@ -541,7 +560,7 @@ class AcquiredProperty(StandardProperty): ...@@ -541,7 +560,7 @@ class AcquiredProperty(StandardProperty):
portal) portal)
if property_dict['elementary_type'] == 'content': if property_dict['elementary_type'] == 'content':
if property_dict['acquisition_base_category'] is not None: if property_dict['acquisition_base_category']:
apply_method = cls._applyAcquisitionBaseCategoryAcquiredPropertyOnAccessorHolder apply_method = cls._applyAcquisitionBaseCategoryAcquiredPropertyOnAccessorHolder
else: else:
apply_method = cls._applyContentTypeAcquiredPropertyOnAccessorHolder apply_method = cls._applyContentTypeAcquiredPropertyOnAccessorHolder
......
...@@ -1059,8 +1059,14 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor): ...@@ -1059,8 +1059,14 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
'organisation', 'organisation',
**self.DEFAULT_ORGANISATION_TITLE_PROP) **self.DEFAULT_ORGANISATION_TITLE_PROP)
person = self.getPersonModule().newContent(id='1', portal_type='Person') person = self.getPersonModule().newContent(id='1', portal_type='Person')
self.assertTrue(hasattr(person, 'getDefaultOrganisationTitle')) self.assertTrue(getattr(person, 'getDefaultOrganisationTitle'))
self.assertTrue(hasattr(person, 'setDefaultOrganisationTitle')) self.assertTrue(getattr(person, 'setDefaultOrganisationTitle'))
self.assertTrue(getattr(person, 'hasDefaultOrganisationTitle'))
self.assertTrue(getattr(person, 'hasOrganisationTitle'))
self.assertFalse(person.hasDefaultOrganisation())
self.assertFalse(person.hasOrganisation())
self.assertFalse(person.hasDefaultOrganisationTitle())
self.assertFalse(person.hasOrganisationTitle())
person.setDefaultOrganisationTitle('The organisation title') person.setDefaultOrganisationTitle('The organisation title')
# XXX content generated properties are not in propertyMap. is it a bug ? # XXX content generated properties are not in propertyMap. is it a bug ?
#self.assertTrue(person.hasProperty('default_organisation_title')) #self.assertTrue(person.hasProperty('default_organisation_title'))
...@@ -1072,7 +1078,10 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor): ...@@ -1072,7 +1078,10 @@ class TestERP5Type(PropertySheetTestCase, LogInterceptor):
default_organisation.getPortalTypeName()) default_organisation.getPortalTypeName())
self.assertEquals('The organisation title', self.assertEquals('The organisation title',
default_organisation.getTitle()) default_organisation.getTitle())
self.assertTrue(person.hasDefaultOrganisation())
self.assertTrue(person.hasOrganisation())
self.assertTrue(person.hasDefaultOrganisationTitle())
self.assertTrue(person.hasOrganisationTitle())
# make sure this new organisation is indexed # make sure this new organisation is indexed
transaction.commit() transaction.commit()
self.assertEquals(1, len([m for m in self.assertEquals(1, len([m for m in
......
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