Commit 0e66321c authored by Stefan H. Holek's avatar Stefan H. Holek

Spring cleaning! Improved docstrings, removed cruft, and added a ClassDiagram.pdf.

No functional changes.
parent 116b49f3
......@@ -114,7 +114,11 @@ class ZopeTestCase(base.TestCase):
class FunctionalTestCase(functional.Functional, ZopeTestCase):
'''Base class for functional Zope tests'''
'''Convenience base class for functional Zope tests
You can mix-in Functional with every xTestCase
to turn it into a functional test case.
'''
__implements__ = (functional.Functional.__implements__,
ZopeTestCase.__implements__)
......
......@@ -12,9 +12,9 @@
##############################################################################
"""Support for functional unit testing in ZTC
After Marius Gedminas' functional.py module for Zope 3.
After Marius Gedminas' functional.py module for Zope3.
$Id: functional.py,v 1.3 2004/09/12 16:49:59 shh42 Exp $
$Id$
"""
import sys, re, base64
......
......@@ -12,14 +12,10 @@
##############################################################################
"""ZopeTestCase interfaces
$Id: interfaces.py,v 1.5 2005/02/07 21:59:35 shh42 Exp $
$Id$
"""
try:
from Interface import Interface
except ImportError:
# Old interface package
from Interface import Base as Interface
from Interface import Interface
class IZopeTestCase(Interface):
......
......@@ -12,7 +12,10 @@
##############################################################################
"""Example functional ZopeTestCase
$Id: testFunctional.py,v 1.16 2005/02/12 13:13:04 shh42 Exp $
Demonstrates how to use the publish() API to execute GET, POST, PUT, etc.
requests against the ZPublisher and how to examine the response.
$Id$
"""
import os, sys
......
......@@ -343,44 +343,6 @@ class TestPortalTestCase(ZopeTestCase.PortalTestCase):
#self.assertEqual(self._called, ['afterClear', 'beforeSetUp', 'afterSetUp'])
self.assertEqual(self._called, ['beforeSetUp', 'afterSetUp'])
# 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):
......
......@@ -10,17 +10,19 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Example ZopeTestCase testing a PythonScript object in the default fixture
"""Example ZopeTestCase testing a PythonScript in the default fixture
Note that you are encouraged to call any of the following methods
from your own tests to modify the test user's security credentials:
This test module demonstrates the security API of ZopeTestCase.
- setRoles()
- setPermissions()
- login()
- logout()
Note that you are encouraged to call any of the following methods to
modify the test user's security credentials:
$Id: testPythonScript.py,v 1.9 2004/04/09 12:38:37 shh42 Exp $
setRoles()
setPermissions()
login()
logout()
$Id$
"""
import os, sys
......@@ -52,9 +54,9 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
self.ps = self.folder['ps']
self.ps.ZPythonScript_edit(ps_params1, ps_body1)
# Test the fixture ##############################################
# Test the setup
def testFixture(self):
def testSetup(self):
# The PythonScript should exist and be properly set up
self.failUnless(hasattr(self.folder, 'ps'))
self.assertEqual(self.ps.body(), ps_body1+'\n')
......@@ -62,7 +64,7 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
owner = self.ps.getOwner()
self.assertEqual(owner.getUserName(), ZopeTestCase.user_name)
# Test the scripts ##############################################
# Test the script(s)
def testCanCallScript1WithArgument(self):
# PythonScript should return 2
......@@ -78,18 +80,18 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
self.assertEqual(self.ps(1), 2)
def testCannotCallScript2WithoutArgument(self):
# PythonScript should raise a TypeError
# PythonScript should raise a TypeError if called without arguments
self.ps.ZPythonScript_edit(ps_params2, ps_body2)
self.assertRaises(TypeError, self.ps, ())
# Test access protection ########################################
# Test access protection with restrictedTraverse
def testCannotAccessWithoutAccessPermission(self):
# manage_main should be protected
self.assertRaises(Unauthorized, self.ps.restrictedTraverse, 'manage_main')
def testCanAccessWithAccessPermission(self):
# manage_main should be accessible
# manage_main should be accessible if we have the necessary permissions
self.setPermissions(access_permissions)
try:
self.ps.restrictedTraverse('manage_main')
......@@ -97,26 +99,26 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
self.fail('Access to manage_main was denied')
def testCannotAccessIfAnonymous(self):
# manage_main should be protected
# manage_main should be protected from Anonymous
self.logout()
self.assertRaises(Unauthorized, self.ps.restrictedTraverse, 'manage_main')
def testCanAccessIfManager(self):
# manage_main should be accessible to Managers
# manage_main should be accessible to Manager
self.setRoles(['Manager'])
try:
self.ps.restrictedTraverse('manage_main')
except Unauthorized:
self.fail('Access to manage_main was denied to Manager')
# Test access protection with SecurityManager ###################
# Test access protection with SecurityManager
def testCannotAccessWithoutAccessPermissionSecurityManager(self):
# manage_main should be protected
self.assertRaises(Unauthorized, getSecurityManager().validateValue, self.ps.manage_main)
def testCanAccessWithAccessPermissionSecurityManager(self):
# manage_main should be accessible
# manage_main should be accessible if we have the necessary permissions
self.setPermissions(access_permissions)
try:
getSecurityManager().validateValue(self.ps.manage_main)
......@@ -124,19 +126,19 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
self.fail('Access to manage_main was denied')
def testCannotAccessIfAnonymousSecurityManager(self):
# manage_main should be protected
# manage_main should be protected from Anonymous
self.logout()
self.assertRaises(Unauthorized, getSecurityManager().validateValue, self.ps.manage_main)
def testCanAccessIfManagerSecurityManager(self):
# manage_main should be accessible to Managers
# manage_main should be accessible to Manager
self.setRoles(['Manager'])
try:
getSecurityManager().validateValue(self.ps.manage_main)
except Unauthorized:
self.fail('Access to manage_main was denied to Manager')
# Test edit protection ##########################################
# Test edit protection with restrictedTraverse
def testCannotEditWithoutChangePermission(self):
# PythonScript should not be editable
......@@ -151,7 +153,7 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
'ZPythonScript_edit was protected but no exception was raised')
def testCanEditWithChangePermission(self):
# PythonScript should be editable
# PythonScript should be editable if we have the necessary permissions
self.setPermissions(change_permissions)
try:
self.ps.restrictedTraverse('ZPythonScript_edit')(ps_params2, ps_body2)
......@@ -162,7 +164,7 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
self.assertEqual(self.ps.params(), ps_params2)
def testCannotEditIfAnonymous(self):
# PythonScript should not be editable
# PythonScript should not be editable by Anonymous
self.logout()
try:
self.ps.restrictedTraverse('ZPythonScript_edit')(ps_params2, ps_body2)
......@@ -175,7 +177,7 @@ class TestPythonScript(ZopeTestCase.ZopeTestCase):
'ZPythonScript_edit was protected but no exception was raised')
def testCanEditIfManager(self):
# PythonScript should be editable for Managers
# PythonScript should be editable by Manager
self.setRoles(['Manager'])
try:
self.ps.restrictedTraverse('ZPythonScript_edit')(ps_params2, ps_body2)
......
......@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Example ZopeTestCase testing the ShoppingCart example application.
"""Example ZopeTestCase testing the ShoppingCart example application
Note the use of sessions and how the SESSION object is added to
the REQUEST in afterSetUp().
......@@ -18,7 +18,7 @@ the REQUEST in afterSetUp().
You can use zLOG.LOG() if you set up the event log variables first.
Handy for debugging and tracing your tests.
$Id: testShoppingCart.py,v 1.11 2005/02/23 17:14:56 shh42 Exp $
$Id$
"""
import os, sys
......
......@@ -12,11 +12,11 @@
##############################################################################
"""Tests ZODB behavior in ZopeTestCase
Demonstrates that cut/copy/paste/clone/rename and import/export
work in ZopeTestCase if a subtransaction is commited before performing
the respective operations.
Demonstrates that cut/copy/paste/clone/rename and import/export
work if a subtransaction is committed before performing the respective
operation.
$Id: testZODBCompat.py,v 1.17 2004/04/09 12:38:37 shh42 Exp $
$Id$
"""
import os, sys
......
......@@ -19,7 +19,7 @@ See testPythonScript.py and testShoppingCart.py for
example test cases. See testSkeleton.py for a quick
way of getting started.
$Id: testZopeTestCase.py,v 1.25 2005/01/30 14:22:48 shh42 Exp $
$Id$
"""
import os, sys
......@@ -319,44 +319,6 @@ class TestZopeTestCase(ZopeTestCase.ZopeTestCase):
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):
......
......@@ -12,11 +12,9 @@
##############################################################################
"""ZopeTestCase doctest support
$Id: __init__.py,v 1.2 2005/03/26 18:07:08 shh42 Exp $
$Id$
"""
__version__ = '0.9.7'
from zope.testing.doctest import *
from functional import *
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment