Commit e13a75d2 authored by Jérome Perrin's avatar Jérome Perrin

r20200 changed behaviour of relation to non existant objects. Restore the

previous behaviour with a test to clarify the behaviour.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@20221 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 70fd4a77
...@@ -2007,7 +2007,9 @@ class Base( CopyContainer, ...@@ -2007,7 +2007,9 @@ class Base( CopyContainer,
ref_list = [] ref_list = []
for path in self._getAcquiredCategoryMembershipList(id, base=1, for path in self._getAcquiredCategoryMembershipList(id, base=1,
spec=spec, filter=filter, **kw): spec=spec, filter=filter, **kw):
ref_list.append(self._getCategoryTool().resolveCategory(path)) category = self._getCategoryTool().resolveCategory(path)
if category is not None:
ref_list.append(category)
return ref_list return ref_list
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
import md5 import md5
import unittest import unittest
import sys
from random import randint from random import randint
from Testing import ZopeTestCase from Testing import ZopeTestCase
...@@ -1823,6 +1824,46 @@ class TestPropertySheet: ...@@ -1823,6 +1824,46 @@ class TestPropertySheet:
self.assertRaises(Unauthorized, foo.getRegionValue) self.assertRaises(Unauthorized, foo.getRegionValue)
self.assertRaises(Unauthorized, foo.getRegionTitle) self.assertRaises(Unauthorized, foo.getRegionTitle)
def test_category_accessor_to_non_existing_documents(self):
# tests behaviour of category accessors with relations to non existing
# documents.
region_category = self.getPortal().portal_categories.region
beta_id = "beta"
beta_title = "Beta System"
beta = region_category.newContent(
portal_type = "Category",
id = beta_id,
title = beta_title, )
beta_path = beta.getCategoryRelativeUrl()
# gamma does not exist
# Make sure categories are reindexed
get_transaction().commit()
self.tic()
# Create a new person, and associate it to beta and gamma.
module = self.getPersonModule()
foo = module.newContent(portal_type='Person', title='Foo')
foo.setRegionList(('beta', 'gamma'))
self.assertEquals([beta_path, 'gamma'],
foo.getRegionList())
# using relations to non existant objects will issue a warning in
# event.log
self._catch_log_errors(ignored_level=sys.maxint)
self.assertEquals([beta],
foo.getRegionValueList())
self.assertEquals([beta_title],
foo.getRegionTitleList())
self._ignore_log_errors()
logged_errors = [ logrecord for logrecord in self.logged
if logrecord[0] == 'CMFCategory' ]
self.assertEquals('Could not access object region/gamma',
logged_errors[0][2])
def test_list_accessors(self): def test_list_accessors(self):
self._addProperty('Person', '''{'id': 'dummy', self._addProperty('Person', '''{'id': 'dummy',
'type': 'lines', 'type': 'lines',
......
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