Back to index

plone3  3.1.7
test_iterate.py
Go to the documentation of this file.
00001 ##################################################################
00002 #
00003 # (C) Copyright 2006 ObjectRealms, LLC
00004 # All Rights Reserved
00005 #
00006 # This file is part of iterate.
00007 #
00008 # iterate 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 # iterate 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 iterate; if not, write to the Free Software
00020 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 ##################################################################
00022 """
00023 $Id: test_iterate.py 1595 2006-08-24 00:15:21Z hazmat $
00024 """
00025 
00026 import os, sys
00027 
00028 from zope.component import getMultiAdapter
00029 
00030 from Acquisition import aq_base
00031 from AccessControl import getSecurityManager
00032 
00033 from plone.app.iterate.interfaces import ICheckinCheckoutPolicy
00034 
00035 from Products.PloneTestCase import PloneTestCase
00036 from Testing.ZopeTestCase import FunctionalDocFileSuite
00037 PloneTestCase.setupPloneSite()
00038 
00039 class TestIterations(PloneTestCase.PloneTestCase):
00040 
00041     def afterSetUp(self):
00042         self.setRoles(['Manager',])
00043         
00044         # Since we depend on ZCML being loaded, we can't do this
00045         # until the layer is set up
00046         
00047         self.portal.portal_quickinstaller.installProduct('plone.app.iterate')
00048 
00049         # add a folder with two documents in it
00050         self.portal.invokeFactory('Folder', 'docs')
00051         self.portal.docs.invokeFactory('Document', 'doc1')
00052         self.portal.docs.invokeFactory('Document', 'doc2')
00053 
00054         # add a working copy folder
00055         self.portal.invokeFactory('Folder', 'workarea')
00056 
00057         self.repo = self.portal.portal_repository
00058         self.wf   = self.portal.portal_workflow
00059 
00060     def beforeTearDown(self):
00061         self.repo = None
00062         self.wf   = None
00063 
00064     def shim_test( self, test_method):
00065 
00066         try:
00067             test_method()
00068         except:
00069             import sys, pdb, traceback
00070             ec, e, tb = sys.exc_info()
00071             traceback.print_exc()            
00072             pdb.post_mortem( tb )
00073 
00074     def test_workflowState( self ):
00075         # ensure baseline workflow state is retained on checkin, including security
00076 
00077         doc = self.portal.docs.doc1
00078         
00079         # sanity check that owner can edit visible docs
00080         self.setRoles(['Owner',])
00081         self.assertTrue( getSecurityManager().checkPermission( "Modify portal content",
00082                                                                self.portal.docs.doc1 ) )
00083 
00084         self.setRoles(['Manager',])        
00085         self.wf.doActionFor( doc, 'publish')
00086         state = self.wf.getInfoFor( doc, 'review_state')
00087         
00088         self.repo.save( doc )
00089         wc = ICheckinCheckoutPolicy( doc ).checkout( self.portal.workarea )
00090         wc_state = self.wf.getInfoFor( wc, 'review_state')
00091         
00092         self.assertNotEqual( state, wc_state )
00093 
00094         ICheckinCheckoutPolicy( wc ).checkin( "modified" )
00095         bstate = self.wf.getInfoFor( wc, 'review_state')
00096         self.assertEqual( state, bstate )
00097         self.setRoles(['Owner',])       
00098 
00099     def test_baselineVersionCreated( self ):
00100         # if a baseline has no version ensure that one is created on checkout
00101 
00102         doc = self.portal.docs.doc1
00103         self.assertTrue( self.repo.isVersionable( doc ) )
00104 
00105         history = self.repo.getHistory( doc )
00106         self.assertEqual( len(history), 0 )
00107 
00108         ICheckinCheckoutPolicy( doc ).checkout( self.portal.workarea )
00109 
00110         history = self.repo.getHistory( doc )
00111         self.assertEqual( len(history), 1 )
00112 
00113         doc2 = self.portal.docs.doc2
00114         self.repo.save( doc2 )
00115 
00116         ICheckinCheckoutPolicy( doc2 ).checkout( self.portal.workarea )
00117 
00118         history = self.repo.getHistory( doc2 )
00119         self.assertEqual( len(history), 1 )
00120     
00121     def test_wcNewForwardReferencesCopied( self ):
00122         # ensure that new wc references are copied back to the baseline on checkin
00123         doc = self.portal.docs.doc1
00124         doc.addReference( self.portal.docs )
00125         self.assertEqual( len(doc.getReferences("zebra")), 0)
00126         wc = ICheckinCheckoutPolicy( doc ).checkout( self.portal.workarea )
00127         wc.addReference( self.portal.docs.doc2, "zebra")        
00128         doc = ICheckinCheckoutPolicy( wc ).checkin( "updated" )
00129         self.assertEqual( len(doc.getReferences("zebra")), 1 )
00130         
00131     def test_wcNewBackwardReferencesCopied( self ):
00132         # ensure that new wc back references are copied back to the baseline on checkin
00133 
00134         doc = self.portal.docs.doc1
00135         self.assertEqual( len(doc.getBackReferences("zebra")), 0)
00136         wc = ICheckinCheckoutPolicy( doc ).checkout( self.portal.workarea )
00137         self.portal.docs.doc2.addReference( wc, "zebra")
00138         self.assertEqual( len( wc.getBackReferences("zebra")), 1 )        
00139         doc = ICheckinCheckoutPolicy( wc ).checkin( "updated")
00140         self.assertEqual( len( doc.getBackReferences("zebra")), 1 )
00141 
00142     def test_baselineReferencesMaintained( self ):
00143         # ensure that baseline references are maintained when the object is checked in
00144         # copies forward, bkw are not copied, but are maintained.
00145 
00146         doc = self.portal.docs.doc1
00147         doc.addReference( self.portal.docs, "elephant" )
00148         self.portal.docs.doc2.addReference( doc )
00149 
00150         wc = ICheckinCheckoutPolicy( doc ).checkout( self.portal.workarea )
00151 
00152         doc = ICheckinCheckoutPolicy( wc ).checkin( "updated" )
00153 
00154         self.assertEqual( len(doc.getReferences()), 1 )
00155         self.assertEqual( len(doc.getBackReferences()), 1 )
00156 
00157     def test_baselineNoCopyReferences( self ):
00158         # ensure that custom state is maintained with the no copy adapter
00159 
00160         # setup the named ref adapter
00161         from zope import component
00162         from Products.Archetypes.interfaces import IBaseObject
00163         from plone.app.iterate import relation, interfaces
00164         from plone.app.iterate.tests.utils import CustomReference
00165         
00166         component.provideAdapter( 
00167             adapts = (IBaseObject,),
00168             provides = interfaces.ICheckinCheckoutReference,
00169             factory = relation.NoCopyReferenceAdapter,
00170             name="zebra")
00171 
00172         doc = self.portal.docs.doc1
00173         ref = doc.addReference( self.portal.docs, "zebra", referenceClass=CustomReference )
00174         ref.custom_state = "hello world"
00175 
00176         wc = ICheckinCheckoutPolicy( doc ).checkout( self.portal.workarea )
00177 
00178         self.assertEqual( len(wc.getReferences("zebra")), 0)
00179 
00180         doc = ICheckinCheckoutPolicy( wc ).checkin( "updated" )
00181 
00182         self.assertEqual( len(doc.getReferences("zebra")), 1)
00183 
00184         ref = doc.getReferenceImpl("zebra")[0]
00185 
00186         self.assert_( hasattr( ref, "custom_state") )
00187         self.assertEqual( ref.custom_state, "hello world")
00188 
00189 
00190 def test_suite():
00191     from unittest import TestSuite, makeSuite
00192     suite = TestSuite()
00193     suite.addTest(makeSuite(TestIterations))
00194     suite.addTest(FunctionalDocFileSuite(
00195         'browser.txt',
00196         test_class=PloneTestCase.FunctionalTestCase))
00197     return suite