[Zope-Checkins] SVN: Zope/trunk/lib/python/Testing/ZopeTestCase/
Update to ZopeTestCase 0.9.2+
Stefan H. Holek
stefan at epy.co.at
Fri Oct 1 06:43:30 EDT 2004
Log message for revision 27730:
Update to ZopeTestCase 0.9.2+
Changed:
U Zope/trunk/lib/python/Testing/ZopeTestCase/PortalTestCase.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeLite.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeTestCase.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py
A Zope/trunk/lib/python/Testing/ZopeTestCase/base.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx
U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/INSTALL.stx
U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/IZopeTestCase.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/SECURITY.stx
U Zope/trunk/lib/python/Testing/ZopeTestCase/doc/VERSION.txt
U Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/sandbox.py
A Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/testFunctional.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/testPortalTestCase.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/testWebserver.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/testZopeTestCase.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py
U Zope/trunk/lib/python/Testing/ZopeTestCase/ztc_common.py
-=-
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/PortalTestCase.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/PortalTestCase.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/PortalTestCase.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -14,19 +14,22 @@
# getPortal() returns a usable portal object to the setup code.
#
-# $Id: PortalTestCase.py,v 1.24 2004/03/29 01:14:14 shh42 Exp $
+# $Id: PortalTestCase.py,v 1.29 2004/09/09 18:48:59 shh42 Exp $
-import ZopeTestCase
+import base
+import types
from AccessControl import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
+from AccessControl.SecurityManagement import noSecurityManager
from Acquisition import aq_base
portal_name = 'portal'
-user_name = ZopeTestCase.user_name
+from ZopeTestCase import user_name
+from ZopeTestCase import user_password
-class PortalTestCase(ZopeTestCase.ZopeTestCase):
+class PortalTestCase(base.TestCase):
'''Base test case for testing CMF-style portals
__implements__ = (IPortalTestCase, ISimpleSecurity, IExtensibleSecurity)
@@ -37,9 +40,11 @@
_configure_portal = 1
def getPortal(self):
- '''Returns the portal object for use by the setup
- code. Will typically be overridden by subclasses
- to return the object serving as the portal.
+ '''Returns the portal object to the setup code.
+ Will typically be overridden by subclasses
+ to return the object serving as the "portal".
+
+ Note: This method should not be called by tests!
'''
return self.app[portal_name]
@@ -67,7 +72,9 @@
raise
def _setup(self):
- '''Configures the portal. Framework authors may override.'''
+ '''Configures the portal. Framework authors may
+ override.
+ '''
if self._configure_portal:
self._setupUserFolder()
self._setupUser()
@@ -82,7 +89,7 @@
def _setupUser(self):
'''Creates the default user.'''
uf = self.portal.acl_users
- uf._doAddUser(user_name, 'secret', ['Member'], [])
+ uf.userFolderAddUser(user_name, user_password, ['Member'], [])
def _setupHomeFolder(self):
'''Creates the default user's home folder.'''
@@ -97,30 +104,31 @@
if hasattr(self.portal, 'setupCurrentSkin'):
self.portal.setupCurrentSkin()
- def _clear(self, call_close_hook=0):
- '''Clears the fixture.'''
- # No automagic cleanups here. We rely on
- # transaction abort. Those who commit are
- # required to clean up their own mess.
- if call_close_hook:
- self.beforeClose()
- self._close()
- self.logout()
- self.afterClear()
-
# Security interfaces
def setRoles(self, roles, name=user_name):
'''Changes the user's roles.'''
+ self.assertEqual(type(roles), types.ListType)
uf = self.portal.acl_users
- uf._doChangeUser(name, None, roles, [])
+ uf.userFolderEditUser(name, None, roles, [])
if name == getSecurityManager().getUser().getId():
self.login(name)
+ def getRoles(self, name=user_name):
+ '''Returns the user's roles.'''
+ uf = self.portal.acl_users
+ return uf.getUserById(name).getRoles()
+
def setPermissions(self, permissions, role='Member'):
- '''Changes the user's permissions.'''
+ '''Changes the permissions assigned to role.'''
+ self.assertEqual(type(permissions), types.ListType)
self.portal.manage_role(role, permissions)
+ def getPermissions(self, role='Member'):
+ '''Returns the permissions assigned to role.'''
+ perms = self.portal.permissionsOfRole(role)
+ return [p['name'] for p in perms if p['selected']]
+
def login(self, name=user_name):
'''Logs in.'''
uf = self.portal.acl_users
@@ -129,7 +137,22 @@
user = user.__of__(uf)
newSecurityManager(None, user)
+ def logout(self):
+ '''Logs out.'''
+ noSecurityManager()
+ # b/w compatibility methods
+
+ def _setRoles(self, roles, name=user_name):
+ self.setRoles(roles, name)
+ def _setPermissions(self, permissions, role='Member'):
+ self.setPermissions(permissions, role)
+ def _login(self, name=user_name):
+ self.login(name)
+ def _logout(self):
+ self.logout()
+
+
# b/w compatibility names
_portal_name = portal_name
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeLite.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeLite.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeLite.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -12,7 +12,7 @@
# app = Zope.app()
#
-# $Id: ZopeLite.py,v 1.19 2004/03/19 13:51:32 shh42 Exp $
+# $Id: ZopeLite.py,v 1.24 2004/08/18 09:28:54 shh42 Exp $
import os, sys, time
@@ -20,7 +20,7 @@
sys.setcheckinterval(2500)
# Shut up if we are not in control of the import process
-_quiet = 'Zope' in sys.modules.keys()
+_quiet = sys.modules.has_key('Zope')
def _print(msg):
'''Writes 'msg' to stderr and flushes the stream.'''
@@ -48,6 +48,10 @@
except ImportError:
pass # Zope < 2.7
else:
+ # Configure logging
+ if not sys.modules.has_key('logging'):
+ import logging
+ logging.basicConfig()
# Need to import Zope early on as the
# ZTUtils package relies on it
config = App.config.getConfiguration()
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeTestCase.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeTestCase.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/ZopeTestCase.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -11,15 +11,11 @@
# and 'View' permissions given to his role.
#
-# $Id: ZopeTestCase.py,v 1.15 2004/03/29 01:14:13 shh42 Exp $
+# $Id: ZopeTestCase.py,v 1.21 2004/09/04 18:01:08 shh42 Exp $
-import ZopeLite as Zope
+import base
+import types
-import unittest
-import utils
-import profiler
-
-import transaction
from AccessControl import getSecurityManager
from AccessControl.SecurityManagement import newSecurityManager
from AccessControl.SecurityManagement import noSecurityManager
@@ -28,30 +24,12 @@
folder_name = 'test_folder_1_'
user_name = 'test_user_1_'
+user_password = 'secret'
user_role = 'test_role_1_'
standard_permissions = [access_contents_information, view]
-_connections = utils.ConnectionRegistry()
-
-
-def app():
- '''Opens a ZODB connection and returns the app object.'''
- app = Zope.app()
- _connections.register(app._p_jar)
- return utils.makerequest(app)
-
-def close(app):
- '''Closes the app's ZODB connection.'''
- _connections.close(app._p_jar)
-
-def closeConnections():
- '''Closes all registered ZODB connections.'''
- _connections.closeAll()
-
-
-
-class ZopeTestCase(profiler.Profiled, unittest.TestCase):
+class ZopeTestCase(base.TestCase):
'''Base test case for Zope testing
__implements__ = (IZopeTestCase, ISimpleSecurity, IExtensibleSecurity)
@@ -61,70 +39,10 @@
_setup_fixture = 1
- def afterSetUp(self):
- '''Called after setUp() has completed. This is
- far and away the most useful hook.
- '''
- pass
-
- def beforeTearDown(self):
- '''Called before tearDown() is executed.
- Note that tearDown() is not called if
- setUp() fails.
- '''
- pass
-
- def afterClear(self):
- '''Called after the fixture has been cleared.
- Note that this may occur during setUp() *and*
- tearDown().
- '''
- pass
-
- def beforeSetUp(self):
- '''Called before the ZODB connection is opened,
- at the start of setUp(). By default begins
- a new transaction.
- '''
- transaction.begin()
-
- def beforeClose(self):
- '''Called before the ZODB connection is closed,
- at the end of tearDown(). By default aborts
- the transaction.
- '''
- get_transaction().abort()
-
- def setUp(self):
- '''Sets up the fixture. Do not override,
- use the hooks instead.
- '''
- try:
- self.beforeSetUp()
- self.app = self._app()
- self._setup()
- self.afterSetUp()
- except:
- self._clear()
- raise
-
- def tearDown(self):
- '''Tears down the fixture. Do not override,
- use the hooks instead.
- '''
- try:
- self.beforeTearDown()
- self._clear(1)
- except:
- self._clear()
- raise
-
- def _app(self):
- '''Returns the app object for a test.'''
- return app()
-
def _setup(self):
- '''Sets up the fixture. Framework authors may override.'''
+ '''Sets up the fixture. Framework authors may
+ override.
+ '''
if self._setup_fixture:
self._setupFolder()
self._setupUserFolder()
@@ -145,37 +63,43 @@
def _setupUser(self):
'''Creates the default user.'''
uf = self.folder.acl_users
- uf._doAddUser(user_name, 'secret', [user_role], [])
+ uf.userFolderAddUser(user_name, user_password, [user_role], [])
def _clear(self, call_close_hook=0):
'''Clears the fixture.'''
- if self._setup_fixture:
- try: self.app._delObject(folder_name)
- except (AttributeError, RuntimeError): pass
- if call_close_hook:
- self.beforeClose()
- self._close()
- self.logout()
- self.afterClear()
+ # This code is a wart from the olden days.
+ try:
+ if base._connections.contains(self.app._p_jar):
+ self.app._delObject(folder_name)
+ except:
+ pass
+ base.TestCase._clear(self, call_close_hook)
- def _close(self):
- '''Closes the ZODB connection.'''
- get_transaction().abort()
- closeConnections()
-
# Security interfaces
def setRoles(self, roles, name=user_name):
'''Changes the user's roles.'''
+ self.assertEqual(type(roles), types.ListType)
uf = self.folder.acl_users
- uf._doChangeUser(name, None, roles, [])
+ uf.userFolderEditUser(name, None, roles, [])
if name == getSecurityManager().getUser().getId():
self.login(name)
+ def getRoles(self, name=user_name):
+ '''Returns the user's roles.'''
+ uf = self.folder.acl_users
+ return uf.getUserById(name).getRoles()
+
def setPermissions(self, permissions, role=user_role):
'''Changes the user's permissions.'''
+ self.assertEqual(type(permissions), types.ListType)
self.folder.manage_role(role, permissions)
+ def getPermissions(self, role=user_role):
+ '''Returns the user's permissions.'''
+ perms = self.folder.permissionsOfRole(role)
+ return [p['name'] for p in perms if p['selected']]
+
def login(self, name=user_name):
'''Logs in.'''
uf = self.folder.acl_users
@@ -205,4 +129,7 @@
_user_name = user_name
_user_role = user_role
_standard_permissions = standard_permissions
+from base import app
+from base import close
+from base import closeConnections
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/__init__.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -2,7 +2,7 @@
# Names exported by the ZopeTestCase module
#
-# $Id: __init__.py,v 1.11 2004/02/06 18:00:02 shh42 Exp $
+# $Id: __init__.py,v 1.13 2004/08/19 15:52:55 shh42 Exp $
import ZopeLite as Zope
import utils
@@ -11,8 +11,13 @@
from ZopeLite import hasProduct
from ZopeLite import _print
+from base import TestCase
+from base import app
+from base import close
+
from ZopeTestCase import folder_name
from ZopeTestCase import user_name
+from ZopeTestCase import user_password
from ZopeTestCase import user_role
from ZopeTestCase import standard_permissions
from ZopeTestCase import ZopeTestCase
@@ -24,10 +29,6 @@
from sandbox import Sandboxed
from functional import Functional
-from ZopeTestCase import app
-from ZopeTestCase import close
-from ZopeTestCase import closeConnections
-
from unittest import main
# Convenience class for functional unit testing
@@ -40,4 +41,5 @@
_user_role = user_role
_standard_permissions = standard_permissions
_portal_name = portal_name
+from base import closeConnections
Added: Zope/trunk/lib/python/Testing/ZopeTestCase/base.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/base.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/base.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -0,0 +1,127 @@
+#
+# Test case for Zope testing
+#
+
+# $Id: base.py,v 1.1 2004/08/19 13:59:41 shh42 Exp $
+
+import ZopeLite as Zope
+
+import unittest
+import transaction
+import profiler
+import utils
+
+from AccessControl.SecurityManagement import noSecurityManager
+
+_connections = utils.ConnectionRegistry()
+
+
+
+def app():
+ '''Opens a ZODB connection and returns the app object.'''
+ app = Zope.app()
+ _connections.register(app._p_jar)
+ return utils.makerequest(app)
+
+def close(app):
+ '''Closes the app's ZODB connection.'''
+ _connections.close(app._p_jar)
+
+def closeConnections():
+ '''Closes all registered ZODB connections.'''
+ _connections.closeAll()
+
+
+
+class TestCase(profiler.Profiled, unittest.TestCase):
+ '''Base test case for Zope testing
+
+ __implements__ = (IZopeTestCase,)
+
+ See doc/IZopeTestCase.py for more
+ '''
+
+ def afterSetUp(self):
+ '''Called after setUp() has completed. This is
+ far and away the most useful hook.
+ '''
+ pass
+
+ def beforeTearDown(self):
+ '''Called before tearDown() is executed.
+ Note that tearDown() is not called if
+ setUp() fails.
+ '''
+ pass
+
+ def afterClear(self):
+ '''Called after the fixture has been cleared.
+ Note that this may occur during setUp() *and*
+ tearDown().
+ '''
+ pass
+
+ def beforeSetUp(self):
+ '''Called before the ZODB connection is opened,
+ at the start of setUp(). By default begins
+ a new transaction.
+ '''
+ transaction.begin()
+
+ def beforeClose(self):
+ '''Called before the ZODB connection is closed,
+ at the end of tearDown(). By default aborts
+ the transaction.
+ '''
+ transaction.abort()
+
+ def setUp(self):
+ '''Sets up the fixture. Do not override,
+ use the hooks instead.
+ '''
+ try:
+ self.beforeSetUp()
+ self.app = self._app()
+ self._setup()
+ self.afterSetUp()
+ except:
+ self._clear()
+ raise
+
+ def tearDown(self):
+ '''Tears down the fixture. Do not override,
+ use the hooks instead.
+ '''
+ try:
+ self.beforeTearDown()
+ self._clear(1)
+ except:
+ self._clear()
+ raise
+
+ def _app(self):
+ '''Returns the app object for a test.'''
+ return app()
+
+ def _setup(self):
+ '''Sets up the fixture. Framework authors may
+ override.
+ '''
+
+ def _clear(self, call_close_hook=0):
+ '''Clears the fixture.'''
+ if call_close_hook:
+ self.beforeClose()
+ self._close()
+ self.logout()
+ self.afterClear()
+
+ def _close(self):
+ '''Closes the ZODB connection.'''
+ transaction.abort()
+ closeConnections()
+
+ def logout(self):
+ '''Logs out.'''
+ noSecurityManager()
+
Property changes on: Zope/trunk/lib/python/Testing/ZopeTestCase/base.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/API.stx 2004-10-01 10:43:30 UTC (rev 27730)
@@ -17,6 +17,8 @@
user_name
+ user_password
+
user_role
standard_permissions
@@ -39,6 +41,8 @@
Classes
+ TestCase
+
ZopeTestCase
PortalTestCase
@@ -81,20 +85,10 @@
-Module ZopeTestCase
+Module base
- Default test case and fixture for Zope testing
+ Bare-bones base test case for Zope testing
- Constants
-
- folder_name
-
- user_name
-
- user_role
-
- standard_permissions
-
Functions
app()
@@ -103,17 +97,14 @@
Classes
- ZopeTestCase
-
-
+ TestCase
-Class ZopeTestCase
- Base test case for Zope testing
- Attributes
+Class TestCase
- _setup_fixture = 1
+ Bare-bones base test case for Zope testing
+ (derived from unittest.TestCase)
Methods
@@ -127,10 +118,45 @@
beforeClose()
+
+
+Module ZopeTestCase
+
+ Test case and fixture for Zope testing
+
+ Constants
+
+ folder_name
+
+ user_name
+
+ user_password
+
+ user_role
+
+ standard_permissions
+
+ Classes
+
+ ZopeTestCase
+
+
+
+Class ZopeTestCase
+
+ Base test case for Zope testing
+ (derived from base.TestCase)
+
+ Methods
+
setRoles(roles, name=user_name)
+ getRoles(name=user_name)
+
setPermissions(permissions, role=user_role)
+ getPermissions(role=user_role)
+
login(name=user_name)
logout()
@@ -147,6 +173,8 @@
user_name
+ user_password
+
Classes
PortalTestCase
@@ -156,31 +184,22 @@
Class PortalTestCase
Base test case for CMF testing
+ (derived from base.TestCase)
- Attributes
-
- _configure_portal = 1
-
Methods
getPortal()
createMemberarea(name)
- afterSetUp()
+ setRoles(roles, name=user_name)
- beforeTearDown()
+ getRoles(name=user_name)
- afterClear()
+ setPermissions(permissions, role='Member')
- beforeSetUp()
+ getPermissions(role='Member')
- beforeClose()
-
- setRoles(roles, name=user_name)
-
- setPermissions(permissions, role=user_role)
-
login(name=user_name)
logout()
@@ -271,3 +290,5 @@
importObjectFromFile(container, filename, quiet=0)
+ appcall(func, *args, **kw)
+
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/CHANGES.txt 2004-10-01 10:43:30 UTC (rev 27730)
@@ -1,3 +1,12 @@
+0.9.2
+- Introduced new base.TestCase class which contains the bare-
+ bones framework code and serves as baseclass for ZTC and PTC.
+- ZopeLite now configures the logging module in Zope >= 2.7.
+- Teardown sequence is now compatible with Zope trunk (again).
+- Added getRoles() and getPermissions() methods to security API.
+- setRoles() now asserts 'roles' argument is ListType.
+- setPermissions() now asserts 'permissions' argument is ListType.
+
0.9.0
- No longer support Zope 2.4 as its DemoStorage is broken.
- Made PortalTestCase derive from ZopeTestCase (again).
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/INSTALL.stx
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/INSTALL.stx 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/INSTALL.stx 2004-10-01 10:43:30 UTC (rev 27730)
@@ -4,9 +4,6 @@
Requires Python 2.1 and Zope 2.5 or higher
- Upgrade Notice: Please remove an existing installation
- of ZopeTestCase before installing version 0.9.0!
-
1. Extract the tarball into the 'lib/python/Testing'
directory of your Zope installation.
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/IZopeTestCase.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/IZopeTestCase.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/IZopeTestCase.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -1,6 +1,6 @@
from Interface import Interface
-# $Id: IZopeTestCase.py,v 1.13 2004/02/21 18:54:38 shh42 Exp $
+# $Id: IZopeTestCase.py,v 1.14 2004/09/04 18:01:11 shh42 Exp $
#
@@ -17,9 +17,15 @@
def setRoles(roles):
'''Changes the user's roles.'''
+ def getRoles():
+ '''Returns the user's roles.'''
+
def setPermissions(permissions):
'''Changes the user's permissions.'''
+ def getPermissions():
+ '''Returns the user's permissions.'''
+
def login():
'''Logs in.'''
@@ -32,9 +38,15 @@
def setRoles(roles, name):
'''Changes the roles assigned to a user.'''
+ def getRoles(name):
+ '''Returns the specified user's roles.'''
+
def setPermissions(permissions, role):
'''Changes the permissions assigned to a role.'''
+ def getPermissions(role):
+ '''Returns the permissions assigned to a role.'''
+
def login(name):
'''Logs in as the specified user.'''
@@ -57,7 +69,7 @@
def afterClear():
'''Called after the fixture has been cleared.
- Note that this is done during setUp() *and*
+ Note that this may occur during setUp() *and*
tearDown().
'''
@@ -77,9 +89,11 @@
class IPortalTestCase(IZopeTestCase):
def getPortal():
- '''Returns the portal object for use by the setup
- code. Will typically be overridden by subclasses
- to return the object serving as the portal.
+ '''Returns the portal object to the setup code.
+ Will typically be overridden by subclasses
+ to return the object serving as the "portal".
+
+ Note: This method should not be called by tests!
'''
def createMemberarea(member_id):
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/SECURITY.stx
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/SECURITY.stx 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/SECURITY.stx 2004-10-01 10:43:30 UTC (rev 27730)
@@ -21,7 +21,8 @@
- **'self.folder.acl_users'** is the user folder providing a security context to the work area.
A default user account is added to the user folder with name 'test_user_1_' and password 'secret'.
- You should use the 'ZopeTestCase.user_name' constant when you need the user's name.
+ You should use the 'ZopeTestCase.user_name' constant when you need the user's name, the
+ 'ZopeTestCase.user_password' constant when you need the user's password.
The default user has a single role, 'ZopeTestCase.user_role'.
@@ -32,10 +33,16 @@
- **'self.setRoles(roles, name=user_name)'** allows to change the roles assigned to a user.
If the 'name' argument is omitted, changes the roles of the default user.
+ - **'self.getRoles(name=user_name)'** returns the roles assigned to a user. If the name argument is
+ omitted, returns the roles assigned to the default user.
+
- **'self.setPermissions(permissions, role=user_role)'** allows to change the permissions
assigned to a role. If the 'role' argument is omitted, changes the permissions of the
default role.
+ - **'self.getPermissions(role=user_role)'** return the permissions assigned to a role. If the role
+ argument is omitted, returns the permissions assigned to the default role.
+
- **'self.login(name=user_name)'** allows to log in as a specified user.
If the 'name' argument is omitted, logs in as the default user.
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/doc/VERSION.txt
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/doc/VERSION.txt 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/doc/VERSION.txt 2004-10-01 10:43:30 UTC (rev 27730)
@@ -1,6 +1,6 @@
-ZopeTestCase 0.9.0
+ZopeTestCase 0.9.2
(c) 2002-2004, Stefan H. Holek, stefan at epy.co.at
http://zope.org/Members/shh/ZopeTestCase
License: ZPL
-Zope: 2.5-2.7
+Zope: 2.5-2.8
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/functional.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -1,11 +1,12 @@
#
# Support for functional unit testing in ZTC
-# After Marius Gedmina's functional.py module for Zope3.
+# After Marius Gedminas' functional.py module for Zope3.
#
-# $Id: functional.py,v 1.2 2004/01/14 12:41:32 shh42 Exp $
+# $Id: functional.py,v 1.3 2004/09/12 16:49:59 shh42 Exp $
import sys, re, base64
+import transaction
import sandbox
@@ -25,7 +26,7 @@
from ZPublisher.Test import publish_module
# Commit the sandbox for good measure
- get_transaction().commit()
+ transaction.commit()
if env is None:
env = {}
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/sandbox.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/sandbox.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/sandbox.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -2,9 +2,10 @@
# Support for ZODB sandboxes in ZTC
#
-# $Id: sandbox.py,v 1.1 2004/01/09 15:03:04 shh42 Exp $
+# $Id: sandbox.py,v 1.2 2004/08/19 15:31:26 shh42 Exp $
import ZopeLite as Zope
+import transaction
import utils
@@ -24,7 +25,7 @@
def _close(self):
'''Clears the transaction and the AppZapper.'''
- get_transaction().abort()
+ transaction.abort()
AppZapper().clear()
@@ -55,6 +56,7 @@
from ZODB.ZApplication import ZApplicationWrapper
-ZApplicationWrapper.__old_bobo_traverse__ = ZApplicationWrapper.__bobo_traverse__
-ZApplicationWrapper.__bobo_traverse__ = __bobo_traverse__
+if not hasattr(ZApplicationWrapper, '__old_bobo_traverse__'):
+ ZApplicationWrapper.__old_bobo_traverse__ = ZApplicationWrapper.__bobo_traverse__
+ ZApplicationWrapper.__bobo_traverse__ = __bobo_traverse__
Added: Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -0,0 +1,300 @@
+#
+# Tests the base.TestCase class
+#
+# NOTE: This is *not* an example TestCase. Do not
+# use this file as a blueprint for your own tests!
+#
+# See testPythonScript.py and testShoppingCart.py for
+# example test cases. See testSkeleton.py for a quick
+# way of getting started.
+#
+
+# $Id: testBaseTestCase.py,v 1.2 2004/09/04 18:56:41 shh42 Exp $
+
+import os, sys
+if __name__ == '__main__':
+ execfile(os.path.join(sys.path[0], 'framework.py'))
+
+from Testing.ZopeTestCase import base
+from Testing.ZopeTestCase import utils
+
+from AccessControl import getSecurityManager
+from AccessControl.SecurityManagement import newSecurityManager
+
+
+class HookTest(base.TestCase):
+
+ def setUp(self):
+ self._called = []
+ base.TestCase.setUp(self)
+
+ def beforeSetUp(self):
+ self._called.append('beforeSetUp')
+ base.TestCase.beforeSetUp(self)
+
+ def _setup(self):
+ self._called.append('_setup')
+ base.TestCase._setup(self)
+
+ def afterSetUp(self):
+ self._called.append('afterSetUp')
+ base.TestCase.afterSetUp(self)
+
+ def beforeTearDown(self):
+ self._called.append('beforeTearDown')
+ base.TestCase.beforeTearDown(self)
+
+ def beforeClose(self):
+ self._called.append('beforeClose')
+ base.TestCase.beforeClose(self)
+
+ def afterClear(self):
+ self._called.append('afterClear')
+ base.TestCase.afterClear(self)
+
+ def assertHooks(self, sequence):
+ self.assertEqual(self._called, sequence)
+
+
+class TestTestCase(HookTest):
+
+ def testSetUp(self):
+ self.assertHooks(['beforeSetUp', '_setup', 'afterSetUp'])
+
+ def testTearDown(self):
+ self._called = []
+ self.tearDown()
+ self.assertHooks(['beforeTearDown', 'beforeClose', 'afterClear'])
+
+ def testAppOpensConnection(self):
+ self.assertEqual(len(base._connections), 1)
+ self._app()
+ self.assertEqual(len(base._connections), 2)
+
+ def testClearCallsCloseHook(self):
+ self._called = []
+ self._clear(1)
+ self.assertHooks(['beforeClose', 'afterClear'])
+
+ def testClearSkipsCloseHook(self):
+ self._called = []
+ self._clear()
+ self.assertHooks(['afterClear'])
+
+ def testClearAbortsTransaction(self):
+ self.assertEqual(len(self.getObjectsInTransaction()), 0)
+ self.app.foo = 1
+ self.assertEqual(len(self.getObjectsInTransaction()), 1)
+ self._clear()
+ self.assertEqual(len(self.getObjectsInTransaction()), 0)
+
+ def testClearClosesConnection(self):
+ self.assertEqual(len(base._connections), 1)
+ self._clear()
+ self.assertEqual(len(base._connections), 0)
+
+ def testClearClosesAllConnections(self):
+ self._app()
+ self.assertEqual(len(base._connections), 2)
+ self._clear()
+ self.assertEqual(len(base._connections), 0)
+
+ def testClearLogsOut(self):
+ uf = self.app.acl_users
+ uf.userFolderAddUser('user_1', '', [], [])
+ newSecurityManager(None, uf.getUserById('user_1').__of__(uf))
+ self.assertEqual(getSecurityManager().getUser().getUserName(), 'user_1')
+ self._clear()
+ self.assertEqual(getSecurityManager().getUser().getUserName(), 'Anonymous User')
+
+ def testCloseAbortsTransaction(self):
+ self.assertEqual(len(self.getObjectsInTransaction()), 0)
+ self.app.foo = 1
+ self.assertEqual(len(self.getObjectsInTransaction()), 1)
+ self._close()
+ self.assertEqual(len(self.getObjectsInTransaction()), 0)
+
+ def testCloseClosesConnection(self):
+ self.assertEqual(len(base._connections), 1)
+ self._close()
+ self.assertEqual(len(base._connections), 0)
+
+ def testCloseClosesAllConnections(self):
+ self._app()
+ self.assertEqual(len(base._connections), 2)
+ self._close()
+ self.assertEqual(len(base._connections), 0)
+
+ def testLogoutLogsOut(self):
+ uf = self.app.acl_users
+ uf.userFolderAddUser('user_1', '', [], [])
+ newSecurityManager(None, uf.getUserById('user_1').__of__(uf))
+ self.assertEqual(getSecurityManager().getUser().getUserName(), 'user_1')
+ self.logout()
+ self.assertEqual(getSecurityManager().getUser().getUserName(), 'Anonymous User')
+
+ def getObjectsInTransaction(self):
+ # Let's us spy into the transaction
+ t = get_transaction()
+ if hasattr(t, '_objects'): # Zope < 2.8
+ return t._objects
+ elif hasattr(t, '_resources'): # Zope >= 2.8
+ return t._resources
+ else:
+ raise Exception, 'Unknown version'
+
+
+class TestSetUpRaises(HookTest):
+
+ class Error: pass
+
+ def setUp(self):
+ try:
+ HookTest.setUp(self)
+ except self.Error:
+ self.assertHooks(['beforeSetUp', '_setup', 'afterClear'])
+ # Connection has been closed
+ self.assertEqual(len(base._connections), 0)
+
+ def _setup(self):
+ HookTest._setup(self)
+ raise self.Error
+
+ def testTrigger(self):
+ pass
+
+
+class TestTearDownRaises(HookTest):
+
+ class Error: pass
+
+ def tearDown(self):
+ self._called = []
+ try:
+ HookTest.tearDown(self)
+ except self.Error:
+ self.assertHooks(['beforeTearDown', 'beforeClose', 'afterClear'])
+ # Connection has been closed
+ self.assertEqual(len(base._connections), 0)
+
+ def beforeClose(self):
+ HookTest.beforeClose(self)
+ raise self.Error
+
+ def testTrigger(self):
+ pass
+
+
+class TestConnectionRegistry(base.TestCase):
+
+ class Conn:
+ closed = 0
+ def close(self):
+ self.closed = 1
+
+ def afterSetUp(self):
+ self.reg = utils.ConnectionRegistry()
+ self.conns = [self.Conn(), self.Conn(), self.Conn()]
+
+ def testRegister(self):
+ # Should be able to register connections
+ for conn in self.conns:
+ self.reg.register(conn)
+ assert len(self.reg) == 3
+
+ def testCloseConnection(self):
+ # Should be able to close a single registered connection
+ for conn in self.conns:
+ self.reg.register(conn)
+ assert len(self.reg) == 3
+ self.reg.close(self.conns[0])
+ assert len(self.reg) == 2
+ assert self.conns[0].closed == 1
+ assert self.conns[1].closed == 0
+ assert self.conns[2].closed == 0
+
+ def testCloseSeveralConnections(self):
+ # Should be able to close all registered connections one-by-one
+ for conn in self.conns:
+ self.reg.register(conn)
+ assert len(self.reg) == 3
+ self.reg.close(self.conns[0])
+ assert len(self.reg) == 2
+ assert self.conns[0].closed == 1
+ assert self.conns[1].closed == 0
+ assert self.conns[2].closed == 0
+ self.reg.close(self.conns[2])
+ assert len(self.reg) == 1
+ assert self.conns[0].closed == 1
+ assert self.conns[1].closed == 0
+ assert self.conns[2].closed == 1
+ self.reg.close(self.conns[1])
+ assert len(self.reg) == 0
+ assert self.conns[0].closed == 1
+ assert self.conns[1].closed == 1
+ assert self.conns[2].closed == 1
+
+ def testCloseForeignConnection(self):
+ # Should be able to close a connection that has not been registered
+ for conn in self.conns:
+ self.reg.register(conn)
+ assert len(self.reg) == 3
+ conn = self.Conn()
+ self.reg.close(conn)
+ assert len(self.reg) == 3
+ assert self.conns[0].closed == 0
+ assert self.conns[1].closed == 0
+ assert self.conns[2].closed == 0
+ assert conn.closed == 1
+
+ def testCloseAllConnections(self):
+ # Should be able to close all registered connections at once
+ for conn in self.conns:
+ self.reg.register(conn)
+ assert len(self.reg) == 3
+ self.reg.closeAll()
+ assert len(self.reg) == 0
+ assert self.conns[0].closed == 1
+ assert self.conns[1].closed == 1
+ assert self.conns[2].closed == 1
+
+ def testContains(self):
+ # Should be able to check if a connection is registered
+ for conn in self.conns:
+ self.reg.register(conn)
+ assert len(self.reg) == 3
+ assert self.reg.contains(self.conns[0])
+ assert self.reg.contains(self.conns[1])
+ assert self.reg.contains(self.conns[2])
+
+
+class TestRequestVariables(base.TestCase):
+ '''Makes sure the REQUEST contains required variables'''
+
+ def testRequestVariables(self):
+ request = self.app.REQUEST
+ self.failIfEqual(request.get('SERVER_NAME', ''), '')
+ self.failIfEqual(request.get('SERVER_PORT', ''), '')
+ self.failIfEqual(request.get('REQUEST_METHOD', ''), '')
+ self.failIfEqual(request.get('URL', ''), '')
+ self.failIfEqual(request.get('SERVER_URL', ''), '')
+ self.failIfEqual(request.get('URL0', ''), '')
+ self.failIfEqual(request.get('URL1', ''), '')
+ self.failIfEqual(request.get('BASE0', ''), '')
+ self.failIfEqual(request.get('BASE1', ''), '')
+ self.failIfEqual(request.get('BASE2', ''), '')
+
+
+def test_suite():
+ from unittest import TestSuite, makeSuite
+ suite = TestSuite()
+ suite.addTest(makeSuite(TestTestCase))
+ suite.addTest(makeSuite(TestSetUpRaises))
+ suite.addTest(makeSuite(TestTearDownRaises))
+ suite.addTest(makeSuite(TestConnectionRegistry))
+ suite.addTest(makeSuite(TestRequestVariables))
+ return suite
+
+if __name__ == '__main__':
+ framework()
+
Property changes on: Zope/trunk/lib/python/Testing/ZopeTestCase/testBaseTestCase.py
___________________________________________________________________
Name: svn:eol-style
+ native
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/testFunctional.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/testFunctional.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/testFunctional.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -2,7 +2,7 @@
# Example functional ZopeTestCase
#
-# $Id: testFunctional.py,v 1.5 2004/04/09 12:38:37 shh42 Exp $
+# $Id: testFunctional.py,v 1.7 2004/09/04 18:01:08 shh42 Exp $
import os, sys
if __name__ == '__main__':
@@ -13,11 +13,11 @@
ZopeTestCase.installProduct('PythonScripts')
-class TestZPublication(ZopeTestCase.Functional, ZopeTestCase.ZopeTestCase):
+class TestFunctional(ZopeTestCase.Functional, ZopeTestCase.ZopeTestCase):
def afterSetUp(self):
- self.folder_path = self.folder.absolute_url(1)
- self.basic_auth = '%s:secret' % ZopeTestCase.user_name
+ self.folder_path = '/%s' % self.folder.absolute_url(1)
+ self.basic_auth = '%s:%s' % (ZopeTestCase.user_name, ZopeTestCase.user_password)
self.folder.addDTMLMethod('index_html', file='foo')
@@ -30,41 +30,41 @@
file='''<dtml-call "manage_changeProperties(title=REQUEST.get('title'))">''')
def testPublishDocument(self):
- response = self.publish('/%s/index_html' % self.folder_path)
+ response = self.publish(self.folder_path+'/index_html')
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getBody(), 'foo')
def testPublishScript(self):
- response = self.publish('/%s/script' % self.folder_path)
+ response = self.publish(self.folder_path+'/script')
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getBody(), '1')
def testPublishScriptWithArgument(self):
- response = self.publish('/%s/script?a:int=2' % self.folder_path)
+ response = self.publish(self.folder_path+'/script?a:int=2')
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getBody(), '3')
def testServerError(self):
- response = self.publish('/%s/script?a=2' % self.folder_path)
+ response = self.publish(self.folder_path+'/script?a=2')
self.assertEqual(response.getStatus(), 500)
def testUnauthorized(self):
self.folder.index_html.manage_permission('View', ['Owner'])
- response = self.publish('/%s/index_html' % self.folder_path)
+ response = self.publish(self.folder_path+'/index_html')
self.assertEqual(response.getStatus(), 401)
def testBasicAuthentication(self):
self.folder.index_html.manage_permission('View', ['Owner'])
- response = self.publish('/%s/index_html'
- % self.folder_path, self.basic_auth)
+ response = self.publish(self.folder_path+'/index_html',
+ self.basic_auth)
self.assertEqual(response.getStatus(), 200)
self.assertEqual(response.getBody(), 'foo')
def testModifyObject(self):
from AccessControl.Permissions import manage_properties
self.setPermissions([manage_properties])
- response = self.publish('/%s/object/change_title?title=Foo'
- % self.folder_path, self.basic_auth)
+ response = self.publish(self.folder_path+'/object/change_title?title=Foo',
+ self.basic_auth)
self.assertEqual(response.getStatus(), 200)
self.assertEqual(self.folder.object.title_or_id(), 'Foo')
@@ -72,7 +72,7 @@
def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
- suite.addTest(makeSuite(TestZPublication))
+ suite.addTest(makeSuite(TestFunctional))
return suite
if __name__ == '__main__':
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/testPortalTestCase.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/testPortalTestCase.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/testPortalTestCase.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -1,7 +1,7 @@
#
# Tests the PortalTestCase
#
-# NOTE: This is *not* an example PortalTestCase. Do not
+# NOTE: This is *not* an example TestCase. Do not
# use this file as a blueprint for your own tests!
#
# See testPythonScript.py and testShoppingCart.py for
@@ -9,18 +9,18 @@
# way of getting started.
#
-# $Id: testPortalTestCase.py,v 1.21 2004/04/09 12:38:37 shh42 Exp $
+# $Id: testPortalTestCase.py,v 1.24 2004/09/09 18:48:59 shh42 Exp $
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
-import transaction
from Testing import ZopeTestCase
from Acquisition import aq_base
from AccessControl import getSecurityManager
from types import ListType
+from transaction import begin
portal_name = 'dummy_1_'
user_name = ZopeTestCase.user_name
@@ -30,7 +30,8 @@
return hasattr(aq_base(ob), attr)
-# Dummy portal
+# Dummy Portal
+
from OFS.SimpleItem import SimpleItem
from OFS.Folder import Folder
@@ -56,7 +57,7 @@
class TestPortalTestCase(ZopeTestCase.PortalTestCase):
- '''Tests the PortalTestCase.'''
+ '''Incrementally exercise the PortalTestCase API.'''
_setUp = ZopeTestCase.PortalTestCase.setUp
_tearDown = ZopeTestCase.PortalTestCase.tearDown
@@ -70,7 +71,7 @@
# with an empty fixture.
self._called = []
# Implicitly aborts previous transaction
- transaction.begin()
+ begin()
def beforeSetUp(self):
self._called.append('beforeSetUp')
@@ -87,7 +88,7 @@
def afterClear(self):
self._called.append('afterClear')
- def test_01_getPortal(self):
+ def test_getPortal(self):
# Portal should be set up
self.app = self._app()
self.portal = self.getPortal()
@@ -96,7 +97,7 @@
self.failUnless(hasattr_(self.portal, 'portal_membership'))
self.failUnless('Member' in self.portal.userdefined_roles())
- def test_02_setupUserFolder(self):
+ def test_setupUserFolder(self):
# User folder should be set up.
self.app = self._app()
self.portal = self.getPortal()
@@ -106,7 +107,7 @@
# Must not complain if UF already exists
self._setupUserFolder()
- def test_03_setupUser(self):
+ def test_setupUser(self):
# User should be set up
self.app = self._app()
self.portal = self.getPortal()
@@ -117,7 +118,7 @@
self.assertEqual(acl_user.getRoles(), ('Member', 'Authenticated'))
self.assertEqual(type(acl_user.roles), ListType)
- def test_04_setupHomeFolder(self):
+ def test_setupHomeFolder(self):
# User's home folder should be set up
self.app = self._app()
self.portal = self.getPortal()
@@ -133,7 +134,7 @@
owner_info = self.folder.getOwner(info=1)
self.assertEqual(owner_info, ([portal_name, 'acl_users'], user_name))
- def test_05_refreshSkinData(self):
+ def test_refreshSkinData(self):
# The _v_skindata attribute should be refreshed
self.app = self._app()
self.portal = self.getPortal()
@@ -141,22 +142,18 @@
self._refreshSkinData()
self.assertEqual(self.portal._v_skindata, 'refreshed')
- def test_06_setRoles(self):
+ def test_setRoles(self):
# Roles should be set for user
self.app = self._app()
self.portal = self.getPortal()
self._setupUserFolder()
self._setupUser()
test_roles = ['Manager', 'Member']
- test_roles.sort()
self.setRoles(test_roles)
acl_user = self.portal.acl_users.getUserById(user_name)
- user_roles = list(acl_user.getRoles())
- user_roles.remove('Authenticated')
- user_roles.sort()
- self.assertEqual(user_roles, test_roles)
+ self.assertRolesOfUser(test_roles, acl_user)
- def test_07_setRoles_2(self):
+ def test_setRoles_2(self):
# Roles should be set for logged in user
self.app = self._app()
self.portal = self.getPortal()
@@ -164,30 +161,43 @@
self._setupUser()
self.login()
test_roles = ['Manager', 'Member']
- test_roles.sort()
self.setRoles(test_roles)
auth_user = getSecurityManager().getUser()
- user_roles = list(auth_user.getRoles())
- user_roles.remove('Authenticated')
- user_roles.sort()
- self.assertEqual(user_roles, test_roles)
+ self.assertRolesOfUser(test_roles, auth_user)
- def test_08_setRoles_3(self):
+ def test_setRoles_3(self):
# Roles should be set for a specified user
self.app = self._app()
self.portal = self.getPortal()
self._setupUserFolder()
- self.portal.acl_users._doAddUser('test_user_2_', 'secret', [], [])
+ self.portal.acl_users.userFolderAddUser('user_2', 'secret', [], [])
test_roles = ['Manager', 'Member']
- test_roles.sort()
- self.setRoles(test_roles, 'test_user_2_')
- acl_user = self.portal.acl_users.getUserById('test_user_2_')
- user_roles = list(acl_user.getRoles())
- user_roles.remove('Authenticated')
- user_roles.sort()
- self.assertEqual(user_roles, test_roles)
+ self.setRoles(test_roles, 'user_2')
+ acl_user = self.portal.acl_users.getUserById('user_2')
+ self.assertRolesOfUser(test_roles, acl_user)
- def test_09_setPermissions(self):
+ def test_setRolesAssertsArgumentType(self):
+ # setRoles should fail if 'roles' argument is not a list
+ self.assertRaises(self.failureException, self.setRoles, 'foo')
+ self.assertRaises(self.failureException, self.setRoles, ('foo',))
+
+ def test_getRoles(self):
+ # Should return roles of user
+ self.app = self._app()
+ self.portal = self.getPortal()
+ self._setupUserFolder()
+ self._setupUser()
+ self.assertEqual(self.getRoles(), ('Member', 'Authenticated'))
+
+ def test_getRoles_2(self):
+ # Should return roles of specified user
+ self.app = self._app()
+ self.portal = self.getPortal()
+ self._setupUserFolder()
+ self.portal.acl_users.userFolderAddUser('user_2', 'secret', ['Manager'], [])
+ self.assertEqual(self.getRoles('user_2'), ('Manager', 'Authenticated'))
+
+ def test_setPermissions(self):
# Permissions should be set for user
self.app = self._app()
self.portal = self.getPortal()
@@ -195,17 +205,39 @@
self.setPermissions(test_perms)
self.assertPermissionsOfRole(test_perms, 'Member')
- def test_10_setPermissions_2(self):
- # Permissions should be set for a specified role
+ def test_setPermissions_2(self):
+ # Permissions should be set for specified role
self.app = self._app()
self.portal = self.getPortal()
- self.portal._addRole('test_role_2_')
+ self.portal._addRole('role_2')
test_perms = ['Add Folders']
- self.assertPermissionsOfRole([], 'test_role_2_')
- self.setPermissions(test_perms, 'test_role_2_')
- self.assertPermissionsOfRole(test_perms, 'test_role_2_')
+ self.assertPermissionsOfRole([], 'role_2')
+ self.setPermissions(test_perms, 'role_2')
+ self.assertPermissionsOfRole(test_perms, 'role_2')
- def test_11_login(self):
+ def test_setPermissionsAssertsArgumentType(self):
+ # setPermissions should fail if 'permissions' argument is not a list
+ self.assertRaises(self.failureException, self.setPermissions, 'foo')
+ self.assertRaises(self.failureException, self.setPermissions, ('foo',))
+
+ def test_getPermissions(self):
+ # Should return permissions of user
+ self.app = self._app()
+ self.portal = self.getPortal()
+ test_perms = ['Add Folders']
+ self.setPermissions(test_perms)
+ self.assertEqual(self.getPermissions(), test_perms)
+
+ def test_getPermissions_2(self):
+ # Should return permissions of specified role
+ self.app = self._app()
+ self.portal = self.getPortal()
+ test_perms = ['Add Folders']
+ self.portal._addRole('role_2')
+ self.setPermissions(test_perms, 'role_2')
+ self.assertEqual(self.getPermissions('role_2'), test_perms)
+
+ def test_login(self):
# User should be able to log in
self.app = self._app()
self.portal = self.getPortal()
@@ -217,26 +249,26 @@
auth_name = getSecurityManager().getUser().getId()
self.assertEqual(auth_name, user_name)
- def test_12_login_2(self):
+ def test_login_2(self):
# A specified user should be logged in
self.app = self._app()
self.portal = self.getPortal()
self._setupUserFolder()
- self.portal.acl_users._doAddUser('test_user_2_', 'secret', [], [])
+ self.portal.acl_users.userFolderAddUser('user_2', 'secret', [], [])
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
- self.login('test_user_2_')
+ self.login('user_2')
auth_name = getSecurityManager().getUser().getId()
- self.assertEqual(auth_name, 'test_user_2_')
+ self.assertEqual(auth_name, 'user_2')
- def test_13_login_3(self):
+ def test_login_3(self):
# Unknown user should raise AttributeError
self.app = self._app()
self.portal = self.getPortal()
self._setupUserFolder()
- self.assertRaises(AttributeError, self.login, 'test_user_3_')
+ self.assertRaises(AttributeError, self.login, 'user_3')
- def test_14_logout(self):
+ def test_logout(self):
# User should be able to log out
self.app = self._app()
self.portal = self.getPortal()
@@ -247,7 +279,7 @@
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
- def test_15_clear(self):
+ def test_clear(self):
# Everything should be removed
self.app = self._app()
self.portal = self.getPortal()
@@ -255,16 +287,14 @@
self._setupUser()
self._setupHomeFolder()
self._clear(1)
- # XXX: No more cleanups in _clear()
- #self.failIf(self.portal.acl_users.getUserById(user_name))
- #self.failIf(hasattr_(self.portal.Members, user_name))
+ self.failIf(self.app.__dict__.has_key(portal_name))
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
self.assertEqual(self._called, ['beforeClose', 'afterClear'])
# clear must not fail when called repeatedly
self._clear()
- def test_16_setUp(self):
+ def test_setUp(self):
# Everything should be set up
self._setUp()
self.failUnless(hasattr_(self.app, portal_name))
@@ -284,19 +314,17 @@
self.assertEqual(self._called, ['beforeSetUp', 'afterSetUp'])
self.assertEqual(self.portal._v_skindata, 'refreshed')
- def test_17_tearDown(self):
+ def test_tearDown(self):
# Everything should be removed
self._setUp()
self._called = []
self._tearDown()
- # XXX: No more cleanups in _clear()
- #self.failIf(hasattr_(self.portal.Members, user_name))
- #self.assertEqual(self.portal.acl_users.getUserById(user_name), None)
+ self.failIf(self.app.__dict__.has_key(portal_name))
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
self.assertEqual(self._called, ['beforeTearDown', 'beforeClose', 'afterClear'])
- def test_18_configureFlag(self):
+ def test_configureFlag(self):
# Nothing should be configured
self._configure_portal = 0
self._setUp()
@@ -309,41 +337,78 @@
self.assertEqual(self._called, ['beforeSetUp', 'afterSetUp'])
self.assertEqual(self.portal._v_skindata, 'refreshed')
- def test_19_configureFlag_2(self):
- # Nothing should be cleared
- self._setUp()
- self._configure_portal = 0
- self._called = []
- self._clear()
- # XXX: Since 0.8.4 we abort before closing the connection
- #self.failUnless(hasattr_(self.portal.Members, user_name))
- #self.failUnless(self.portal.acl_users.getUserById(user_name))
- auth_name = getSecurityManager().getUser().getUserName()
- self.assertEqual(auth_name, 'Anonymous User')
- self.assertEqual(self._called, ['afterClear'])
+ # This is crazy
+ def __test_crazyRoles_0(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ perms = self.getPermissionsOfRole('Anonymous', self.app)
+ for perm in ['Access contents information', 'View', 'Query Vocabulary', 'Search ZCatalog']:
+ if perm not in perms:
+ self.fail('Expected permission "%s"' % perm)
+
+ def __test_crazyRoles_1(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ self.app.manage_role('Anonymous', ['View'])
+ self.assertPermissionsOfRole(['View'], 'Anonymous', self.app)
+ self.failIf(getSecurityManager().checkPermission('Access contents information', self.app))
+
+ def __test_crazyRoles_2(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ try:
+ self.assertPermissionsOfRole(['View'], 'Anonymous', self.app)
+ except self.failureException:
+ pass
+
+ def __test_crazyRoles_3(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ self.failUnless(getSecurityManager().checkPermission('Access contents information', self.app))
+
+ def __test_crazyRoles_4(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ perms = self.getPermissionsOfRole('Anonymous', self.app)
+ for perm in ['Access contents information', 'View', 'Query Vocabulary', 'Search ZCatalog']:
+ if perm not in perms:
+ self.fail('Expected permission "%s"' % perm)
+
# Helpers
def getPermissionsOfRole(self, role, context=None):
'''Returns sorted list of permission names of the
given role in the given context.
'''
- if context is None: context = self.portal
+ if context is None:
+ context = self.portal
perms = context.permissionsOfRole(role)
- perms = [p['name'] for p in perms if p['selected']]
- perms.sort()
- return perms
+ return [p['name'] for p in perms if p['selected']]
def assertPermissionsOfRole(self, permissions, role, context=None):
'''Compares list of permission names to permissions of the
given role in the given context. Fails if the lists are not
found equal.
'''
- perms = list(permissions)[:]
- perms.sort()
- self.assertEqual(self.getPermissionsOfRole(role, context), perms)
+ lhs = list(permissions)[:]
+ lhs.sort()
+ rhs = self.getPermissionsOfRole(role, context)
+ rhs.sort()
+ self.assertEqual(lhs, rhs)
+ def assertRolesOfUser(self, roles, user):
+ '''Compares list of role names to roles of user. Fails if the
+ lists are not found equal.
+ '''
+ lhs = list(roles)[:]
+ lhs.sort()
+ rhs = list(user.getRoles())[:]
+ rhs.remove('Authenticated')
+ rhs.sort()
+ self.assertEqual(lhs, rhs)
+
from AccessControl.User import UserFolder
class WrappingUserFolder(UserFolder):
@@ -385,7 +450,7 @@
self.portal._setObject('acl_users', WrappingUserFolder())
def testGetUserWrapsUser(self):
- user = self.folder.acl_users.getUserById(user_name)
+ user = self.portal.acl_users.getUserById(user_name)
self.failUnless(hasattr(user, 'aq_base'))
self.failIf(user is aq_base(user))
self.failUnless(user.aq_parent.__class__.__name__, 'WrappingUserFolder')
@@ -399,12 +464,62 @@
self.failUnless(user.aq_parent.aq_parent.__class__.__name__, 'Folder')
+# Because we override setUp we need to test again
+
+class HookTest(ZopeTestCase.PortalTestCase):
+
+ def setUp(self):
+ self._called = []
+ ZopeTestCase.PortalTestCase.setUp(self)
+
+ def beforeSetUp(self):
+ self._called.append('beforeSetUp')
+ ZopeTestCase.PortalTestCase.beforeSetUp(self)
+
+ def _setup(self):
+ self._called.append('_setup')
+ ZopeTestCase.PortalTestCase._setup(self)
+
+ def afterClear(self):
+ self._called.append('afterClear')
+ ZopeTestCase.PortalTestCase.afterClear(self)
+
+ def assertHooks(self, sequence):
+ self.assertEqual(self._called, sequence)
+
+
+class TestSetUpRaises(HookTest):
+
+ def getPortal(self):
+ self.app._setObject(portal_name, DummyPortal(portal_name))
+ return self.app[portal_name]
+
+ class Error: pass
+
+ def setUp(self):
+ try:
+ HookTest.setUp(self)
+ except self.Error:
+ self.assertHooks(['beforeSetUp', '_setup', 'afterClear'])
+ # Connection has been closed
+ from Testing.ZopeTestCase import base
+ self.assertEqual(len(base._connections), 0)
+
+ def _setup(self):
+ HookTest._setup(self)
+ raise self.Error
+
+ def testTrigger(self):
+ pass
+
+
def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
suite.addTest(makeSuite(TestPortalTestCase))
suite.addTest(makeSuite(TestPlainUserFolder))
suite.addTest(makeSuite(TestWrappingUserFolder))
+ suite.addTest(makeSuite(TestSetUpRaises))
return suite
if __name__ == '__main__':
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/testWebserver.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/testWebserver.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/testWebserver.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -16,7 +16,7 @@
# example instead.
#
-# $Id: testWebserver.py,v 1.14 2004/04/09 12:38:37 shh42 Exp $
+# $Id: testWebserver.py,v 1.15 2004/09/04 18:01:08 shh42 Exp $
import os, sys
if __name__ == '__main__':
@@ -53,7 +53,7 @@
def afterSetUp(self):
uf = self.folder.acl_users
- uf._doAddUser('manager', 'secret', ['Manager'], [])
+ uf.userFolderAddUser('manager', 'secret', ['Manager'], [])
manager = uf.getUserById('manager').__of__(uf)
self.folder.addDTMLMethod('index_html', file='index_html called')
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/testZopeTestCase.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/testZopeTestCase.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/testZopeTestCase.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -1,7 +1,7 @@
#
# Tests the ZopeTestCase, eating its own dogfood
#
-# NOTE: This is *not* an example ZopeTestCase. Do not
+# NOTE: This is *not* an example TestCase. Do not
# use this file as a blueprint for your own tests!
#
# See testPythonScript.py and testShoppingCart.py for
@@ -9,18 +9,18 @@
# way of getting started.
#
-# $Id: testZopeTestCase.py,v 1.17 2004/04/09 12:38:37 shh42 Exp $
+# $Id: testZopeTestCase.py,v 1.21 2004/09/04 18:01:08 shh42 Exp $
import os, sys
if __name__ == '__main__':
execfile(os.path.join(sys.path[0], 'framework.py'))
-import transaction
from Testing import ZopeTestCase
from Acquisition import aq_base
from AccessControl import getSecurityManager
from types import ListType
+from transaction import begin
folder_name = ZopeTestCase.folder_name
user_name = ZopeTestCase.user_name
@@ -33,9 +33,7 @@
class TestZopeTestCase(ZopeTestCase.ZopeTestCase):
- '''Incrementally exercise the ZopeTestCase API.
- Exploit the fact that tests are sorted by name.
- '''
+ '''Incrementally exercise the ZopeTestCase API.'''
_setUp = ZopeTestCase.ZopeTestCase.setUp
_tearDown = ZopeTestCase.ZopeTestCase.tearDown
@@ -45,7 +43,7 @@
# with an empty fixture.
self._called = []
# Implicitly aborts previous transaction
- transaction.begin()
+ begin()
def beforeSetUp(self):
self._called.append('beforeSetUp')
@@ -62,23 +60,23 @@
def afterClear(self):
self._called.append('afterClear')
- def test_01_setupFolder(self):
+ def test_setupFolder(self):
# Folder should be set up
self.app = self._app()
self._setupFolder()
self.failUnless(hasattr_(self.app, folder_name))
- self.failUnless(hasattr(self, 'folder'))
+ self.failUnless(hasattr_(self, 'folder'))
self.failUnless(user_role in self.folder.userdefined_roles())
self.assertPermissionsOfRole(standard_permissions, user_role)
- def test_02_setupUserFolder(self):
+ def test_setupUserFolder(self):
# User folder should be set up
self.app = self._app()
self._setupFolder()
self._setupUserFolder()
self.failUnless(hasattr_(self.folder, 'acl_users'))
- def test_03_setupUser(self):
+ def test_setupUser(self):
# User should be set up
self.app = self._app()
self._setupFolder()
@@ -89,22 +87,18 @@
self.assertEqual(acl_user.getRoles(), (user_role, 'Authenticated'))
self.assertEqual(type(acl_user.roles), ListType)
- def test_04_setRoles(self):
+ def test_setRoles(self):
# Roles should be set for user
self.app = self._app()
self._setupFolder()
self._setupUserFolder()
self._setupUser()
test_roles = ['Manager', user_role]
- test_roles.sort()
self.setRoles(test_roles)
acl_user = self.folder.acl_users.getUserById(user_name)
- user_roles = list(acl_user.getRoles())
- user_roles.remove('Authenticated')
- user_roles.sort()
- self.assertEqual(user_roles, test_roles)
+ self.assertRolesOfUser(test_roles, acl_user)
- def test_05_setRoles_2(self):
+ def test_setRoles_2(self):
# Roles of logged in user should be updated
self.app = self._app()
self._setupFolder()
@@ -112,48 +106,81 @@
self._setupUser()
self.login()
test_roles = ['Manager', user_role]
- test_roles.sort()
self.setRoles(test_roles)
auth_user = getSecurityManager().getUser()
- user_roles = list(auth_user.getRoles())
- user_roles.remove('Authenticated')
- user_roles.sort()
- self.assertEqual(user_roles, test_roles)
+ self.assertRolesOfUser(test_roles, auth_user)
- def test_06_setRoles_3(self):
+ def test_setRoles_3(self):
# Roles should be set for a specified user
self.app = self._app()
self._setupFolder()
self._setupUserFolder()
- self.folder.acl_users._doAddUser('test_user_2_', 'secret', [], [])
+ self.folder.acl_users.userFolderAddUser('user_2', 'secret', [], [])
test_roles = ['Manager', user_role]
- test_roles.sort()
- self.setRoles(test_roles, 'test_user_2_')
- acl_user = self.folder.acl_users.getUserById('test_user_2_')
- user_roles = list(acl_user.getRoles())
- user_roles.remove('Authenticated')
- user_roles.sort()
- self.assertEqual(user_roles, test_roles)
+ self.setRoles(test_roles, 'user_2')
+ acl_user = self.folder.acl_users.getUserById('user_2')
+ self.assertRolesOfUser(test_roles, acl_user)
- def test_07_setPermissions(self):
+ def test_setRolesAssertsArgumentType(self):
+ # setRoles should fail if 'roles' argument is not a list
+ self.assertRaises(self.failureException, self.setRoles, 'foo')
+ self.assertRaises(self.failureException, self.setRoles, ('foo',))
+
+ def test_getRoles(self):
+ # Should return roles of user
+ self.app = self._app()
+ self._setupFolder()
+ self._setupUserFolder()
+ self._setupUser()
+ self.assertEqual(self.getRoles(), (user_role, 'Authenticated'))
+
+ def test_getRoles_2(self):
+ # Should return roles of specified user
+ self.app = self._app()
+ self._setupFolder()
+ self._setupUserFolder()
+ self.folder.acl_users.userFolderAddUser('user_2', 'secret', ['Manager'], [])
+ self.assertEqual(self.getRoles('user_2'), ('Manager', 'Authenticated'))
+
+ def test_setPermissions(self):
# Permissions should be set for user
self.app = self._app()
self._setupFolder()
- test_perms = standard_permissions + ['Add Folders']
+ test_perms = ['Add Folders']
self.assertPermissionsOfRole(standard_permissions, user_role)
self.setPermissions(test_perms)
self.assertPermissionsOfRole(test_perms, user_role)
- def test_08_setPermissions_2(self):
- # Permissions should be set for a specified role
+ def test_setPermissions_2(self):
+ # Permissions should be set for specified role
self.app = self._app()
self._setupFolder()
- self.folder._addRole('test_role_2_')
- self.assertPermissionsOfRole([], 'test_role_2_')
- self.setPermissions(standard_permissions, 'test_role_2_')
- self.assertPermissionsOfRole(standard_permissions, 'test_role_2_')
+ self.folder._addRole('role_2')
+ self.assertPermissionsOfRole([], 'role_2')
+ self.setPermissions(standard_permissions, 'role_2')
+ self.assertPermissionsOfRole(standard_permissions, 'role_2')
- def test_09_login(self):
+ def test_setPermissionsAssertsArgumentType(self):
+ # setPermissions should fail if 'permissions' argument is not a list
+ self.assertRaises(self.failureException, self.setPermissions, 'foo')
+ self.assertRaises(self.failureException, self.setPermissions, ('foo',))
+
+ def test_getPermissions(self):
+ # Should return permissions of user
+ self.app = self._app()
+ self._setupFolder()
+ self.assertEqual(self.getPermissions(), standard_permissions)
+
+ def test_getPermissions_2(self):
+ # Should return permissions of specified role
+ self.app = self._app()
+ self._setupFolder()
+ test_perms = ['Add Folders']
+ self.folder._addRole('role_2')
+ self.setPermissions(test_perms, 'role_2')
+ self.assertEqual(self.getPermissions('role_2'), test_perms)
+
+ def test_login(self):
# User should be able to log in
self.app = self._app()
self._setupFolder()
@@ -165,26 +192,26 @@
auth_name = getSecurityManager().getUser().getId()
self.assertEqual(auth_name, user_name)
- def test_10_login_2(self):
+ def test_login_2(self):
# A specified user should be logged in
self.app = self._app()
self._setupFolder()
self._setupUserFolder()
- self.folder.acl_users._doAddUser('test_user_2_', 'secret', [], [])
+ self.folder.acl_users.userFolderAddUser('user_2', 'secret', [], [])
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
- self.login('test_user_2_')
+ self.login('user_2')
auth_name = getSecurityManager().getUser().getId()
- self.assertEqual(auth_name, 'test_user_2_')
+ self.assertEqual(auth_name, 'user_2')
- def test_11_login_3(self):
+ def test_login_3(self):
# Unknown user should raise AttributeError
self.app = self._app()
self._setupFolder()
self._setupUserFolder()
- self.assertRaises(AttributeError, self.login, 'test_user_3_')
+ self.assertRaises(AttributeError, self.login, 'user_3')
- def test_12_logout(self):
+ def test_logout(self):
# User should be able to log out
self.app = self._app()
self._setupFolder()
@@ -195,25 +222,26 @@
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
- def test_13_clear(self):
+ def test_clear(self):
# Everything should be removed
self.app = self._app()
self._setupFolder()
self._setupUserFolder()
self._setupUser()
+ self.login()
self._clear(1)
- self.failIf(hasattr_(self.app, folder_name))
+ self.failIf(self.app.__dict__.has_key(folder_name))
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
self.assertEqual(self._called, ['beforeClose', 'afterClear'])
# _clear must not fail when called repeatedly
self._clear()
- def test_14_setUp(self):
+ def test_setUp(self):
# Everything should be set up
self._setUp()
self.failUnless(hasattr_(self.app, folder_name))
- self.failUnless(hasattr(self, 'folder'))
+ self.failUnless(hasattr_(self, 'folder'))
self.failUnless(user_role in self.folder.userdefined_roles())
self.assertPermissionsOfRole(standard_permissions, user_role)
self.failUnless(hasattr_(self.folder, 'acl_users'))
@@ -227,17 +255,17 @@
#self.assertEqual(self._called, ['afterClear', 'beforeSetUp', 'afterSetUp'])
self.assertEqual(self._called, ['beforeSetUp', 'afterSetUp'])
- def test_15_tearDown(self):
+ def test_tearDown(self):
# Everything should be removed
self._setUp()
self._called = []
self._tearDown()
- self.failIf(hasattr_(self.app, folder_name))
+ self.failIf(self.app.__dict__.has_key(folder_name))
auth_name = getSecurityManager().getUser().getUserName()
self.assertEqual(auth_name, 'Anonymous User')
self.assertEqual(self._called, ['beforeTearDown', 'beforeClose', 'afterClear'])
- def test_16_setupFlag(self):
+ def test_setupFlag(self):
# Nothing should be set up
self._setup_fixture = 0
self._setUp()
@@ -248,21 +276,9 @@
#self.assertEqual(self._called, ['afterClear', 'beforeSetUp', 'afterSetUp'])
self.assertEqual(self._called, ['beforeSetUp', 'afterSetUp'])
- def test_17_setupFlag_2(self):
- # Nothing should be cleared
- self._setUp()
- self._setup_fixture = 0
- self._called = []
- self._clear()
- # XXX: Since 0.8.4 we abort before closing the connection
- #self.failUnless(hasattr_(self.app, folder_name))
- auth_name = getSecurityManager().getUser().getUserName()
- self.assertEqual(auth_name, 'Anonymous User')
- self.assertEqual(self._called, ['afterClear'])
-
# Bug tests
- def test_18_setOwnerPermissions(self):
+ def test_setOwnerPermissions(self):
# Permissions should be modified for the Owner role
self.app = self._app()
self._setupFolder()
@@ -270,7 +286,7 @@
self.setPermissions(standard_permissions, 'Owner')
self.assertPermissionsOfRole(standard_permissions, 'Owner')
- def test_19_setManagerPermissions(self):
+ def test_setManagerPermissions(self):
# Permissions should *not* be modified for the Manager role
self.app = self._app()
self._setupFolder()
@@ -280,7 +296,7 @@
# Manager does still have all permissions
self.assertPermissionsOfRole(manager_perms, 'Manager')
- def test_20_setManagerPermissions_2(self):
+ def test_setManagerPermissions_2(self):
# Permissions should be modified for the Manager role
self.app = self._app()
self._setupFolder()
@@ -292,105 +308,78 @@
manager_perms.remove('Take ownership')
self.assertPermissionsOfRole(manager_perms, 'Manager')
+ # This is crazy
+
+ def __test_crazyRoles_0(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ perms = self.getPermissionsOfRole('Anonymous', self.app)
+ for perm in ['Access contents information', 'View', 'Query Vocabulary', 'Search ZCatalog']:
+ if perm not in perms:
+ self.fail('Expected permission "%s"' % perm)
+
+ def __test_crazyRoles_1(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ self.app.manage_role('Anonymous', ['View'])
+ self.assertPermissionsOfRole(['View'], 'Anonymous', self.app)
+ self.failIf(getSecurityManager().checkPermission('Access contents information', self.app))
+
+ def __test_crazyRoles_2(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ try:
+ self.assertPermissionsOfRole(['View'], 'Anonymous', self.app)
+ except self.failureException:
+ pass
+
+ def __test_crazyRoles_3(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ self.failUnless(getSecurityManager().checkPermission('Access contents information', self.app))
+
+ def __test_crazyRoles_4(self):
+ # Permission assignments should be reset
+ self.app = self._app()
+ perms = self.getPermissionsOfRole('Anonymous', self.app)
+ for perm in ['Access contents information', 'View', 'Query Vocabulary', 'Search ZCatalog']:
+ if perm not in perms:
+ self.fail('Expected permission "%s"' % perm)
+
# Helpers
def getPermissionsOfRole(self, role, context=None):
'''Returns sorted list of permission names of the
given role in the given context.
'''
- if context is None: context = self.folder
+ if context is None:
+ context = self.folder
perms = context.permissionsOfRole(role)
- perms = [p['name'] for p in perms if p['selected']]
- perms.sort()
- return perms
+ return [p['name'] for p in perms if p['selected']]
def assertPermissionsOfRole(self, permissions, role, context=None):
'''Compares list of permission names to permissions of the
given role in the given context. Fails if the lists are not
found equal.
'''
- perms = list(permissions)[:]
- perms.sort()
- self.assertEqual(self.getPermissionsOfRole(role, context), perms)
+ lhs = list(permissions)[:]
+ lhs.sort()
+ rhs = self.getPermissionsOfRole(role, context)
+ rhs.sort()
+ self.assertEqual(lhs, rhs)
+ def assertRolesOfUser(self, roles, user):
+ '''Compares list of role names to roles of user. Fails if the
+ lists are not found equal.
+ '''
+ lhs = list(roles)[:]
+ lhs.sort()
+ rhs = list(user.getRoles())[:]
+ rhs.remove('Authenticated')
+ rhs.sort()
+ self.assertEqual(lhs, rhs)
-import unittest
-class TestConnectionRegistry(unittest.TestCase):
- '''Tests the ZODB connection registry'''
-
- class Conn:
- closed = 0
- def close(self):
- self.closed = 1
-
- def setUp(self):
- self.reg = ZopeTestCase.utils.ConnectionRegistry()
- self.conns = [self.Conn(), self.Conn(), self.Conn()]
-
- def testRegister(self):
- # Should be able to register connections
- for conn in self.conns:
- self.reg.register(conn)
- assert len(self.reg) == 3
-
- def testCloseConnection(self):
- # Should be able to close a single registered connection
- for conn in self.conns:
- self.reg.register(conn)
- assert len(self.reg) == 3
- self.reg.close(self.conns[0])
- assert len(self.reg) == 2
- assert self.conns[0].closed == 1
- assert self.conns[1].closed == 0
- assert self.conns[2].closed == 0
-
- def testCloseSeveralConnections(self):
- # Should be able to close all registered connections one-by-one
- for conn in self.conns:
- self.reg.register(conn)
- assert len(self.reg) == 3
- self.reg.close(self.conns[0])
- assert len(self.reg) == 2
- assert self.conns[0].closed == 1
- assert self.conns[1].closed == 0
- assert self.conns[2].closed == 0
- self.reg.close(self.conns[2])
- assert len(self.reg) == 1
- assert self.conns[0].closed == 1
- assert self.conns[1].closed == 0
- assert self.conns[2].closed == 1
- self.reg.close(self.conns[1])
- assert len(self.reg) == 0
- assert self.conns[0].closed == 1
- assert self.conns[1].closed == 1
- assert self.conns[2].closed == 1
-
- def testCloseForeignConnection(self):
- # Should be able to close a connection that has not been registered
- for conn in self.conns:
- self.reg.register(conn)
- assert len(self.reg) == 3
- conn = self.Conn()
- self.reg.close(conn)
- assert len(self.reg) == 3
- assert self.conns[0].closed == 0
- assert self.conns[1].closed == 0
- assert self.conns[2].closed == 0
- assert conn.closed == 1
-
- def testCloseAllConnections(self):
- # Should be able to close all registered connections at once
- for conn in self.conns:
- self.reg.register(conn)
- assert len(self.reg) == 3
- self.reg.closeAll()
- assert len(self.reg) == 0
- assert self.conns[0].closed == 1
- assert self.conns[1].closed == 1
- assert self.conns[2].closed == 1
-
-
from AccessControl.User import UserFolder
from Acquisition import aq_inner, aq_parent, aq_chain
@@ -439,31 +428,12 @@
self.failUnless(user.aq_parent.aq_parent.__class__.__name__, 'Folder')
-class TestRequestVariables(ZopeTestCase.ZopeTestCase):
- '''Makes sure the REQUEST contains required variables'''
-
- def testRequestVariables(self):
- request = self.app.REQUEST
- self.failIfEqual(request.get('SERVER_NAME', ''), '')
- self.failIfEqual(request.get('SERVER_PORT', ''), '')
- self.failIfEqual(request.get('REQUEST_METHOD', ''), '')
- self.failIfEqual(request.get('URL', ''), '')
- self.failIfEqual(request.get('SERVER_URL', ''), '')
- self.failIfEqual(request.get('URL0', ''), '')
- self.failIfEqual(request.get('URL1', ''), '')
- self.failIfEqual(request.get('BASE0', ''), '')
- self.failIfEqual(request.get('BASE1', ''), '')
- self.failIfEqual(request.get('BASE2', ''), '')
-
-
def test_suite():
from unittest import TestSuite, makeSuite
suite = TestSuite()
suite.addTest(makeSuite(TestZopeTestCase))
- suite.addTest(makeSuite(TestConnectionRegistry))
suite.addTest(makeSuite(TestPlainUserFolder))
suite.addTest(makeSuite(TestWrappingUserFolder))
- suite.addTest(makeSuite(TestRequestVariables))
return suite
if __name__ == '__main__':
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/threadutils.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -3,7 +3,7 @@
# be imported more selectively.
#
-# $Id: threadutils.py,v 1.5 2004/01/09 14:35:08 shh42 Exp $
+# $Id: threadutils.py,v 1.6 2004/08/19 15:31:26 shh42 Exp $
from threading import Thread
from StringIO import StringIO
@@ -41,6 +41,7 @@
from ZServer.PubCore.ZServerPublisher import ZServerPublisher
-ZServerPublisher.__old_init__ = ZServerPublisher.__init__
-ZServerPublisher.__init__ = QuietPublisher
+if not hasattr(ZServerPublisher, '__old_init__'):
+ ZServerPublisher.__old_init__ = ZServerPublisher.__init__
+ ZServerPublisher.__init__ = QuietPublisher
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/utils.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -5,7 +5,7 @@
# module level to add functionality to the test environment.
#
-# $Id: utils.py,v 1.13 2004/02/17 19:34:36 shh42 Exp $
+# $Id: utils.py,v 1.16 2004/08/19 13:59:41 shh42 Exp $
def setupCoreSessions(app=None):
@@ -105,6 +105,7 @@
t = QuietThread(target=zserverRunner, args=(_Z2HOST, _Z2PORT, log))
t.setDaemon(1)
t.start()
+ time.sleep(0.1) # Sandor Palfy
return _Z2HOST, _Z2PORT
@@ -127,13 +128,13 @@
def appcall(function, *args, **kw):
'''Calls a function passing 'app' as first argument.'''
- import ZopeTestCase
- app = ZopeTestCase.app()
+ from base import app, close
+ app = app()
args = (app,) + args
try:
return function(*args, **kw)
finally:
- ZopeTestCase.close(app)
+ close(app)
class ConnectionRegistry:
@@ -160,3 +161,6 @@
def __len__(self):
return len(self._conns)
+ def contains(self, conn):
+ return conn in self._conns
+
Modified: Zope/trunk/lib/python/Testing/ZopeTestCase/ztc_common.py
===================================================================
--- Zope/trunk/lib/python/Testing/ZopeTestCase/ztc_common.py 2004-10-01 08:27:32 UTC (rev 27729)
+++ Zope/trunk/lib/python/Testing/ZopeTestCase/ztc_common.py 2004-10-01 10:43:30 UTC (rev 27730)
@@ -7,7 +7,7 @@
# 'ZopeTestCase', 'ztc_common.py'))
#
-# $Id: ztc_common.py,v 1.13 2004/03/30 16:40:04 shh42 Exp $
+# $Id: ztc_common.py,v 1.14 2004/05/27 15:06:24 shh42 Exp $
# Overwrites the default framework() method to expose the
@@ -28,9 +28,9 @@
else:
sys.exit(globals()[arg]() and 1 or 0)
- errors = TestRunner(stream, descriptions, verbosity).run(test_suite())
+ result = TestRunner(stream, descriptions, verbosity).run(test_suite())
from Testing.ZopeTestCase import profiler; profiler.print_stats()
- sys.exit(errors and 1 or 0)
+ sys.exit(len(result.errors) + len(result.failures))
# Configures the Zope environment
More information about the Zope-Checkins
mailing list