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

tests Folder_delete:

 when everything is OK
 when a document you want to delete has related documents
 when a document you want to delete has related documents you cannot access
 (the later is currently failing in Unauthorized)



git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@23742 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 11d8a4e6
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
import unittest import unittest
import md5
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase from Testing import ZopeTestCase
...@@ -65,6 +66,14 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -65,6 +66,14 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
self.portal_id = self.portal.getId() self.portal_id = self.portal.getId()
self.auth = '%s:%s' % (self.manager_username, self.manager_password) self.auth = '%s:%s' % (self.manager_username, self.manager_password)
def beforeTearDown(self):
get_transaction().abort()
if 'test_folder' in self.portal.objectIds():
self.portal.manage_delObjects(['test_folder'])
self.portal.portal_selections.setSelectionFor('test_selection', None)
get_transaction().commit()
self.tic()
def test_01_ERP5Site_createModule(self, quiet=quiet, run=run_all_test): def test_01_ERP5Site_createModule(self, quiet=quiet, run=run_all_test):
""" """
Test that a module is created when ERP5Site_createModule is given the Test that a module is created when ERP5Site_createModule is given the
...@@ -290,6 +299,77 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional): ...@@ -290,6 +299,77 @@ class TestERP5Core(ERP5TypeTestCase, ZopeTestCase.Functional):
response = self.publish('%s/view' % self.portal_id, self.auth) response = self.publish('%s/view' % self.portal_id, self.auth)
self.assertEquals(HTTP_OK, response.getStatus()) self.assertEquals(HTTP_OK, response.getStatus())
def test_Folder_delete(self):
module = self.portal.newContent(portal_type='Folder', id='test_folder')
document_1 = module.newContent(portal_type='Folder', id='1')
document_2 = module.newContent(portal_type='Folder', id='2')
uid_list = [document_1.getUid(), document_2.getUid()]
self.portal.portal_selections.setSelectionParamsFor(
'test_selection', dict(uids=uid_list))
get_transaction().commit()
self.tic()
md5_string = md5.new(str(sorted([str(x) for x in uid_list]))).hexdigest()
redirect = module.Folder_delete(selection_name='test_selection',
uids=uid_list,
md5_object_uid_list=md5_string)
self.assert_('Deleted.' in redirect, redirect)
get_transaction().commit(1)
self.assertEquals(len(module.objectValues()), 0)
def test_Folder_delete_related_object(self):
# deletion is refused if there are related objects
module = self.portal.newContent(portal_type='Folder', id='test_folder')
document_1 = module.newContent(portal_type='Folder', id='1')
document_2 = module.newContent(portal_type='Folder', id='2')
self.portal.portal_categories.setCategoryMembership(
context=document_1,
base_category_list=('source',),
category_list=document_2.getRelativeUrl())
uid_list = [document_1.getUid(), document_2.getUid()]
self.portal.portal_selections.setSelectionParamsFor(
'test_selection', dict(uids=uid_list))
get_transaction().commit()
self.tic()
self.assertEquals([document_1],
self.portal.portal_categories.getRelatedValueList(document_2))
md5_string = md5.new(str(sorted([str(x) for x in uid_list]))).hexdigest()
redirect = module.Folder_delete(selection_name='test_selection',
uids=uid_list,
md5_object_uid_list=md5_string)
self.assert_('Sorry, 1 item is in use.' in redirect, redirect)
get_transaction().commit(1)
self.assertEquals(len(module.objectValues()), 2)
def test_Folder_delete_non_accessible_object(self):
# deletion is refused if there are related objects, even if those related
# objects cannot be accessed
module = self.portal.newContent(portal_type='Folder', id='test_folder')
document_1 = module.newContent(portal_type='Folder', id='1')
document_2 = module.newContent(portal_type='Folder', id='2')
self.portal.portal_categories.setCategoryMembership(
context=document_1,
base_category_list=('source',),
category_list=document_2.getRelativeUrl())
uid_list = [document_2.getUid(), ]
self.portal.portal_selections.setSelectionParamsFor(
'test_selection', dict(uids=uid_list))
get_transaction().commit()
self.tic()
self.assertEquals([document_1],
self.portal.portal_categories.getRelatedValueList(document_2))
md5_string = md5.new(str(sorted([str(x) for x in uid_list]))).hexdigest()
document_1.manage_permission('View', [], acquire=0)
document_1.manage_permission('Access contents information', [], acquire=0)
redirect = module.Folder_delete(selection_name='test_selection',
uids=uid_list,
md5_object_uid_list=md5_string)
self.assert_('Sorry, 1 item is in use.' in redirect, redirect)
get_transaction().commit(1)
self.assertEquals(len(module.objectValues()), 2)
def test_suite(): def test_suite():
suite = unittest.TestSuite() suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestERP5Core)) suite.addTest(unittest.makeSuite(TestERP5Core))
......
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