Commit 27912c0f authored by Jean-Paul Smets's avatar Jean-Paul Smets

More fixes - more unit tests

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@10208 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0250bbbc
......@@ -1331,17 +1331,21 @@ class Base( CopyContainer, PortalContent, ActiveObject, Historical, ERP5Property
security.declareProtected( Permissions.ModifyPortalContent, '_setDefaultValue' )
def _setDefaultValue(self, id, target, spec=(), filter=None, portal_type=()):
start_string = "%s/" % id
start_string_len = len(start_string)
if target is None :
path = target
elif isinstance(target, str):
# We have been provided a string
path = target
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
else:
# We have been provided an object
# Find the object
path = target.getRelativeUrl()
if path.startswith(start_string): path = path[start_string_len:] # Prevent duplicating base category
self._setDefaultCategoryMembership(id, path, spec=spec, filter=filter,
portal_type=portal_type, base=1)
portal_type=portal_type, base=0)
security.declareProtected( Permissions.ModifyPortalContent, 'setDefaultValue' )
def setDefaultValue(self, id, target, spec=(), filter=None, portal_type=()):
......
......@@ -439,6 +439,9 @@ class TestPropertySheet:
from Products.ERP5Type.Utils import ConstraintNotFound
organisation = self.assertRaises(ConstraintNotFound,folder.newContent,
portal_type='Organisation')
# Cleanup for next test
organisation_portal_type.setPropertySheetList([])
_aq_reset()
def test_11_valueAccessor(self, quiet=quiet, run=run_all_test):
"""
......@@ -475,20 +478,30 @@ class TestPropertySheet:
portal_type = "Category",
id = "zeta",
title = "Zeta System", )
function_category = self.getPortal().portal_categories.function
nofunction = function_category.newContent(
portal_type = "Category",
id = "nofunction",
title = "No Function", )
self.assertEquals(alpha.getRelativeUrl(), 'region/alpha')
#get_transaction().commit()
alpha.immediateReindexObject()
beta.immediateReindexObject()
zeta.immediateReindexObject()
#self.tic() # Make sure categories are reindexed
alpha.reindexObject()
beta.reindexObject()
zeta.reindexObject()
nofunction.reindexObject()
get_transaction().commit()
self.tic() # Make sure categories are reindexed
# Create a new person
module = self.getPersonModule()
person = module.newContent(portal_type='Person')
# Value setters (list, set, default)
person.setFunction('nofunction') # Fill at least one other category
person.setDefaultRegionValue(alpha)
self.assertEquals(person.getDefaultRegion(), 'alpha')
self.assertEquals(person.getRegion(), 'alpha')
person.setRegionValue(alpha)
self.assertEquals(person.getRegion(), 'alpha')
person.setRegionValueList([alpha, alpha])
......@@ -513,8 +526,19 @@ class TestPropertySheet:
result.sort()
self.assertEquals(result, ['alpha', 'beta'])
self.assertEquals(person.getRegionList(), ['alpha', 'beta'])
# Test accessor on documents rather than on categories
person.setDefaultRegionValue(person)
self.assertEquals(person.getDefaultRegion(), person.getRelativeUrl())
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
person.setRegionValue([person, alpha, beta])
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
# Category setters (list, set, default)
person = module.newContent(portal_type='Person')
person.setFunction('nofunction') # Fill at least one other category
person.setDefaultRegion('alpha')
self.assertEquals(person.getRegion(), 'alpha')
self.assertEquals(person.getDefaultRegion(), 'alpha')
person.setRegion('alpha')
self.assertEquals(person.getRegion(), 'alpha')
person.setRegionList(['alpha', 'alpha'])
......@@ -539,8 +563,22 @@ class TestPropertySheet:
result.sort()
self.assertEquals(result, ['alpha', 'beta'])
self.assertEquals(person.getRegionList(), ['alpha', 'beta'])
# Test accessor on documents rather than on categories
person.setDefaultRegion(person.getRelativeUrl())
self.assertEquals(person.getDefaultRegion(), person.getRelativeUrl())
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
person.setRegion([person.getRelativeUrl(), 'alpha', 'beta'])
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
# Uid setters (list, set, default)
person = module.newContent(portal_type='Person')
person.reindexObject()
get_transaction().commit()
self.tic() # Make sure person is reindexed
person.setFunction('nofunction') # Fill at least one other category
person.setDefaultRegionUid(alpha.getUid())
self.assertEquals(person.getRegion(), 'alpha')
self.assertEquals(person.getDefaultRegion(), 'alpha')
person.setRegionUid(alpha.getUid())
self.assertEquals(person.getRegion(), 'alpha')
person.setRegionUidList([alpha.getUid(), alpha.getUid()])
......@@ -565,6 +603,12 @@ class TestPropertySheet:
result.sort()
self.assertEquals(result, ['alpha', 'beta'])
self.assertEquals(person.getRegionList(), ['alpha', 'beta'])
# Test accessor on documents rather than on categories
person.setDefaultRegionUid(person.getUid())
self.assertEquals(person.getDefaultRegion(), person.getRelativeUrl())
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
person.setRegionUid([person.getUid(), alpha.getUid(), beta.getUid()])
self.assertEquals(person.getRegionList(), [person.getRelativeUrl(), 'alpha', 'beta'])
def test_12_listAccessor(self, quiet=quiet, run=run_all_test):
"""
......
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