Commit 7c90c3be authored by Jérome Perrin's avatar Jérome Perrin

administration: fix MissingCategoryDocumentConstraint with acquisition

MissingCategoryDocumentConstraint was incorrectly using
unrestrictedTraverse, unlike category API which uses its own
resolveCategory method with better semantics.

Because of this, some problems were not reported:
 - categories using paths that resolve by acquisition, but does not
exists as such (like in the test)
 - categories using path with dynamic objects, like a website language.

/reviewed-on !986
parent cce8da26
...@@ -37,7 +37,7 @@ class MissingCategoryDocumentConstraint(ConstraintMixin): ...@@ -37,7 +37,7 @@ class MissingCategoryDocumentConstraint(ConstraintMixin):
error_list = [] error_list = []
category_tool = obj.getPortalObject().portal_categories category_tool = obj.getPortalObject().portal_categories
for category in obj.getCategoryList(): for category in obj.getCategoryList():
if category_tool.unrestrictedTraverse(category, None) is None: if category_tool.resolveCategory(category) is None:
error_list.append( error_list.append(
self._generateError( self._generateError(
obj, obj,
......
...@@ -156,10 +156,25 @@ class TestERP5Administration(InventoryAPITestCase): ...@@ -156,10 +156,25 @@ class TestERP5Administration(InventoryAPITestCase):
portal_type='Missing Category Document Constraint', portal_type='Missing Category Document Constraint',
temp_object=True, temp_object=True,
).checkConsistency(person) ).checkConsistency(person)
self.assertEquals( self.assertEqual(
'Category group/not/exist on object %s is missing.' % person.getRelativeUrl(), 'Category group/not/exist on object %s is missing.' % person.getRelativeUrl(),
str(consistency_error.getTranslatedMessage())) str(consistency_error.getTranslatedMessage()))
def test_missing_category_document_constraint_acquisition(self):
person = self.portal.person_module.newContent(portal_type='Person')
# This constraint is not confused by acquisition. group/level1/test_group can
# be traversed, but category API does not use simple traversal.
person.setCategoryList(['group/level1/test_group'])
consistency_error, = self.portal.portal_trash.newContent(
portal_type='Missing Category Document Constraint',
temp_object=True,
).checkConsistency(person)
self.assertEqual(
'Category group/level1/test_group on object %s is missing.' % person.getRelativeUrl(),
str(consistency_error.getTranslatedMessage()))
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Administration)) suite.addTest(unittest.makeSuite(TestERP5Administration))
......
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