[CMF-checkins] CVS: CMF/CMFStaging/tests - testVersions.py:1.1 testStaging.py:1.5
Shane Hathaway
shane@cvs.zope.org
Mon, 13 May 2002 15:21:09 -0400
Update of /cvs-repository/CMF/CMFStaging/tests
In directory cvs.zope.org:/tmp/cvs-serv22249/tests
Modified Files:
testStaging.py
Added Files:
testVersions.py
Log Message:
- Added tests of the versions tool.
- Added a test of a complete combination of the three tools.
- Made the name of the version repository configurable.
=== Added File CMF/CMFStaging/tests/testVersions.py ===
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE
#
##############################################################################
"""Unit tests for the versions tool.
$Id: testVersions.py,v 1.1 2002/05/13 19:21:08 shane Exp $
"""
import unittest
import Testing
from Acquisition import aq_base
import Zope
from OFS.Folder import Folder
from AccessControl.User import SimpleUser
from Products.CMFStaging.VersionsTool import VersionsTool
from Products.ZopeVersionControl.Utility import VersionControlError
class Tests(unittest.TestCase):
def setUp(self):
app = Zope.app()
self.app = app
if hasattr(app, 'testroot'):
app._delObject('testroot')
app.manage_addProduct['OFSP'].manage_addFolder('testroot')
self.root = app.testroot
zvc = self.root.manage_addProduct['ZopeVersionControl']
zvc.addRepository('VersionRepository')
setattr(self.root, VersionsTool.id, VersionsTool())
self.tool = getattr(self.root, VersionsTool.id)
self.root.content = Folder()
self.root.content.id = 'content'
def tearDown(self):
app = self.app
if hasattr(app, 'testroot'):
app._delObject('testroot')
self.app._p_jar.close()
def testCheckinCheckout(self):
vt = self.tool
content = self.root.content
vt.checkin(content)
self.assert_(not vt.isCheckedOut(content))
vt.checkout(content)
self.assert_(vt.isCheckedOut(content))
def testGetVersionId(self):
vt = self.tool
content = self.root.content
self.assertEqual(vt.getVersionId(content), '')
vt.checkin(content)
old_id = vt.getVersionId(content)
self.assertNotEqual(old_id, '')
vt.checkout(content)
vt.checkin(content)
new_id = vt.getVersionId(content)
self.assertNotEqual(new_id, '')
self.assertNotEqual(old_id, new_id)
def testRevertToVersion(self):
vt = self.tool
content = self.root.content
vt.checkin(content)
old_id = vt.getVersionId(content)
vt.checkout(content)
vt.checkin(content)
new_id = vt.getVersionId(content)
self.assertNotEqual(new_id, old_id)
vt.revertToVersion(content, old_id)
content = self.root.content # XXX ZopeVersionControl requires this
current_id = vt.getVersionId(content)
self.assertNotEqual(new_id, current_id)
self.assertEqual(old_id, current_id)
def testRevertThenCheckout(self):
vt = self.tool
content = self.root.content
vt.checkin(content)
old_id = vt.getVersionId(content)
vt.checkout(content)
vt.checkin(content)
new_id = vt.getVersionId(content)
vt.revertToVersion(content, old_id)
content = self.root.content # XXX ZopeVersionControl requires this
vt.auto_copy_forward = 0
# Can't normally check out when the object is in an old state
self.assertRaises(VersionControlError, vt.checkout, content)
vt.auto_copy_forward = 1
# Now we can check out.
vt.checkout(content)
content = self.root.content # XXX ZopeVersionControl requires this
current_id = vt.getVersionId(content)
self.assertNotEqual(current_id, old_id)
self.assertNotEqual(current_id, new_id)
def testGetLogEntries(self):
vt = self.tool
content = self.root.content
log = vt.getLogEntries(content)
self.assertEqual(tuple(log), ())
vt.checkin(content)
content = vt.checkout(content)
vt.checkin(content)
log = vt.getLogEntries(content, only_checkins=1)
self.assert_(len(log) == 2)
log = vt.getLogEntries(content, only_checkins=0)
for entry in log:
for key in ('timestamp', 'version_id', 'action', 'message',
'user_id', 'path'):
self.assert_(entry.has_key(key))
def test_suite():
return unittest.TestSuite((
unittest.makeSuite(Tests),
))
if __name__ == '__main__':
unittest.main(defaultTest='test_suite')
=== CMF/CMFStaging/tests/testStaging.py 1.4 => 1.5 ===
from Acquisition import aq_base
from OFS.Folder import Folder
+from AccessControl.SecurityManagement import newSecurityManager, \
+ noSecurityManager
from Products.CMFStaging.StagingTool import StagingTool, StagingError
from Products.ZopeVersionControl.Utility import VersionControlError
@@ -65,6 +67,7 @@
if hasattr(app, 'testroot'):
app._delObject('testroot')
self.app._p_jar.close()
+ noSecurityManager()
def testStageable(self):
@@ -150,10 +153,63 @@
self.assertRaises(StagingError, st.checkContainers,
self.dev_stage.c1.test, ['review'])
+
def testGetURLForStage(self):
st = self.root.portal_staging
url = st.getURLForStage(self.dev_stage.c1, 'dev', 1)
self.assert_(url.find('/Stages/Development/c1') >= 0)
+
+
+ def testCompleteSetup(self):
+ # Create a lock tool and versions tool then perform
+ # some complete development and staging activities.
+ from Products.CMFStaging.LockTool import LockTool
+ from Products.CMFStaging.VersionsTool import VersionsTool
+
+ self.root.manage_addProduct['CMFStaging'].manage_addTool(
+ LockTool.meta_type)
+ self.root.manage_addProduct['CMFStaging'].manage_addTool(
+ VersionsTool.meta_type)
+
+ lt = self.root.portal_lock
+ vt = self.root.portal_versions
+ st = self.root.portal_staging
+
+ # The automation features need to be turned on.
+ self.assert_(lt.auto_version)
+ self.assert_(st.auto_checkin)
+
+ from testLockTool import TestUser
+
+ user = TestUser('andre')
+ newSecurityManager(None, user.__of__(self.root.acl_users))
+
+ # Put c1 in the review stage.
+ # Lock with auto checkout
+ lt.lock(self.dev_stage.c1)
+ # Update with auto unlock and checkin
+ st.updateStages(self.dev_stage.c1, 'dev', ['review'])
+ versions = st.getVersionIds(self.dev_stage.c1)
+ self.assertEqual(versions['dev'], versions['review'])
+ self.assert_(not versions['prod'])
+
+ # Make a change in the dev stage.
+ # Lock with auto checkout
+ lt.lock(self.dev_stage.c1)
+ # Unlock with auto checkin
+ lt.unlock(self.dev_stage.c1)
+ versions = st.getVersionIds(self.dev_stage.c1)
+ self.assertNotEqual(versions['dev'], versions['review'])
+ wanted_published = versions['dev'] # This version should be published.
+
+ # Publish c1.
+ # Unlocked and checked in already
+ st.updateStages(self.dev_stage.c1, 'dev', ['review', 'prod'])
+ versions = st.getVersionIds(self.dev_stage.c1)
+ self.assertEqual(versions['dev'], wanted_published)
+ self.assertEqual(versions['dev'], versions['review'])
+ self.assertEqual(versions['dev'], versions['prod'])
+
def test_suite():