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 nexedi/erp5!986
parent cce8da26
Pipeline #6813 failed with stage
in 0 seconds
......@@ -37,7 +37,7 @@ class MissingCategoryDocumentConstraint(ConstraintMixin):
error_list = []
category_tool = obj.getPortalObject().portal_categories
for category in obj.getCategoryList():
if category_tool.unrestrictedTraverse(category, None) is None:
if category_tool.resolveCategory(category) is None:
error_list.append(
self._generateError(
obj,
......
......@@ -156,10 +156,25 @@ class TestERP5Administration(InventoryAPITestCase):
portal_type='Missing Category Document Constraint',
temp_object=True,
).checkConsistency(person)
self.assertEquals(
self.assertEqual(
'Category group/not/exist on object %s is missing.' % person.getRelativeUrl(),
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():
suite = unittest.TestSuite()
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