Back to index

plone3  3.1.7
test_CopyModifyMergeRepositoryTool.py
Go to the documentation of this file.
00001 #########################################################################
00002 # Copyright (c) 2004, 2005 Alberto Berti, Gregoire Weber.
00003 # Reflab (Vincenzo Di Somma, Francesco Ciriaci, Riccardo Lemmi)
00004 # All Rights Reserved.
00005 #
00006 # This file is part of CMFEditions.
00007 #
00008 # CMFEditions is free software; you can redistribute it and/or modify
00009 # it under the terms of the GNU General Public License as published by
00010 # the Free Software Foundation; either version 2 of the License, or
00011 # (at your option) any later version.
00012 #
00013 # CMFEditions is distributed in the hope that it will be useful,
00014 # but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 # GNU General Public License for more details.
00017 #
00018 # You should have received a copy of the GNU General Public License
00019 # along with CMFEditions; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00021 #########################################################################
00022 """Test the standard archivist
00023 
00024 $Id: test_CopyModifyMergeRepositoryTool.py,v 1.17 2005/06/22 10:43:46 gregweb Exp $
00025 """
00026 
00027 from Products.PloneTestCase import PloneTestCase
00028 PloneTestCase.setupPloneSite()
00029 
00030 import transaction
00031 from Interface.Verify import verifyObject
00032 from Products.CMFCore.utils import getToolByName
00033 
00034 from Products.CMFEditions.interfaces.IRepository import ICopyModifyMergeRepository
00035 from Products.CMFEditions.interfaces.IRepository import IPurgeSupport
00036 from Products.CMFEditions.interfaces.IRepository import RepositoryPurgeError
00037 from Products.CMFEditions.interfaces.IRepository import IContentTypeVersionPolicySupport
00038 from Products.CMFEditions.interfaces.IRepository import IVersionData
00039 from Products.CMFEditions.VersionPolicies import VersionPolicy
00040 from Products.CMFEditions.VersionPolicies import ATVersionOnEditPolicy
00041 
00042 from DummyTools import DummyArchivist
00043 from DummyTools import notifyModified
00044 
00045 class dummyPolicyWithHooks(VersionPolicy):
00046     """A dummy policy to test the hooks"""
00047     def setupPolicyHook(self, portal, out):
00048         out.append('added')
00049 
00050     def removePolicyHook(self, portal, out):
00051         out.append('removed')
00052 
00053     def enablePolicyOnTypeHook(self, portal, p_type, out):
00054         out.append('enabled %s'%p_type)
00055 
00056     def disablePolicyOnTypeHook(self, portal, p_type, out):
00057         out.append('disabled %s'%p_type)
00058 
00059 class TestCopyModifyMergeRepositoryToolBase(PloneTestCase.PloneTestCase):
00060 
00061     def afterSetUp(self):
00062         # we need to have the Manager role to be able to add things
00063         # to the portal root
00064         self.setRoles(['Manager',])
00065 
00066         # add an additional user
00067         self.portal.acl_users.userFolderAddUser('reviewer', 'reviewer',
00068                                                 ['Manager'], '')
00069 
00070         # add test data
00071         self.portal.invokeFactory('Document', 'doc')
00072         self.portal.invokeFactory('Link', 'link')
00073         self.portal.invokeFactory('Folder', 'fol')
00074         self.portal.fol.invokeFactory('Document', 'doc1_inside')
00075         self.portal.fol.invokeFactory('Document', 'doc2_inside')
00076         self.portal.fol.invokeFactory('Document', 'doc3_outside')
00077 
00078         self._setupArchivist()
00079 
00080     def _setupArchivist(self):
00081         # override this to install a different than the "official" tools
00082         pass
00083 
00084 class TestCopyModifyMergeRepositoryTool(TestCopyModifyMergeRepositoryToolBase):
00085 
00086     def test00_interface(self):
00087         portal_repository = self.portal.portal_repository
00088         portal_archivist = self.portal.portal_archivist
00089         doc = self.portal.doc
00090 
00091         # test the tools interface conformance
00092         verifyObject(ICopyModifyMergeRepository, portal_repository)
00093         verifyObject(IPurgeSupport, portal_repository)
00094 
00095         # test the version data interface conformance
00096         doc.text = 'text v1'
00097         portal_repository.applyVersionControl(doc, comment='save no 1')
00098 
00099         vdata = portal_repository.retrieve(doc)
00100         verifyObject(IVersionData, vdata)
00101 
00102     def test01_saveVersionableAspects(self):
00103         portal_repository = self.portal.portal_repository
00104         portal_archivist = self.portal.portal_archivist
00105         doc = self.portal.doc
00106 
00107         doc.text = 'text v1'
00108         portal_repository.applyVersionControl(doc, comment='save no 1')
00109         doc.text = 'text v2'
00110 
00111         portal_repository.save(doc, comment='save no 2')
00112 
00113         vdata = portal_archivist.retrieve(obj=doc, selector=0)
00114 
00115         self.assertEqual(vdata.data.object.text, 'text v1')
00116         vdata = portal_archivist.retrieve(obj=doc, selector=1)
00117         self.assertEqual(vdata.data.object.text, 'text v2')
00118 
00119     def test02_retrieve(self):
00120         portal_repository = self.portal.portal_repository
00121         portal_archivist = self.portal.portal_archivist
00122         doc = self.portal.doc
00123 
00124         doc.text = 'text v1'
00125         portal_repository.applyVersionControl(doc, comment='save no 1')
00126         doc.text = 'text v2'
00127         portal_repository.save(doc, comment='save no 2')
00128 
00129         vdata = portal_repository.retrieve(doc, selector=0)
00130         self.failUnless(verifyObject(IVersionData, vdata))
00131         self.assertEqual(vdata.object.text, 'text v1')
00132         vdata = portal_repository.retrieve(doc, selector=1)
00133         self.assertEqual(vdata.object.text, 'text v2')
00134 
00135     def test03_recursiveRevertOfFolderWithOutsideObject(self):
00136         portal_repository = self.portal.portal_repository
00137         portal_archivist = self.portal.portal_archivist
00138         fol = self.portal.fol
00139         doc3_outside = fol.doc3_outside
00140 
00141         fol.title = 'fol title v1'
00142         doc3_outside.title = 'doc3_outside title text v1'
00143         portal_repository.applyVersionControl(fol, comment='save no 1')
00144 
00145         fol.title = 'fol title v2'
00146         doc3_outside.title = 'doc3_outside title text v2'
00147         portal_repository.save(fol, comment='save no 2')
00148 
00149         portal_repository.revert(fol, 0)
00150 
00151         # check result
00152         self.assertEqual(self.portal.fol, fol)
00153         self.assertEqual(self.portal.fol.doc3_outside, doc3_outside)
00154 
00155         self.assertEqual(fol.title, 'fol title v1')
00156         self.assertEqual(doc3_outside.title,
00157                         'doc3_outside title text v2')
00158 
00159     def test04_isUptoDate(self):
00160         portal_repository = self.portal.portal_repository
00161         portal_archivist = self.portal.portal_archivist
00162         doc = self.portal.doc
00163 
00164         doc.text = 'text v1'
00165         portal_repository.applyVersionControl(doc, comment='save no 1')
00166         self.assertEqual(portal_repository.isUpToDate(doc), True)
00167         doc.text = 'text v2'
00168         notifyModified(doc)
00169         self.failIf(portal_repository.isUpToDate(doc))
00170 
00171     def test05_getHistory(self):
00172         portal_repository = self.portal.portal_repository
00173         portal_archivist = self.portal.portal_archivist
00174         doc = self.portal.doc
00175 
00176         doc.text = 'text v1'
00177         portal_repository.applyVersionControl(doc, comment='save no 1')
00178         hist = portal_repository.getHistory(doc)
00179         self.assertEqual(hist._obj.text, 'text v1')
00180         self.assertEqual(len(hist), 1)
00181 
00182         doc.text = 'text v2'
00183         portal_repository.save(doc, comment='save no 2')
00184         hist = portal_repository.getHistory(doc)
00185         self.assertEqual(hist._obj.text, 'text v2')
00186         self.assertEqual(len(hist), 2)
00187 
00188     def test06_retrieveWithNoMoreExistentObject(self):
00189         portal_repository = self.portal.portal_repository
00190         portal_archivist = self.portal.portal_archivist
00191         portal_hidhandler = self.portal.portal_historyidhandler
00192         doc = self.portal.doc
00193 
00194         doc.text = 'text v1'
00195         portal_repository.applyVersionControl(doc, comment='save no 1')
00196         doc.text = 'text v2'
00197         portal_repository.save(doc, comment='save no 2')
00198 
00199         # save the ``history_id`` to be able to retrieve the object after
00200         # it's deletion
00201         history_id = portal_hidhandler.queryUid(doc)
00202 
00203         # delete the object we want to retrieve later
00204         doc_type = doc.getPortalTypeName()
00205         self.portal.manage_delObjects(ids=['doc'])
00206         self.portal.invokeFactory(doc_type, 'doc_tmp')
00207         doc = self.portal.doc_tmp
00208         portal_hidhandler.setUid(doc, history_id, check_uniqueness=True)
00209         vdata = portal_repository.retrieve(doc, selector=0)
00210         self.failUnless(verifyObject(IVersionData, vdata))
00211         self.assertEqual(vdata.object.text, 'text v1')
00212         vdata = portal_repository.retrieve(doc, selector=1)
00213         self.assertEqual(vdata.object.text, 'text v2')
00214 
00215     def test07_restoreDeletedObject(self):
00216         portal_repository = self.portal.portal_repository
00217         portal_hidhandler = self.portal.portal_historyidhandler
00218         doc = self.portal.doc
00219 
00220         doc.text = 'text v1'
00221         portal_repository.applyVersionControl(doc, comment='save no 1')
00222 
00223         # save the ``history_id`` to be able to retrieve the object after
00224         # it's deletion
00225         history_id = portal_hidhandler.queryUid(doc)
00226 
00227         # delete the object we want to retrieve later
00228         self.portal.manage_delObjects(ids=['doc'])
00229         self.failIf('doc' in self.portal.objectIds())
00230         vdata = portal_repository.restore(history_id, selector=0, container=self.portal)
00231         self.failUnless('doc' in self.portal.objectIds())
00232         restored = self.portal.doc
00233         self.assertEqual(restored.text, 'text v1')
00234 
00235     def test07_restoreDeletedObjectWithNewId(self):
00236         portal_repository = self.portal.portal_repository
00237         portal_hidhandler = self.portal.portal_historyidhandler
00238         doc = self.portal.doc
00239 
00240         doc.text = 'text v1'
00241         portal_repository.applyVersionControl(doc, comment='save no 1')
00242 
00243         # save the ``history_id`` to be able to retrieve the object after
00244         # it's deletion
00245         history_id = portal_hidhandler.queryUid(doc)
00246 
00247         # delete the object we want to retrieve later
00248         self.portal.manage_delObjects(ids=['doc'])
00249         self.failIf('doc' in self.portal.objectIds())
00250         vdata = portal_repository.restore(history_id, selector=0,
00251                                          container=self.portal, new_id='doc2')
00252         self.failUnless('doc2' in self.portal.objectIds())
00253         restored = self.portal.doc2
00254         self.assertEqual(restored.text, 'text v1')
00255 
00256     def test08_purgingDisallowedWithoutPurgingPolicy(self):
00257         portal_repository = self.portal.portal_repository
00258         doc = self.portal.doc
00259         
00260         # remove purge policy for this test
00261         portal_purgepolicy = self.portal.portal_purgepolicy
00262         del self.portal.portal_purgepolicy
00263 
00264         doc.text = 'text v1'
00265         portal_repository.applyVersionControl(doc, comment='save no 1')
00266 
00267         self.assertRaises(RepositoryPurgeError,
00268                           portal_repository.purge, doc, selector=0)
00269 
00270         self.portal.portal_purgepolicy = portal_purgepolicy
00271 
00272 
00273 class TestRepositoryWithDummyArchivist(TestCopyModifyMergeRepositoryToolBase):
00274 
00275     def _setupArchivist(self):
00276         # replace the "original" tools by dummy tools
00277         tools = (
00278             DummyArchivist(),
00279         )
00280         for tool in tools:
00281             setattr(self.portal, tool.getId(), tool)
00282 
00283     def test01_recursiveSave(self):
00284         portal_repository = self.portal.portal_repository
00285         portal_repository.autoapply = False
00286         portal_archivist = self.portal.portal_archivist
00287         fol = self.portal.fol
00288 
00289         portal_archivist.reset_log()
00290         portal_repository.applyVersionControl(fol, comment='save no 1')
00291         portal_repository.save(fol, comment='save no 2')
00292 
00293         # check if correctly recursing and setting reference data correctly
00294         alog_str = portal_archivist.get_log()
00295         expected = """
00296 prepare fol: hid=1, refs=(doc1_inside, doc2_inside, doc3_outside)
00297   prepare doc1_inside: hid=3
00298   save    doc1_inside: hid=3, isreg=False, auto=True
00299   prepare doc2_inside: hid=4
00300   save    doc2_inside: hid=4, isreg=False, auto=True
00301 save    fol: hid=1, irefs=({hid:3, vid:0}, {hid:4, vid:0}), orefs=({hid:None, vid:-1}), isreg=False, auto=True
00302 
00303 prepare fol: hid=1, refs=(doc1_inside, doc2_inside, doc3_outside)
00304   prepare doc1_inside: hid=3
00305   save    doc1_inside: hid=3, isreg=True, auto=False
00306   prepare doc2_inside: hid=4
00307   save    doc2_inside: hid=4, isreg=True, auto=False
00308 save    fol: hid=1, irefs=({hid:3, vid:1}, {hid:4, vid:1}), orefs=({hid:None, vid:-1}), isreg=True, auto=False"""
00309 
00310         self.assertEqual(alog_str, expected)
00311 
00312     def test02_recursiveRetrieve(self):
00313         portal_repository = self.portal.portal_repository
00314         portal_archivist = self.portal.portal_archivist
00315         fol = self.portal.fol
00316 
00317         fol.title = 'fol title v1'
00318         fol.doc1_inside.title = 'doc1_inside title text v1'
00319         fol.doc2_inside.title = 'doc2_inside title text v1'
00320         fol.doc3_outside.title = 'doc3_outside title text v1'
00321         portal_repository.applyVersionControl(fol, comment='save no 1')
00322 
00323         fol.title = 'fol title v2'
00324         fol.doc1_inside.title = 'doc1_inside title text v2'
00325         fol.doc2_inside.title = 'doc2_inside title text v2'
00326         fol.doc3_outside.title = 'doc3_outside title text v2'
00327         portal_repository.save(fol, comment='save no 2')
00328 
00329         portal_archivist.reset_log()
00330 
00331         retr = portal_repository.retrieve(fol, selector=0)
00332 
00333         # check recursive retrieve
00334         alog_str = portal_archivist.get_log()
00335 
00336         expected = """retrieve fol: hid=1, selector=0
00337 retrieve doc1_inside: hid=3, selector=0
00338 retrieve doc2_inside: hid=4, selector=0"""
00339         self.assertEqual(alog_str, expected)
00340 
00341         # check result
00342         self.assertEqual(retr.object.title, 'fol title v1')
00343         self.assertEqual(retr.object.doc1_inside.title,
00344                         'doc1_inside title text v1')
00345         self.assertEqual(retr.object.doc2_inside.title,
00346                         'doc2_inside title text v1')
00347         self.assertEqual(retr.object.doc3_outside.title,
00348                         'doc3_outside title text v2')
00349 
00350 
00351 class TestRegressionTests(PloneTestCase.PloneTestCase):
00352 
00353     def afterSetUp(self):
00354         # we need to have the Manager role to be able to add things
00355         # to the portal root
00356         self.setRoles(['Manager',])
00357         self.portal.acl_users.userFolderAddUser('reviewer', 'reviewer',
00358                                                 ['Manager'], '')
00359 
00360         self.portal.invokeFactory('Document', 'doc')
00361         self.portal.invokeFactory('Folder', 'fol')
00362 
00363         # add the Editions Tool (this way we test the 'Install' script!)
00364         self._setupArchivist()
00365 
00366     def _setupArchivist(self):
00367         # override this to install a different than the "official" tools
00368         pass
00369 
00370     def test_idModification(self):
00371         portal_repository = self.portal.portal_repository
00372         portal_archivist = self.portal.portal_archivist
00373         doc = self.portal.doc
00374         doc.text = 'text v1'
00375         portal_repository.applyVersionControl(doc, comment='save no 1')
00376         doc.text = 'text v2'
00377         transaction.savepoint(optimistic=True)
00378         self.portal.manage_renameObject(doc.getId(), 'newdoc',)
00379         portal_repository.save(doc, comment='save no 2')
00380         portal_repository.revert(doc, 0)
00381         self.assertEqual(doc.getId(), 'newdoc')
00382         self.failUnless('newdoc' in self.portal.objectIds())
00383 
00384 class TestPolicyVersioning(TestCopyModifyMergeRepositoryToolBase):
00385 
00386     def afterSetUp(self):
00387         # define number of default policies
00388         TestCopyModifyMergeRepositoryToolBase.afterSetUp(self)
00389         self.np = len(self.portal.portal_repository.listPolicies())
00390 
00391     def isFCActionInPlace(self, object_id, status, button, context):
00392         fc = getToolByName(self.portal, 'portal_form_controller')
00393         for action in fc.listFormActions(1):
00394             if (object_id == action.getObjectId() and
00395                 status == action.getStatus() and
00396                 button == action.getButton() and
00397                 context == action.getContextType()):
00398                 return True
00399         return False
00400 
00401     def test00_interface(self):
00402         portal_repository = self.portal.portal_repository
00403         # test the tools interface conformance
00404         verifyObject(IContentTypeVersionPolicySupport, portal_repository)
00405 
00406     def test01_remove_policy_from_type(self):
00407         # test that policies can be removed
00408         portal_repository = self.portal.portal_repository
00409         # Set it twice to ensure that duplicates aren't created
00410         self.failUnless(portal_repository.supportsPolicy(self.portal.doc,
00411                                                         'at_edit_autoversion'))
00412         portal_repository.removePolicyFromContentType('Document',
00413                                                         'at_edit_autoversion')
00414         self.failIf(portal_repository.supportsPolicy(self.portal.doc,
00415                                                         'at_edit_autoversion'))
00416 
00417     def test02_set_policy_on_type(self):
00418         # test that policies can be set and retrieved
00419         portal_repository = self.portal.portal_repository
00420         self.failUnless(portal_repository.supportsPolicy(self.portal.doc,
00421                                                         'at_edit_autoversion'))
00422         portal_repository.removePolicyFromContentType('Document',
00423                                                         'at_edit_autoversion')
00424         self.failIf(portal_repository.supportsPolicy(self.portal.doc,
00425                                                         'at_edit_autoversion'))
00426         portal_repository.addPolicyForContentType('Document',
00427                                                         'at_edit_autoversion')
00428         self.failUnless(portal_repository.supportsPolicy(self.portal.doc,
00429                                                         'at_edit_autoversion'))
00430 
00431     def test03_set_policy_types_map(self):
00432         # test the mapping of policies to types
00433         portal_repository = self.portal.portal_repository
00434         # Get something in place first
00435         portal_repository.addPolicyForContentType('Document',
00436                                                         'at_edit_autoversion')
00437         portal_repository.removePolicyFromContentType('Document',
00438                                                         'at_edit_autoversion')
00439         # update the mapping
00440         portal_repository.manage_setTypePolicies({'Document':
00441                                                      ['at_edit_autoversion']})
00442         self.failUnless(portal_repository.supportsPolicy(self.portal.doc,
00443                                                        'at_edit_autoversion'))
00444 
00445     def test04_add_policy(self):
00446         # test adding a new policy
00447         portal_repository = self.portal.portal_repository
00448         self.assertEqual(len(portal_repository.listPolicies()), self.np)
00449         portal_repository.addPolicy('version_on_publish',
00450                                             'Create version when published')
00451         policies = portal_repository.listPolicies()
00452         self.assertEqual(len(policies), self.np+1)
00453         self.failUnless('version_on_publish' in [p.getId() for p in policies])
00454 
00455     def test04_add_policy_updates(self):
00456         # test calling addPolicy with an existing Id updates the title
00457         portal_repository = self.portal.portal_repository
00458         self.assertEqual(len(portal_repository.listPolicies()), self.np)
00459         portal_repository.addPolicy('at_edit_autoversion',
00460                                             'Fake policy title')
00461         policies = portal_repository.listPolicies()
00462         self.assertEqual(len(policies), self.np)
00463         self.failUnless('Fake policy title' in [p.Title() for p in policies])
00464 
00465     def test05_remove_policy(self):
00466         # test removing a policy removes the policy from all content types
00467         portal_repository = self.portal.portal_repository
00468         portal_repository.addPolicy('version_on_publish',
00469                                             'Create version when published')
00470         portal_repository.addPolicyForContentType('Document',
00471                                                         'version_on_publish')
00472         portal_repository.removePolicy('version_on_publish')
00473         self.assertEqual(len(portal_repository.listPolicies()), self.np)
00474         self.failIf(portal_repository.supportsPolicy(self.portal.doc,
00475                                                         'version_on_publish'))
00476 
00477     def test07_set_policy_defs(self):
00478         # test update policy definition list
00479         portal_repository = self.portal.portal_repository
00480         portal_repository.removePolicy('at_edit_autoversion')
00481         self.assertEqual(len(portal_repository.listPolicies()), self.np-1)
00482         portal_repository.manage_changePolicyDefs((('at_edit_autoversion',
00483                                             'Fake policy title'),))
00484         policies = portal_repository.listPolicies()
00485         self.assertEqual(len(policies), 1)
00486         self.failUnless('Fake policy title' in [p.Title() for p in policies])
00487 
00488     def test08_mutators_fail_on_invalid_input(self):
00489         portal_repository = self.portal.portal_repository
00490         # manage_changePolicyDefs requires a sequence of two-tuples with
00491         # strings
00492         self.assertRaises(AssertionError,
00493                             portal_repository.manage_changePolicyDefs,
00494                             {'at_edit_autoversion':'Fake policy title'})
00495         self.assertRaises(AssertionError,
00496                             portal_repository.manage_changePolicyDefs,
00497                             ('at_edit_autoversion','policy2'))
00498         self.assertRaises(AssertionError,
00499                             portal_repository.manage_changePolicyDefs,
00500                             [(1,'My new policy')])
00501         self.assertRaises(TypeError,
00502                             portal_repository.manage_changePolicyDefs,
00503                 [('at_edit_autoversion','My new policy', 'some_extra_stuff')])
00504         self.assertRaises(AssertionError,
00505                             portal_repository.manage_changePolicyDefs,
00506         [('at_edit_autoversion','My new policy', dummyPolicyWithHooks,'str')])
00507         # manage_setTypePolicies requires a mapping of of portal_types to a
00508         # list of valid policies
00509         self.assertRaises(AssertionError,
00510                             portal_repository.manage_setTypePolicies,
00511                             {'my_type':'at_edit_autoversion'})
00512         self.assertRaises(AssertionError,
00513                             portal_repository.manage_setTypePolicies,
00514                             {'my_type':['a_bogus_policy']})
00515         self.assertRaises(AssertionError,
00516                             portal_repository.manage_setTypePolicies,
00517                             (('my_type',['a_bogus_policy']),))
00518         # addPolicyForContentType fails unless the policy is valid
00519         self.assertRaises(AssertionError,
00520                             portal_repository.addPolicyForContentType,
00521                             'my_type','my_bogus_policy')
00522 
00523     def test09_policy_hooks(self):
00524         portal_repository = self.portal.portal_repository
00525         out = []
00526         # Test hooks on basic actions
00527         portal_repository.addPolicy('my_bogus_policy',
00528                                   'Hook Tests', dummyPolicyWithHooks, out=out)
00529         self.assertEqual(out, ['added'])
00530         self.assertEqual(len(portal_repository.listPolicies()), self.np+1)
00531         portal_repository.addPolicyForContentType('Document',
00532                                                    'my_bogus_policy', out=out)
00533         self.failUnless(portal_repository.supportsPolicy(self.portal.doc,
00534                                                         'my_bogus_policy'))
00535         self.assertEqual(out, ['added','enabled Document'])
00536         portal_repository.removePolicyFromContentType('Document',
00537                                                    'my_bogus_policy', out=out)
00538         self.failIf(portal_repository.supportsPolicy(self.portal.doc,
00539                                                         'my_bogus_policy'))
00540         self.assertEqual(out, ['added','enabled Document',
00541                                                     'disabled Document'])
00542         portal_repository.removePolicy('my_bogus_policy', out=out)
00543         self.assertEqual(out, ['added','enabled Document',
00544                                             'disabled Document','removed'])
00545         self.assertEqual(len(portal_repository.listPolicies()), self.np)
00546 
00547     def test10_remove_policy_disables_types_first(self):
00548         # Ensure that removal calls the type removal hooks
00549         portal_repository = self.portal.portal_repository
00550         out = []
00551         portal_repository.addPolicy('my_bogus_policy',
00552                                   'Hook Tests', dummyPolicyWithHooks, out=out)
00553         portal_repository.addPolicyForContentType('Document',
00554                                                    'my_bogus_policy', out=out)
00555         portal_repository.removePolicy('my_bogus_policy', out=out)
00556         self.assertEqual(out, ['added','enabled Document',
00557                                             'disabled Document','removed'])
00558 
00559     def test11_set_policy_calls_all_hooks(self):
00560         # Explicitly setting policies removes/disables all old policies and
00561         # adds/enables new ones.
00562         portal_repository = self.portal.portal_repository
00563         out = []
00564         portal_repository.addPolicy('my_bogus_policy',
00565                                   'Hook Tests', dummyPolicyWithHooks, out=out)
00566         portal_repository.addPolicyForContentType('Document',
00567                                                    'my_bogus_policy', out=out)
00568         portal_repository.manage_changePolicyDefs((('my_bogus_policy2',
00569                   'Fake title', dummyPolicyWithHooks, {'out':out}),), out=out)
00570         self.assertEqual(out, ['added','enabled Document','disabled Document',
00571                     'removed','added'])
00572 
00573     def test12_set_policy_types_map_calls_all_hooks(self):
00574         # Explicitly setting policies removes/disables all old policies and
00575         # adds/enables new ones.
00576         portal_repository = self.portal.portal_repository
00577         out = []
00578         portal_repository.addPolicy('my_bogus_policy',
00579                                   'Hook Tests', dummyPolicyWithHooks, out=out)
00580         portal_repository.addPolicyForContentType('Document',
00581                                                    'my_bogus_policy', out=out)
00582         portal_repository.manage_setTypePolicies({'Event':
00583                                                          ['my_bogus_policy']},
00584                                                          out=out)
00585         self.assertEqual(out, ['added','enabled Document','disabled Document',
00586                     'enabled Event'])
00587 
00588     def test13_at_auto_version_hooks(self):
00589         portal_repository = self.portal.portal_repository
00590         # Check if the form controller hook is in place:
00591         self.failUnless(self.isFCActionInPlace('validate_integrity',
00592                                                      'success', None, None))
00593         self.failUnless(self.isFCActionInPlace('atct_edit',
00594                                                      'success', None, None))
00595         # Remove policy and check if hook is removed
00596         portal_repository.removePolicy('at_edit_autoversion')
00597         self.failIf(self.isFCActionInPlace('validate_integrity',
00598                                                  'success', None, None))
00599         self.failIf(self.isFCActionInPlace('atct_edit',
00600                                                      'success', None, None))
00601         # Add policy and check if hook is added
00602         portal_repository.addPolicy('at_edit_autoversion', 'Auto policy',
00603                                      ATVersionOnEditPolicy)
00604         self.failUnless(self.isFCActionInPlace('validate_integrity',
00605                                                      'success', None, None))
00606         self.failUnless(self.isFCActionInPlace('atct_edit',
00607                                                      'success', None, None))
00608 
00609     def test14_has_policy(self):
00610         portal_repository = self.portal.portal_repository
00611         # We already have two policies by default
00612         self.failUnless(portal_repository.hasPolicy(self.portal.doc))
00613         portal_repository.removePolicyFromContentType('Document',
00614                                                         'at_edit_autoversion')
00615         portal_repository.removePolicyFromContentType('Document',
00616                                                         'version_on_revert')
00617         self.failIf(portal_repository.hasPolicy(self.portal.doc))
00618 
00619 
00620 
00621 from unittest import TestSuite, makeSuite
00622 def test_suite():
00623     suite = TestSuite()
00624     suite.addTest(makeSuite(TestCopyModifyMergeRepositoryTool))
00625     suite.addTest(makeSuite(TestRepositoryWithDummyArchivist))
00626     suite.addTest(makeSuite(TestRegressionTests))
00627     suite.addTest(makeSuite(TestPolicyVersioning))
00628     return suite