Commit 7939c0d8 authored by Aurel's avatar Aurel

raise a more user friendly message, remove trailling spaces

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@12671 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 88b120e7
...@@ -210,7 +210,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -210,7 +210,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
return cache[key] return cache[key]
except KeyError: except KeyError:
pass pass
try: try:
relative_url = str(relative_url) relative_url = str(relative_url)
if base_category is not None: if base_category is not None:
...@@ -219,12 +219,12 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -219,12 +219,12 @@ class CategoryTool( UniqueObject, Folder, Base ):
value = node value = node
except (TypeError, KeyError, NotFound): except (TypeError, KeyError, NotFound):
value = None value = None
if cache is not None: if cache is not None:
cache[key] = value cache[key] = value
return value return value
# security.declareProtected(Permissions.AccessContentsInformation, 'getCategoryValue') # security.declareProtected(Permissions.AccessContentsInformation, 'getCategoryValue')
# def getCategoryValue(self, relative_url, base_category = None): # def getCategoryValue(self, relative_url, base_category = None):
# """ # """
...@@ -608,16 +608,16 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -608,16 +608,16 @@ class CategoryTool( UniqueObject, Folder, Base ):
portal_type = kw.get('portal_type', ()) portal_type = kw.get('portal_type', ())
if isinstance(portal_type, str): if isinstance(portal_type, str):
portal_type = (portal_type,) portal_type = (portal_type,)
if spec is (): if spec is ():
spec = portal_type spec = portal_type
#LOG("set Category",0,str(category_list))
default_dict = {} default_dict = {}
self._cleanupCategories(context) self._cleanupCategories(context)
if isinstance(category_list, str): if isinstance(category_list, str):
category_list = (category_list,) category_list = (category_list,)
elif category_list is None: elif category_list is None:
category_list = () category_list = ()
elif not isinstance(category_list, list):
raise TypeError, 'Category must be a string.'
if isinstance(base_category_list, str): if isinstance(base_category_list, str):
base_category_list = [base_category_list] base_category_list = [base_category_list]
new_category_list = [] new_category_list = []
...@@ -783,23 +783,23 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -783,23 +783,23 @@ class CategoryTool( UniqueObject, Folder, Base ):
spec=(), filter=None, acquired_object_dict = None, **kw ): spec=(), filter=None, acquired_object_dict = None, **kw ):
cache = getReadOnlyTransactionCache(self) cache = getReadOnlyTransactionCache(self)
if cache is not None: if cache is not None:
key = ('getSingleCategoryAcquiredMembershipList', context._p_oid, base_category, base, spec, key = ('getSingleCategoryAcquiredMembershipList', context._p_oid, base_category, base, spec,
filter, str(kw)) filter, str(kw))
try: try:
return cache[key] return cache[key]
except KeyError: except KeyError:
pass pass
result = self._getSingleCategoryAcquiredMembershipList(context, base_category, base=base, result = self._getSingleCategoryAcquiredMembershipList(context, base_category, base=base,
spec=spec, filter=filter, spec=spec, filter=filter,
acquired_object_dict = acquired_object_dict, acquired_object_dict = acquired_object_dict,
**kw) **kw)
if cache is not None: if cache is not None:
cache[key] = result cache[key] = result
return result return result
def _getSingleCategoryAcquiredMembershipList(self, context, base_category, def _getSingleCategoryAcquiredMembershipList(self, context, base_category,
base = 0, spec = (), filter = None, base = 0, spec = (), filter = None,
acquired_portal_type = (), acquired_portal_type = (),
...@@ -878,7 +878,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -878,7 +878,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
result = self.getSingleCategoryMembershipList( context, base_category, base=base, result = self.getSingleCategoryMembershipList( context, base_category, base=base,
spec=spec, filter=filter, **kw ) # Not acquired because this is the first try spec=spec, filter=filter, **kw ) # Not acquired because this is the first try
# to get a local defined category # to get a local defined category
base_category_value = self.getCategoryValue(base_category) base_category_value = self.getCategoryValue(base_category)
#LOG("result", 0, str(result)) #LOG("result", 0, str(result))
if base_category_value is not None: if base_category_value is not None:
...@@ -1027,7 +1027,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1027,7 +1027,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
# WE MUST IMPLEMENT HERE THE REST OF THE SEMANTICS # WE MUST IMPLEMENT HERE THE REST OF THE SEMANTICS
#LOG("Get Acquired Category Result ",0,str(result)) #LOG("Get Acquired Category Result ",0,str(result))
return result return result
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getAcquiredCategoryMembershipList' ) 'getAcquiredCategoryMembershipList' )
def getAcquiredCategoryMembershipList(self, context, base_category = None, base=1, def getAcquiredCategoryMembershipList(self, context, base_category = None, base=1,
...@@ -1057,12 +1057,12 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1057,12 +1057,12 @@ class CategoryTool( UniqueObject, Folder, Base ):
""" """
Tests if an object if member of a given category Tests if an object if member of a given category
Category is a string here. It could be more than a string (ex. an object) Category is a string here. It could be more than a string (ex. an object)
Keywords parameters : Keywords parameters :
- strict_membership: if we want strict membership checking - strict_membership: if we want strict membership checking
- strict : alias for strict_membership (deprecated but still here for - strict : alias for strict_membership (deprecated but still here for
skins backward compatibility. ) skins backward compatibility. )
XXX - there should be 2 different methods, one which acuiqred XXX - there should be 2 different methods, one which acuiqred
and the other which does not. A complete review of and the other which does not. A complete review of
the use of isMemberOf is required the use of isMemberOf is required
...@@ -1077,7 +1077,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1077,7 +1077,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
if c == category: if c == category:
return 1 return 1
else: else:
for c in self.getAcquiredCategoryMembershipList(context, base_category = base_category): for c in self.getAcquiredCategoryMembershipList(context, base_category = base_category):
if c.find(category) == 0: if c.find(category) == 0:
# The names begin with the same string # The names begin with the same string
c_right_split = c.split(category)[1] c_right_split = c.split(category)[1]
...@@ -1218,7 +1218,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1218,7 +1218,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
def updateRelatedContent(self, context, def updateRelatedContent(self, context,
previous_category_url, new_category_url): previous_category_url, new_category_url):
"""Updates related object when an object have moved. """Updates related object when an object have moved.
o context: the moved object o context: the moved object
o previous_category_url: the related url of this object before o previous_category_url: the related url of this object before
the move the move
...@@ -1273,7 +1273,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1273,7 +1273,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
""" """
strict_membership = kw.get('strict_membership', kw.get('strict', 0)) strict_membership = kw.get('strict_membership', kw.get('strict', 0))
portal_type = kw.get('portal_type') portal_type = kw.get('portal_type')
if isinstance(portal_type, str): if isinstance(portal_type, str):
portal_type = [portal_type] portal_type = [portal_type]
if spec is (): spec = None # We do not want to care about spec if spec is (): spec = None # We do not want to care about spec
...@@ -1289,12 +1289,12 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1289,12 +1289,12 @@ class CategoryTool( UniqueObject, Folder, Base ):
category_list = [] category_list = []
for base_category in base_category_list: for base_category in base_category_list:
category_list.append("%s/%s" % (base_category, context.getRelativeUrl())) category_list.append("%s/%s" % (base_category, context.getRelativeUrl()))
brain_result = self.Base_zSearchRelatedObjectsByCategoryList( brain_result = self.Base_zSearchRelatedObjectsByCategoryList(
category_list = category_list, category_list = category_list,
portal_type = portal_type, portal_type = portal_type,
strict_membership = strict_membership ) strict_membership = strict_membership )
result = [] result = []
for b in brain_result: for b in brain_result:
o = b.getObject() o = b.getObject()
...@@ -1305,7 +1305,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1305,7 +1305,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
# XXX missing filter and **kw stuff # XXX missing filter and **kw stuff
#return self.search_category(category_list = category_list, portal_type = spec) #return self.search_category(category_list = category_list, portal_type = spec)
# future implementation with brains, much more efficient # future implementation with brains, much more efficient
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getRelatedPropertyList' ) 'getRelatedPropertyList' )
def getRelatedPropertyList(self, context, base_category_list=None, def getRelatedPropertyList(self, context, base_category_list=None,
...@@ -1320,7 +1320,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1320,7 +1320,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
filter=filter, base=base, **kw) : filter=filter, base=base, **kw) :
result.append(o.getProperty(property_name, None)) result.append(o.getProperty(property_name, None))
return result return result
# SQL Expression Building # SQL Expression Building
security.declareProtected(Permissions.AccessContentsInformation, 'buildSQLSelector') security.declareProtected(Permissions.AccessContentsInformation, 'buildSQLSelector')
def buildSQLSelector(self, category_list, query_table='category'): def buildSQLSelector(self, category_list, query_table='category'):
...@@ -1395,7 +1395,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1395,7 +1395,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
else: else:
catalog_search = self.portal_catalog(portal_type = portal_type, catalog_search = self.portal_catalog(portal_type = portal_type,
selection_domain = selection_domain) selection_domain = selection_domain)
return catalog_search return catalog_search
security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' ) security.declareProtected( Permissions.AccessContentsInformation, 'getCategoryMemberItemList' )
...@@ -1404,7 +1404,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1404,7 +1404,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
This returns a list of items belonging to a category. This returns a list of items belonging to a category.
The following parameters are accepted : The following parameters are accepted :
portal_type : returns only objects from the given portal_type portal_type : returns only objects from the given portal_type
strict_membership : returns only object belonging to this category, not strict_membership : returns only object belonging to this category, not
objects belonging to child categories. objects belonging to child categories.
strict : a deprecated alias for strict_membership strict : a deprecated alias for strict_membership
""" """
...@@ -1418,14 +1418,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1418,14 +1418,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
security.declareProtected( Permissions.AccessContentsInformation, security.declareProtected( Permissions.AccessContentsInformation,
'getCategoryMemberTitleItemList' ) 'getCategoryMemberTitleItemList' )
def getCategoryMemberTitleItemList(self, context, base_category = None, def getCategoryMemberTitleItemList(self, context, base_category = None,
spec = (), filter=None, portal_type=(), strict_membership = 0, spec = (), filter=None, portal_type=(), strict_membership = 0,
strict="DEPRECATED"): strict="DEPRECATED"):
""" """
This returns a title list of items belonging to a category This returns a title list of items belonging to a category
""" """
return self.getCategoryMemberItemList(self, context, base_category = base_category, return self.getCategoryMemberItemList(self, context, base_category = base_category,
spec = spec, filter=filter, portal_type=portal_type, spec = spec, filter=filter, portal_type=portal_type,
strict_membership = strict_membership, strict = strict, strict_membership = strict_membership, strict = strict,
display_id = 'getTitle') display_id = 'getTitle')
...@@ -1443,7 +1443,7 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1443,7 +1443,7 @@ class CategoryTool( UniqueObject, Folder, Base ):
return cache[key] return cache[key]
except KeyError: except KeyError:
pass pass
try: try:
obj = self.restrictedTraverse(relative_url) obj = self.restrictedTraverse(relative_url)
if obj is None: if obj is None:
...@@ -1456,10 +1456,10 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1456,10 +1456,10 @@ class CategoryTool( UniqueObject, Folder, Base ):
except (KeyError, AttributeError) : except (KeyError, AttributeError) :
LOG("CMFCategory WARNING",0,"Could not access object relative_url %s" % relative_url ) LOG("CMFCategory WARNING",0,"Could not access object relative_url %s" % relative_url )
value = None value = None
if cache is not None: if cache is not None:
cache[key] = value cache[key] = value
return value return value
InitializeClass( CategoryTool ) InitializeClass( CategoryTool )
......
...@@ -187,7 +187,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -187,7 +187,7 @@ class TestCMFCategory(ERP5TypeTestCase):
LOG('Testing... ',0,'testSingleCategory') LOG('Testing... ',0,'testSingleCategory')
o1 = self.getOrganisationModule()._getOb(self.id1) o1 = self.getOrganisationModule()._getOb(self.id1)
LOG('SingleCategory,',0,o1.getGenderRelatedValueList()) LOG('SingleCategory,',0,o1.getGenderRelatedValueList())
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegion(self.region1) p1.setRegion(self.region1)
self.assertEqual(p1.getRegion(),self.region1) self.assertEqual(p1.getRegion(),self.region1)
...@@ -283,7 +283,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -283,7 +283,7 @@ class TestCMFCategory(ERP5TypeTestCase):
self.assertEqual(p1.getRegion(),self.region1) self.assertEqual(p1.getRegion(),self.region1)
self.assertEqual(p1.getDefaultRegion(),self.region1) self.assertEqual(p1.getDefaultRegion(),self.region1)
self.assertEqual(p1.getRegionList(),self.region_list) self.assertEqual(p1.getRegionList(),self.region_list)
def test_listAcquisitionIsMemberOf(self): def test_listAcquisitionIsMemberOf(self):
o1 = self.getOrganisationModule()._getOb(self.id1) o1 = self.getOrganisationModule()._getOb(self.id1)
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
...@@ -351,7 +351,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -351,7 +351,7 @@ class TestCMFCategory(ERP5TypeTestCase):
parent_uid_list2 = cat2.getCategoryParentUidList(relative_url = cat2.getRelativeUrl()) parent_uid_list2 = cat2.getCategoryParentUidList(relative_url = cat2.getRelativeUrl())
parent_uid_list2.sort() parent_uid_list2.sort()
self.assertEqual(parent_uid_list2, parent_uid_list) self.assertEqual(parent_uid_list2, parent_uid_list)
def test_10_FallBackBaseCategory(self, quiet=quiet, run=run_all_test): def test_10_FallBackBaseCategory(self, quiet=quiet, run=run_all_test):
# Test if we can use an alternative base category # Test if we can use an alternative base category
if not run: return if not run: return
...@@ -365,7 +365,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -365,7 +365,7 @@ class TestCMFCategory(ERP5TypeTestCase):
self.assertEqual(p1.getGenderValue(),None) self.assertEqual(p1.getGenderValue(),None)
p1.setSubordinationValue(o1) p1.setSubordinationValue(o1)
self.assertEqual(p1.getGenderValue(),o1) self.assertEqual(p1.getGenderValue(),o1)
def test_FallBackAcquisitionIsMemberOf(self): def test_FallBackAcquisitionIsMemberOf(self):
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
o1 = self.getOrganisationModule()._getOb(self.id1) o1 = self.getOrganisationModule()._getOb(self.id1)
...@@ -386,7 +386,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -386,7 +386,7 @@ class TestCMFCategory(ERP5TypeTestCase):
p1.setRegion(self.region1) p1.setRegion(self.region1)
self.assertEqual(p1.getRegion(),self.region1) self.assertEqual(p1.getRegion(),self.region1)
self.assertEqual(sub_person.getRegion(),self.region1) self.assertEqual(sub_person.getRegion(),self.region1)
def test_parentAcquisitionIsMemberOf(self): def test_parentAcquisitionIsMemberOf(self):
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
sub_person = p1._getOb(self.id1) sub_person = p1._getOb(self.id1)
...@@ -401,7 +401,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -401,7 +401,7 @@ class TestCMFCategory(ERP5TypeTestCase):
self.failUnless(p1.isMemberOf('region/%s' % self.region1)) self.failUnless(p1.isMemberOf('region/%s' % self.region1))
sub_person.setRegion(self.region2) sub_person.setRegion(self.region2)
self.failUnless(sub_person.isMemberOf('region/%s' % self.region2)) self.failUnless(sub_person.isMemberOf('region/%s' % self.region2))
def test_12_GetRelatedValueAndValueList(self, quiet=quiet, run=run_all_test): def test_12_GetRelatedValueAndValueList(self, quiet=quiet, run=run_all_test):
# Test if an infinite loop of the acquisition for a single value is working # Test if an infinite loop of the acquisition for a single value is working
# Typical error results from bad brain (do not copy, use aliases for zsqlbrain.py) # Typical error results from bad brain (do not copy, use aliases for zsqlbrain.py)
...@@ -415,7 +415,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -415,7 +415,7 @@ class TestCMFCategory(ERP5TypeTestCase):
o1 = self.getOrganisationModule()._getOb(self.id1) o1 = self.getOrganisationModule()._getOb(self.id1)
p1.setGenderValue(o1) p1.setGenderValue(o1)
get_transaction().commit() get_transaction().commit()
self.tic() # This is required self.tic() # This is required
self.assertEqual(p1.getGenderValue(),o1) self.assertEqual(p1.getGenderValue(),o1)
self.assertEqual(o1.getGenderRelatedValueList(),[p1]) self.assertEqual(o1.getGenderRelatedValueList(),[p1])
...@@ -430,22 +430,22 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -430,22 +430,22 @@ class TestCMFCategory(ERP5TypeTestCase):
if not quiet: if not quiet:
ZopeTestCase._print('\n Test Category Renaming') ZopeTestCase._print('\n Test Category Renaming')
LOG('Testing... ',0,'Category Renaming') LOG('Testing... ',0,'Category Renaming')
portal = self.getPortal() portal = self.getPortal()
france = portal.portal_categories.resolveCategory( france = portal.portal_categories.resolveCategory(
'region/europe/west/france') 'region/europe/west/france')
self.assertNotEqual(france, None) self.assertNotEqual(france, None)
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegion('europe/west/france') p1.setRegion('europe/west/france')
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
west = portal.portal_categories.resolveCategory('region/europe/west') west = portal.portal_categories.resolveCategory('region/europe/west')
west.setId("ouest") west.setId("ouest")
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
self.assertEqual(west, self.assertEqual(west,
portal.portal_categories.resolveCategory('region/europe/ouest')) portal.portal_categories.resolveCategory('region/europe/ouest'))
self.assertEqual(p1.getRegion(), 'europe/ouest/france') self.assertEqual(p1.getRegion(), 'europe/ouest/france')
...@@ -456,29 +456,29 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -456,29 +456,29 @@ class TestCMFCategory(ERP5TypeTestCase):
if not quiet: if not quiet:
ZopeTestCase._print('\n Test Category Renaming with cut n paste') ZopeTestCase._print('\n Test Category Renaming with cut n paste')
LOG('Testing... ',0,'Category Renaming') LOG('Testing... ',0,'Category Renaming')
portal = self.getPortal() portal = self.getPortal()
france = portal.portal_categories.resolveCategory( france = portal.portal_categories.resolveCategory(
'region/europe/west/france') 'region/europe/west/france')
self.assertNotEqual(france, None) self.assertNotEqual(france, None)
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegion('europe/west/france') p1.setRegion('europe/west/france')
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
europe = portal.portal_categories.resolveCategory('region/europe') europe = portal.portal_categories.resolveCategory('region/europe')
west = europe.west west = europe.west
cb_data = europe.manage_cutObjects(['west']) cb_data = europe.manage_cutObjects(['west'])
portal.portal_categories.region.manage_pasteObjects(cb_data) portal.portal_categories.region.manage_pasteObjects(cb_data)
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
self.assertEqual(west, self.assertEqual(west,
portal.portal_categories.resolveCategory('region/west')) portal.portal_categories.resolveCategory('region/west'))
self.assertEqual(p1.getRegion(), 'west/france') self.assertEqual(p1.getRegion(), 'west/france')
self.failUnless(p1 in west.getRegionRelatedValueList()) self.failUnless(p1 in west.getRegionRelatedValueList())
def test_13c_RenameCategoryUsingCutAndPasteButNotCopy( def test_13c_RenameCategoryUsingCutAndPasteButNotCopy(
self, quiet=quiet, run=run_all_test) : self, quiet=quiet, run=run_all_test) :
if not run: return if not run: return
...@@ -486,31 +486,31 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -486,31 +486,31 @@ class TestCMFCategory(ERP5TypeTestCase):
ZopeTestCase._print('\n Test Category Renaming with cut n paste, ' ZopeTestCase._print('\n Test Category Renaming with cut n paste, '
'copy n paste doesnt change') 'copy n paste doesnt change')
LOG('Testing... ',0,'Category Renaming') LOG('Testing... ',0,'Category Renaming')
portal = self.getPortal() portal = self.getPortal()
france = portal.portal_categories.resolveCategory( france = portal.portal_categories.resolveCategory(
'region/europe/west/france') 'region/europe/west/france')
self.assertNotEqual(france, None) self.assertNotEqual(france, None)
p1 = self.getPersonModule()._getOb(self.id1) p1 = self.getPersonModule()._getOb(self.id1)
p1.setRegion('europe/west/france') p1.setRegion('europe/west/france')
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
europe = portal.portal_categories.resolveCategory('region/europe') europe = portal.portal_categories.resolveCategory('region/europe')
west = europe.west west = europe.west
cb_data = europe.manage_copyObjects(['west']) cb_data = europe.manage_copyObjects(['west'])
portal.portal_categories.region.manage_pasteObjects(cb_data) portal.portal_categories.region.manage_pasteObjects(cb_data)
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
self.assertEqual(west, self.assertEqual(west,
portal.portal_categories.resolveCategory('region/europe/west')) portal.portal_categories.resolveCategory('region/europe/west'))
self.assertEqual(p1.getRegion(), 'europe/west/france') self.assertEqual(p1.getRegion(), 'europe/west/france')
# we are not member of the copy # we are not member of the copy
self.failUnless('west/france' not in p1.getRegionList()) self.failUnless('west/france' not in p1.getRegionList())
self.failUnless(p1 in west.getRegionRelatedValueList()) self.failUnless(p1 in west.getRegionRelatedValueList())
def test_14_MultiplePortalTypes(self, quiet=quiet, run=run_all_test) : def test_14_MultiplePortalTypes(self, quiet=quiet, run=run_all_test) :
""" Checks that categories support different value per portal_type, """ Checks that categories support different value per portal_type,
...@@ -522,16 +522,16 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -522,16 +522,16 @@ class TestCMFCategory(ERP5TypeTestCase):
LOG('Testing... ', 0, message) LOG('Testing... ', 0, message)
portal = self.getPortal() portal = self.getPortal()
folder = self.getOrganisationModule() folder = self.getOrganisationModule()
org_a = folder.newContent(portal_type='Organisation', id="org_a") org_a = folder.newContent(portal_type='Organisation', id="org_a")
org_b = folder.newContent(portal_type='Organisation', id="org_b") org_b = folder.newContent(portal_type='Organisation', id="org_b")
org_a.setDestinationValue(org_b) org_a.setDestinationValue(org_b)
self.assertEqual(org_a.getDestinationValue(), org_b) self.assertEqual(org_a.getDestinationValue(), org_b)
pers_a = self.getPersonModule().newContent( pers_a = self.getPersonModule().newContent(
portal_type='Person', id='pers_a') portal_type='Person', id='pers_a')
for loop in range(3) : for loop in range(3) :
org_a.setDestinationValue(pers_a, portal_type='Person') org_a.setDestinationValue(pers_a, portal_type='Person')
self.assertEquals( self.assertEquals(
...@@ -539,7 +539,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -539,7 +539,7 @@ class TestCMFCategory(ERP5TypeTestCase):
self.assertEquals( self.assertEquals(
org_a.getDestinationValue(portal_type='Organisation'), org_b) org_a.getDestinationValue(portal_type='Organisation'), org_b)
self.assertEquals(len(org_a.getDestinationValueList()), 2) self.assertEquals(len(org_a.getDestinationValueList()), 2)
org_a.setDestinationValue(org_b, portal_type='Organisation') org_a.setDestinationValue(org_b, portal_type='Organisation')
self.assertEquals( self.assertEquals(
org_a.getDestinationValue(portal_type='Person'), pers_a) org_a.getDestinationValue(portal_type='Person'), pers_a)
...@@ -554,7 +554,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -554,7 +554,7 @@ class TestCMFCategory(ERP5TypeTestCase):
message = 'Test Sort Child Values' message = 'Test Sort Child Values'
ZopeTestCase._print('\n '+message) ZopeTestCase._print('\n '+message)
LOG('Testing... ', 0, message) LOG('Testing... ', 0, message)
pc = self.getCategoriesTool() pc = self.getCategoriesTool()
bc = pc.newContent(portal_type='Base Category', id='sort_test') bc = pc.newContent(portal_type='Base Category', id='sort_test')
self.failUnless(bc is not None) self.failUnless(bc is not None)
...@@ -562,7 +562,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -562,7 +562,7 @@ class TestCMFCategory(ERP5TypeTestCase):
bc.newContent(portal_type='Category', id='2', title='b', int_index=1) bc.newContent(portal_type='Category', id='2', title='b', int_index=1)
bc.newContent(portal_type='Category', id='3', title='c', int_index=1) bc.newContent(portal_type='Category', id='3', title='c', int_index=1)
# simple sorting # simple sorting
category_list = bc.getCategoryChildValueList(sort_on='title') category_list = bc.getCategoryChildValueList(sort_on='title')
self.assertEquals(len(category_list), 3) self.assertEquals(len(category_list), 3)
self.assertEquals(category_list[0].getId(), '1') self.assertEquals(category_list[0].getId(), '1')
...@@ -596,7 +596,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -596,7 +596,7 @@ class TestCMFCategory(ERP5TypeTestCase):
self.assertEquals(category_list[0].getId(), '1') self.assertEquals(category_list[0].getId(), '1')
self.assertEquals(category_list[1].getId(), '2') self.assertEquals(category_list[1].getId(), '2')
self.assertEquals(category_list[2].getId(), '3') self.assertEquals(category_list[2].getId(), '3')
def test_16_GetRelatedValues(self, quiet=quiet, run=run_all_test) : def test_16_GetRelatedValues(self, quiet=quiet, run=run_all_test) :
""" Checks on getting related values""" """ Checks on getting related values"""
if not run: return if not run: return
...@@ -604,7 +604,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -604,7 +604,7 @@ class TestCMFCategory(ERP5TypeTestCase):
message = 'Test Get Related Values' message = 'Test Get Related Values'
ZopeTestCase._print('\n '+message) ZopeTestCase._print('\n '+message)
LOG('Testing... ', 0, message) LOG('Testing... ', 0, message)
pc = self.getCategoriesTool() pc = self.getCategoriesTool()
bc = pc.newContent(portal_type='Base Category', id='related_value_test') bc = pc.newContent(portal_type='Base Category', id='related_value_test')
self.failUnless(bc is not None) self.failUnless(bc is not None)
...@@ -613,7 +613,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -613,7 +613,7 @@ class TestCMFCategory(ERP5TypeTestCase):
# A newly created base category should be referred to only by itself # A newly created base category should be referred to only by itself
value_list = pc.getRelatedValueList(bc) value_list = pc.getRelatedValueList(bc)
self.assertEquals(len(value_list), 1) self.assertEquals(len(value_list), 1)
c = bc.newContent(portal_type='Category', id='1') c = bc.newContent(portal_type='Category', id='1')
self.failUnless(c is not None) self.failUnless(c is not None)
get_transaction().commit() get_transaction().commit()
...@@ -624,7 +624,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -624,7 +624,7 @@ class TestCMFCategory(ERP5TypeTestCase):
# This sub category should be referred to only by itself # This sub category should be referred to only by itself
value_list = pc.getRelatedValueList(c) value_list = pc.getRelatedValueList(c)
self.assertEquals(len(value_list), 1) self.assertEquals(len(value_list), 1)
#test _getDefaultRelatedProperty Accessor #test _getDefaultRelatedProperty Accessor
person = self.getPortal().person_module.newContent(id='person_test') person = self.getPortal().person_module.newContent(id='person_test')
org = self.getPortal().organisation_module.newContent(id='organisation_test',destination='person_module/person_test') org = self.getPortal().organisation_module.newContent(id='organisation_test',destination='person_module/person_test')
...@@ -640,7 +640,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -640,7 +640,7 @@ class TestCMFCategory(ERP5TypeTestCase):
message = 'Test Domain Selection and Categories' message = 'Test Domain Selection and Categories'
ZopeTestCase._print('\n '+message) ZopeTestCase._print('\n '+message)
LOG('Testing... ', 0, message) LOG('Testing... ', 0, message)
category_tool = self.getCategoryTool() category_tool = self.getCategoryTool()
base = category_tool.newContent(portal_type = 'Base Category', base = category_tool.newContent(portal_type = 'Base Category',
id='test_base_cat') id='test_base_cat')
...@@ -696,36 +696,36 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -696,36 +696,36 @@ class TestCMFCategory(ERP5TypeTestCase):
message = 'Test strict_membership and Category Member Value List' message = 'Test strict_membership and Category Member Value List'
ZopeTestCase._print('\n '+message) ZopeTestCase._print('\n '+message)
LOG('Testing... ',0,message) LOG('Testing... ',0,message)
portal_categories = self.getCategoryTool() portal_categories = self.getCategoryTool()
organisation = self.getOrganisationModule().newContent( organisation = self.getOrganisationModule().newContent(
portal_type='Organisation', region='west/france') portal_type='Organisation', region='west/france')
get_transaction().commit() get_transaction().commit()
self.tic() self.tic()
self.assertEquals([x.getObject() for x in self.assertEquals([x.getObject() for x in
portal_categories.getCategoryMemberValueList( portal_categories.getCategoryMemberValueList(
portal_categories.region.west.france, portal_categories.region.west.france,
base_category='region', base_category='region',
strict_membership=0, strict_membership=0,
portal_type='Organisation')], [organisation]) portal_type='Organisation')], [organisation])
self.assertEquals([x.getObject() for x in self.assertEquals([x.getObject() for x in
portal_categories.getCategoryMemberValueList( portal_categories.getCategoryMemberValueList(
portal_categories.region.west.france, portal_categories.region.west.france,
base_category='region', base_category='region',
strict_membership=1, strict_membership=1,
portal_type='Organisation')], [organisation]) portal_type='Organisation')], [organisation])
self.assertEquals([x.getObject() for x in self.assertEquals([x.getObject() for x in
portal_categories.getCategoryMemberValueList( portal_categories.getCategoryMemberValueList(
portal_categories.region.west, portal_categories.region.west,
base_category='region', base_category='region',
strict_membership=0, strict_membership=0,
portal_type='Organisation')], [organisation]) portal_type='Organisation')], [organisation])
self.assertEquals([x.getObject() for x in self.assertEquals([x.getObject() for x in
portal_categories.getCategoryMemberValueList( portal_categories.getCategoryMemberValueList(
portal_categories.region.west, portal_categories.region.west,
base_category='region', base_category='region',
...@@ -745,7 +745,7 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -745,7 +745,7 @@ class TestCMFCategory(ERP5TypeTestCase):
id='the_id', title='The Title') id='the_id', title='The Title')
self.assertEquals([['', ''], ['The Title (the_id)', 'the_id']], self.assertEquals([['', ''], ['The Title (the_id)', 'the_id']],
base_cat.getCategoryChildTitleAndIdItemList()) base_cat.getCategoryChildTitleAndIdItemList())
def test_21_AcquiredPortalType(self, quiet=quiet, run=run_all_test): def test_21_AcquiredPortalType(self, quiet=quiet, run=run_all_test):
"""Test if acquired_portal_type works correctly.""" """Test if acquired_portal_type works correctly."""
if not run : return if not run : return
...@@ -772,6 +772,33 @@ class TestCMFCategory(ERP5TypeTestCase): ...@@ -772,6 +772,33 @@ class TestCMFCategory(ERP5TypeTestCase):
packing_list.setCausalityValue(order) packing_list.setCausalityValue(order)
self.assertEquals(packing_list.getDestinationAdministrationPersonTitle(), 'toto') self.assertEquals(packing_list.getDestinationAdministrationPersonTitle(), 'toto')
def test_22_UserFriendlyException(self, quiet=quiet, run=run_all_test):
"""Test message raise if bad use of setter."""
if not run : return
if not quiet:
message = 'Test User Friendly Exception'
ZopeTestCase._print('\n '+message)
LOG('Testing... ',0,message)
person_module = self.getPersonModule()
portal = self.getPortal()
person_module = self.getPersonModule()
if self.id1 not in person_module.objectIds():
p1 = person_module.newContent(id=self.id1, title=self.id1)
else:
p1 = person_module._getOb(self.id1)
organisation_module = self.getOrganisationModule()
organisation_module = self.getOrganisationModule()
if self.id1 not in organisation_module.objectIds():
o1 = organisation_module.newContent(id=self.id1)
else:
o1 = organisation_module._getOb(self.id1)
try:
p1.setCareerSubordination(o1)
except Exception, e:
self.failUnless(isinstance(e, TypeError))
self.assertEqual(e.args[0], 'Category must be a string.')
if __name__ == '__main__': if __name__ == '__main__':
framework() framework()
else: else:
......
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