Commit 3310c231 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Modernize the test with portal_activities. This triggers another failure, but...

Modernize the test with portal_activities. This triggers another failure, but it is not a fault in this test itself. It is a problem in CMFCategory (or ERP5Type). The problem is that updateRelatedContent may be executed after reindexObject, and updateRelatedContent or notifyAfterUpdateRelatedContent does not call reindexObject. So the catalog becomes inconsistent.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14504 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent e694d57a
...@@ -62,12 +62,6 @@ class TestERP5Category(ERP5TypeTestCase): ...@@ -62,12 +62,6 @@ class TestERP5Category(ERP5TypeTestCase):
""" """
return ('erp5_base',) return ('erp5_base',)
def enableActivityTool(self):
"""
You can override this. Return if we should create (1) or not (0) an activity tool
"""
return 0
def getPortalId(self): def getPortalId(self):
return self.getPortal().getId() return self.getPortal().getId()
...@@ -83,34 +77,57 @@ class TestERP5Category(ERP5TypeTestCase): ...@@ -83,34 +77,57 @@ class TestERP5Category(ERP5TypeTestCase):
portal_categories = self.getCategoryTool() portal_categories = self.getCategoryTool()
person_module = self.getPersonModule() person_module = self.getPersonModule()
bc = self.base_cat bc = self.base_cat
portal_categories.newContent(portal_type='Base Category',id=bc) if bc not in portal_categories.objectIds():
self.cat1 = portal_categories[bc].newContent(id='1',portal_type='Category') portal_categories.newContent(portal_type='Base Category', id=bc)
self.deep_cat1 = self.cat1.newContent(id='1',portal_type='Category') if not portal_categories[bc].has_key('1'):
self.cat2 = portal_categories[bc].newContent(id='2',portal_type='Category') portal_categories[bc].newContent(id='1', portal_type='Category')
self.deep_cat2 = self.cat2.newContent(id='1',portal_type='Category') self.cat1 = portal_categories[bc]['1']
portal_categories[self.base_cat].recursiveImmediateReindexObject() if not self.cat1.has_key('1'):
self.cat1.newContent(id='1', portal_type='Category')
self.deep_cat1 = self.cat1['1']
if not portal_categories[bc].has_key('2'):
portal_categories[bc].newContent(id='2', portal_type='Category')
self.cat2 = portal_categories[bc]['2']
if not self.cat2.has_key('1'):
self.cat2.newContent(id='1', portal_type='Category')
self.deep_cat2 = self.cat2['1']
portal_type = self.getTypeTool()[self.portal_type] portal_type = self.getTypeTool()[self.portal_type]
portal_type.base_category_list = [self.base_cat, self.base_cat2] portal_type.base_category_list = [self.base_cat, self.base_cat2]
# Reset aq dynamic # Reset aq dynamic
_aq_reset() _aq_reset()
organisation_module = self.getOrganisationModule() organisation_module = self.getOrganisationModule()
self.organisation = organisation_module.newContent(id='1',portal_type=self.portal_type) if not organisation_module.has_key('1'):
self.organisation.immediateReindexObject() organisation_module.newContent(id='1', portal_type=self.portal_type)
self.telephone = self.organisation.newContent(id='1',portal_type='Telephone') self.organisation = organisation_module['1']
self.organisation2 = organisation_module.newContent(id='2',portal_type=self.portal_type) if not self.organisation.has_key('1'):
self.organisation2.immediateReindexObject() self.organisation.newContent(id='1', portal_type='Telephone')
self.telephone2 = self.organisation2.newContent(id='1',portal_type='Telephone') self.telephone = self.organisation['1']
self.person = person_module.newContent(portal_type = 'Person') if not organisation_module.has_key('2'):
self.person.immediateReindexObject() organisation_module.newContent(id='2', portal_type=self.portal_type)
self.organisation2 = organisation_module['2']
if not self.organisation2.has_key('1'):
self.organisation2.newContent(id='1', portal_type='Telephone')
self.telephone2 = self.organisation2['1']
if not person_module.has_key('1'):
person_module.newContent(id='1', portal_type = 'Person')
self.person = person_module['1']
bc2 = self.base_cat2 bc2 = self.base_cat2
portal_categories.newContent(portal_type='Base Category',id=bc2) if bc2 not in portal_categories.objectIds():
self.efg_l1=portal_categories[bc2].newContent(id='1',portal_type='Category') portal_categories.newContent(portal_type='Base Category', id=bc2)
self.efg_l2=self.efg_l1.newContent(id='11',portal_type='Category') if not portal_categories[bc2].has_key('1'):
self.efg_l3=self.efg_l2.newContent(id='111',portal_type='Category') portal_categories[bc2].newContent(id='1', portal_type='Category')
self.efg_l4=self.efg_l3.newContent(id='1111',portal_type='Category') self.efg_l1 = portal_categories[bc2]['1']
portal_categories[self.base_cat2].recursiveImmediateReindexObject() if not self.efg_l1.has_key('11'):
self.efg_l1.newContent(id='11', portal_type='Category')
self.efg_l2 = self.efg_l1['11']
if not self.efg_l2.has_key('111'):
self.efg_l2.newContent(id='111', portal_type='Category')
self.efg_l3 = self.efg_l2['111']
if not self.efg_l3.has_key('1111'):
self.efg_l3.newContent(id='1111',portal_type='Category')
self.efg_l4 = self.efg_l3['1111']
# We have no place to put a Predicate, we will put it in the # We have no place to put a Predicate, we will put it in the
# Organisation Module # Organisation Module
...@@ -119,12 +136,31 @@ class TestERP5Category(ERP5TypeTestCase): ...@@ -119,12 +136,31 @@ class TestERP5Category(ERP5TypeTestCase):
module_type = type_tool['%s Module' % self.portal_type] module_type = type_tool['%s Module' % self.portal_type]
module_type.allowed_content_types += ('Mapped Value',) module_type.allowed_content_types += ('Mapped Value',)
module = self.getOrganisationModule() module = self.getOrganisationModule()
predicate = module.newContent(id='predicate',portal_type='Mapped Value') if not module.has_key('predicate'):
predicate.setCriterion('quantity',identity=None,min=None,max=None) module.newContent(id='predicate', portal_type='Mapped Value')
predicate.immediateReindexObject() predicate = module['predicate']
predicate.setCriterion('quantity', identity=None, min=None, max=None)
self.predicate = predicate self.predicate = predicate
get_transaction().commit(1) # If we don't commit, then we can't rename get_transaction().commit() # If we don't commit, then we can't rename
self.tic()
def beforeTearDown(self):
portal_categories = self.getCategoryTool()
if portal_categories[self.base_cat].has_key('3'):
portal_categories[self.base_cat].manage_delObjects('3')
self.commitAndTic()
portal = self.getPortal()
if 'new_id' in portal.objectIds():
portal['new_id'].edit(id='organisation_module')
self.commitAndTic()
organisation_module = self.getOrganisationModule()
if organisation_module.has_key('new_id'):
organisation_module.manage_delObjects('new_id')
self.commitAndTic()
def login(self, quiet=0): def login(self, quiet=0):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
...@@ -132,42 +168,54 @@ class TestERP5Category(ERP5TypeTestCase): ...@@ -132,42 +168,54 @@ class TestERP5Category(ERP5TypeTestCase):
user = uf.getUserById('seb').__of__(uf) user = uf.getUserById('seb').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
def test_01(self, quiet=0, run=run_all_test): def commitAndTic(self):
"""Just to save one line.
"""
get_transaction().commit()
self.tic()
def test_01_RenameCategory(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename Category') self.logMessage('Rename Category')
organisation = self.organisation organisation = self.organisation
organisation.setCategoryList(self.cat_list) organisation.setCategoryList(self.cat_list)
self.commitAndTic()
self.failIfDifferentSet(organisation.getCategoryList(),self.cat_list) self.failIfDifferentSet(organisation.getCategoryList(),self.cat_list)
portal_categories = self.getCategoryTool() portal_categories = self.getCategoryTool()
portal_categories[self.base_cat]['1'].edit(id='3') portal_categories[self.base_cat]['1'].edit(id='3')
self.commitAndTic()
self.failIfDifferentSet(organisation.getCategoryList(),self.new_cat_list) self.failIfDifferentSet(organisation.getCategoryList(),self.new_cat_list)
def test_02(self, quiet=0, run=run_all_test): def test_02_RenameCategoryTree(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename Category Tree') self.logMessage('Rename Category Tree')
organisation = self.organisation organisation = self.organisation
organisation.setCategoryList(self.deep_cat_list) organisation.setCategoryList(self.deep_cat_list)
self.commitAndTic()
self.failIfDifferentSet(organisation.getCategoryList(),self.deep_cat_list) self.failIfDifferentSet(organisation.getCategoryList(),self.deep_cat_list)
portal_categories = self.getCategoryTool() portal_categories = self.getCategoryTool()
portal_categories[self.base_cat]['1'].edit(id='3') portal_categories[self.base_cat]['1'].edit(id='3')
self.commitAndTic()
self.failIfDifferentSet(organisation.getCategoryList(),self.new_deep_cat_list) self.failIfDifferentSet(organisation.getCategoryList(),self.new_deep_cat_list)
def test_03(self, quiet=0, run=run_all_test): def test_03_RenameRelatedObject(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename Related Object') self.logMessage('Rename Related Object')
organisation = self.organisation organisation = self.organisation
organisation2 = self.organisation2 organisation2 = self.organisation2
organisation.setAbcValueList([organisation2]) organisation.setAbcValueList([organisation2])
self.commitAndTic()
self.assertEquals(organisation.getAbcValueList(),[organisation2]) self.assertEquals(organisation.getAbcValueList(),[organisation2])
self.assertEquals(organisation.getAbcIdList(),['2']) self.assertEquals(organisation.getAbcIdList(),['2'])
organisation2.edit(id='new_id') organisation2.edit(id='new_id')
self.commitAndTic()
self.assertEquals(organisation.getAbcValueList(),[organisation2]) self.assertEquals(organisation.getAbcValueList(),[organisation2])
self.assertEquals(organisation.getAbcIdList(),['new_id']) self.assertEquals(organisation.getAbcIdList(),['new_id'])
def test_04(self, quiet=0, run=run_all_test): def test_04_RenameObjectWithRelatedSubObject(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename Object With a related Sub Object') self.logMessage('Rename Object With a related Sub Object')
...@@ -175,25 +223,29 @@ class TestERP5Category(ERP5TypeTestCase): ...@@ -175,25 +223,29 @@ class TestERP5Category(ERP5TypeTestCase):
organisation = self.organisation organisation = self.organisation
organisation2 = self.organisation2 organisation2 = self.organisation2
organisation.setAbcValueList([telephone2]) organisation.setAbcValueList([telephone2])
self.commitAndTic()
self.assertEquals(organisation.getAbcValueList(),[telephone2]) self.assertEquals(organisation.getAbcValueList(),[telephone2])
self.assertEquals(organisation.getAbcList(),[telephone2.getRelativeUrl()]) self.assertEquals(organisation.getAbcList(),[telephone2.getRelativeUrl()])
organisation2.edit(id='new_id') organisation2.edit(id='new_id')
self.commitAndTic()
self.assertEquals(organisation.getAbcValueList(),[telephone2]) self.assertEquals(organisation.getAbcValueList(),[telephone2])
self.assertEquals(organisation.getAbcList(),[telephone2.getRelativeUrl()]) self.assertEquals(organisation.getAbcList(),[telephone2.getRelativeUrl()])
def test_05(self, quiet=0, run=run_all_test): def test_05_RenameMembershipCriterionCategory(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename Membership Criterion Category') self.logMessage('Rename Membership Criterion Category')
predicate = self.predicate predicate = self.predicate
predicate.setMembershipCriterionBaseCategoryList(self.base_cat) predicate.setMembershipCriterionBaseCategoryList(self.base_cat)
predicate.setMembershipCriterionCategoryList(self.cat_list) predicate.setMembershipCriterionCategoryList(self.cat_list)
self.commitAndTic()
self.failIfDifferentSet(predicate.getMembershipCriterionCategoryList(),self.cat_list) self.failIfDifferentSet(predicate.getMembershipCriterionCategoryList(),self.cat_list)
portal_categories = self.getCategoryTool() portal_categories = self.getCategoryTool()
portal_categories[self.base_cat]['1'].edit(id='3') portal_categories[self.base_cat]['1'].edit(id='3')
self.commitAndTic()
self.failIfDifferentSet(predicate.getMembershipCriterionCategoryList(),self.new_cat_list) self.failIfDifferentSet(predicate.getMembershipCriterionCategoryList(),self.new_cat_list)
def test_06(self, quiet=0, run=run_all_test): def test_06_RenameModuleWithObjectOuterRelated(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename Module With an Object Related to an Object it Contains') self.logMessage('Rename Module With an Object Related to an Object it Contains')
...@@ -201,39 +253,44 @@ class TestERP5Category(ERP5TypeTestCase): ...@@ -201,39 +253,44 @@ class TestERP5Category(ERP5TypeTestCase):
organisation = self.organisation organisation = self.organisation
person = self.person person = self.person
person.setSubordinationValue(organisation) person.setSubordinationValue(organisation)
self.commitAndTic()
self.assertEquals(person.getSubordinationValue(),organisation) self.assertEquals(person.getSubordinationValue(),organisation)
organisation_module.edit(id='new_id') organisation_module.edit(id='new_id')
self.commitAndTic()
self.assertEquals(person.getSubordinationValue(),organisation) self.assertEquals(person.getSubordinationValue(),organisation)
def test_07(self, quiet=0, run=run_all_test): def test_07_RenameBaseCategoryWithPersonRelatedToSubSubSubCategory(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename a Base Category with a Person Related to a Sub-Sub-Sub-Category') self.logMessage('Rename a Base Category with a Person Related to a Sub-Sub-Sub-Category')
o = self.organisation o = self.organisation
o.setEfgValueList([self.efg_l4]) o.setEfgValueList([self.efg_l4])
self.commitAndTic()
self.failIfDifferentSet(o.getEfgList(base=1),[self.base_cat2+'/1/11/111/1111']) self.failIfDifferentSet(o.getEfgList(base=1),[self.base_cat2+'/1/11/111/1111'])
self.efg_l1.edit(id='new_id') self.efg_l1.edit(id='new_id')
self.commitAndTic()
self.failIfDifferentSet(o.getEfgList(base=1),[self.base_cat2+'/new_id/11/111/1111']) self.failIfDifferentSet(o.getEfgList(base=1),[self.base_cat2+'/new_id/11/111/1111'])
def test_08(self, quiet=0, run=run_all_test): def test_08_RenameModuleWithObjectsInnerRelated(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Rename a Module with Contained Objects Refering to Other Objects inside the Same Module') self.logMessage('Rename a Module with Contained Objects Refering to Other Objects inside the Same Module')
om = self.getOrganisationModule() om = self.getOrganisationModule()
om['1'].setAbcValue(om['2']) om['1'].setAbcValue(om['2'])
om['1'].immediateReindexObject() self.commitAndTic()
self.assertEquals(len(om['2'].getRelatedValueList('abc')), 1) self.assertEquals(len(om['2'].getRelatedValueList('abc')), 1)
self.assertEquals(len(om['2'].Base_zSearchRelatedObjectsByCategory(category_uid = om['2'].getUid())),1) self.assertEquals(len(om['2'].Base_zSearchRelatedObjectsByCategory(category_uid = om['2'].getUid())),1)
self.assertEquals(om['1'].getAbc(),om['2'].getRelativeUrl()) self.assertEquals(om['1'].getAbc(),om['2'].getRelativeUrl())
original_uid = om['2'].getUid() original_uid = om['2'].getUid()
om.edit(id='new_id') om.edit(id='new_id')
self.commitAndTic()
om = self.getPortal()['new_id'] om = self.getPortal()['new_id']
self.assertEquals(original_uid, om['2'].getUid()) self.assertEquals(original_uid, om['2'].getUid())
self.assertEquals(len(om['2'].getRelatedValueList('abc')), 1) self.assertEquals(len(om['2'].getRelatedValueList('abc')), 1)
self.assertEquals(len(om['2'].Base_zSearchRelatedObjectsByCategory(category_uid = om['2'].getUid())),1) self.assertEquals(len(om['2'].Base_zSearchRelatedObjectsByCategory(category_uid = om['2'].getUid())),1)
self.assertEquals(om['1'].getAbc(),om['2'].getRelativeUrl()) self.assertEquals(om['1'].getAbc(),om['2'].getRelativeUrl())
def test_08(self, quiet=0, run=run_all_test): def test_09_Base_viewDictWithCategoryWithSubCategory(self, quiet=0, run=run_all_test):
if not run: return if not run: return
if not quiet: if not quiet:
self.logMessage('Make sure Base_viewDict is working for categories with sub categories') self.logMessage('Make sure Base_viewDict is working for categories with sub categories')
......
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