Commit 936a8cea authored by Jérome Perrin's avatar Jérome Perrin

Fail with explicit error when searchPredicateList is passed a context with non existant categories

parent 52358c8a
...@@ -1587,9 +1587,14 @@ class CategoryTool( UniqueObject, Folder, Base ): ...@@ -1587,9 +1587,14 @@ class CategoryTool( UniqueObject, Folder, Base ):
if len(category_uid_list) == 0: if len(category_uid_list) == 0:
# New base category, append it to the ordered list. # New base category, append it to the ordered list.
ordered_base_category_uid_list.append(base_category_uid) ordered_base_category_uid_list.append(base_category_uid)
category_uid_list.append(self.getCategoryUid(category)) category_uid = self.getCategoryUid(category)
else: category_uid_list.append(category_uid)
LOG('CategoryTool', 0, 'Received invalid category %r' % (category, ))
if category_uid is None and category != 'NULL':
raise TypeError(
"Invalid category passed to buildAdvancedSQLSelector: %r"
% category )
# Generate "left join" and "where" expressions. # Generate "left join" and "where" expressions.
left_join_list = [catalog_table_name] left_join_list = [catalog_table_name]
where_expression_list = [] where_expression_list = []
......
...@@ -649,6 +649,38 @@ class TestDomainTool(TestPredicateMixIn): ...@@ -649,6 +649,38 @@ class TestDomainTool(TestPredicateMixIn):
tested_base_category_list=['WAAA', 'BOOO'], tested_base_category_list=['WAAA', 'BOOO'],
src__=1)) src__=1))
def test_searchPredicateInvalidCategories(self):
predicate = self.portal.sale_supply_module.newContent(
portal_type='Sale Supply')
predicate.validate()
self.assertNotEquals(predicate.asPredicate(), None)
context = self.portal.person_module.newContent(
portal_type='Person',
region=('broken/category'))
# An invalid category should raise explicitly, for all parameters of
# searchPredicateList ( the code paths are different )
self.assertRaises(TypeError, self.portal.portal_domains.searchPredicateList,
context=context, portal_type=predicate.portal_type)
self.assertRaises(TypeError, self.portal.portal_domains.searchPredicateList,
context=context, portal_type=predicate.portal_type, acquired=False)
self.assertRaises(TypeError, self.portal.portal_domains.searchPredicateList,
context=context, portal_type=predicate.portal_type,
tested_base_category_list=['region'])
self.assertRaises(TypeError, self.portal.portal_domains.searchPredicateList,
context=context, portal_type=predicate.portal_type,
tested_base_category_list=['region'], acquired=False)
# This is also the case if there are multiple categories (another code
# path)
context = self.portal.person_module.newContent(
portal_type='Person',
region=('broken/category', 'region'))
self.assertRaises(TypeError, self.portal.portal_domains.searchPredicateList,
context=context, portal_type=predicate.portal_type)
def test_setRelationToBaseDomain(self): def test_setRelationToBaseDomain(self):
# category accessors can be useed to set relations to base domains. # category accessors can be useed to set relations to base domains.
base_domain = self.portal.portal_domains.newContent( base_domain = self.portal.portal_domains.newContent(
......
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