[Zope-Checkins] SVN: Zope/trunk/src/Testing/ZopeTestCase/ Reverted r90443 and r90454. We keep the shopping cart tests working by including a copy of Examples.zexp.
Stefan H. Holek
stefan at epy.co.at
Sat Mar 7 17:26:44 EST 2009
Log message for revision 97643:
Reverted r90443 and r90454. We keep the shopping cart tests working by including a copy of Examples.zexp.
Changed:
U Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt
U Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx
U Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx
U Zope/trunk/src/Testing/ZopeTestCase/doc/TIMELINES.txt
U Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py
U Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py
A Zope/trunk/src/Testing/ZopeTestCase/testShoppingCart.py
U Zope/trunk/src/Testing/ZopeTestCase/testZopeTestCase.py
A Zope/trunk/src/Testing/ZopeTestCase/testimport/
A Zope/trunk/src/Testing/ZopeTestCase/testimport/Examples.zexp
-=-
Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt 2009-03-07 22:04:50 UTC (rev 97642)
+++ Zope/trunk/src/Testing/ZopeTestCase/doc/ENVIRONMENT.txt 2009-03-07 22:26:44 UTC (rev 97643)
@@ -2,9 +2,14 @@
ZTC makes the following assumptions about its environment:
a) The 'ZopeTestCase' package is installed in the Zope "trunk" inside the
- 'Testing' module.
+ 'Testing' module, which means: SOFTWARE_HOME/Testing/ZopeTestCase.
-b) The somewhat weak assumption is that ZTC can walk up the directory tree from
+b) A 'Products' directory exists inside SOFTWARE_HOME and INSTANCE_HOME.
+
+c) The tests (the 'tests' subdirectories) are located either below a
+ SOFTWARE_HOME or INSTANCE_HOME, typically in Products/MyCoolProduct/tests.
+
+d) The somewhat weak assumption is that ZTC can walk up the directory tree from
'tests', and find a 'Products' directory. This is how INSTANCE_HOME
detection works. It regrettably fails on some filesystems when symbolic
links are involved (a solution is detailed below, so hang on).
@@ -19,7 +24,8 @@
ZTC attempts to resolve this by detecting an INSTANCE_HOME for 1) but leaving
-the actual environment variable untouched.
+the actual environment variable untouched so 2) works by still pointing into
+SOFTWARE_HOME/Testing.
As soon as I allow you to set INSTANCE_HOME yourself, I lose the ability to
distinguish whether you mean 1) or 2) or both.
Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx 2009-03-07 22:04:50 UTC (rev 97642)
+++ Zope/trunk/src/Testing/ZopeTestCase/doc/HOWTO.stx 2009-03-07 22:26:44 UTC (rev 97643)
@@ -176,6 +176,9 @@
It demonstrates how to manipulate the test user's roles and permissions and how
security is validated.
+ - **'testShoppingCart.py'** tests the ShoppingCart example. This test
+ uses Sessions and shows how to test a TTW Zope application.
+
- **'testFunctional.py'** demonstrates the new functional testing features.
Tests may call 'self.publish()' to simulate URL calls to the ZPublisher.
Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx 2009-03-07 22:04:50 UTC (rev 97642)
+++ Zope/trunk/src/Testing/ZopeTestCase/doc/README.stx 2009-03-07 22:26:44 UTC (rev 97643)
@@ -43,9 +43,27 @@
Note that there is a skeleton test suite named 'testSkeleton.py' that you
may copy into your 'tests' directory and take it from there.
+ Note also that when the tests are run in an INSTANCE_HOME installation of
+ Zope, you must set the SOFTWARE_HOME environment variable for the 'Testing'
+ and 'ZopeTestCase' packages to be found.
+
See the sample tests in the 'ZopeTestCase' directory for details on writing
your own tests.
+framework.py
+
+ 1. Uses SOFTWARE_HOME (if set) to locate the Testing package.
+
+ 2. Detects and handles INSTANCE_HOME installations of Zope. Please
+ see ENVIRONMENT.txt for the assumptions ZTC makes about its
+ environment.
+
+ 3. Supports setting up a ZODB from a 'custom_zodb.py' file in
+ the 'tests' directory.
+
+ 4. Allows to connect to a running ZEO server by setting the
+ ZEO_INSTANCE_HOME environment variable.
+
testrunner.py
Alternatively, you may use Zope's testrunner utility to run your tests
@@ -53,7 +71,8 @@
installation). If you do so, you will have to define a 'test_suite' method
in your modules (see examples).
- You may have to provide the -i flag when testing in an INSTANCE_HOME setup.
+ There is no need to set SOFTWARE_HOME when using the testrunner but you may
+ have to provide the -i flag when testing in an INSTANCE_HOME setup.
Example: 'python /path/to/Zope/utilities/testrunner.py -q -i -a'
Modified: Zope/trunk/src/Testing/ZopeTestCase/doc/TIMELINES.txt
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/doc/TIMELINES.txt 2009-03-07 22:04:50 UTC (rev 97642)
+++ Zope/trunk/src/Testing/ZopeTestCase/doc/TIMELINES.txt 2009-03-07 22:26:44 UTC (rev 97643)
@@ -5,6 +5,7 @@
1. includes file framework.py
1.1 locates and imports the Testing package by means of
+ - SOFTWARE_HOME environment variable
- auto-detection
1.2 locates and includes file ztc_common.py
Modified: Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py 2009-03-07 22:04:50 UTC (rev 97642)
+++ Zope/trunk/src/Testing/ZopeTestCase/testBaseTestCase.py 2009-03-07 22:26:44 UTC (rev 97643)
@@ -15,8 +15,9 @@
NOTE: This is *not* an example TestCase. Do not
use this file as a blueprint for your own tests!
-See testPythonScript.py for example test cases. See testSkeleton.py for a
-quick way of getting started.
+See testPythonScript.py and testShoppingCart.py for
+example test cases. See testSkeleton.py for a quick
+way of getting started.
$Id$
"""
Modified: Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py 2009-03-07 22:04:50 UTC (rev 97642)
+++ Zope/trunk/src/Testing/ZopeTestCase/testPortalTestCase.py 2009-03-07 22:26:44 UTC (rev 97643)
@@ -15,8 +15,9 @@
NOTE: This is *not* an example TestCase. Do not
use this file as a blueprint for your own tests!
-See testPythonScript.py for example test cases. See testSkeleton.py for a
-quick way of getting started.
+See testPythonScript.py and testShoppingCart.py for
+example test cases. See testSkeleton.py for a quick
+way of getting started.
$Id$
"""
Copied: Zope/trunk/src/Testing/ZopeTestCase/testShoppingCart.py (from rev 90453, Zope/trunk/lib/python/Testing/ZopeTestCase/testShoppingCart.py)
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/testShoppingCart.py (rev 0)
+++ Zope/trunk/src/Testing/ZopeTestCase/testShoppingCart.py 2009-03-07 22:26:44 UTC (rev 97643)
@@ -0,0 +1,131 @@
+##############################################################################
+#
+# Copyright (c) 2005 Zope Corporation and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (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.
+#
+##############################################################################
+"""Example ZopeTestCase testing the ShoppingCart example application
+
+Note the use of sessions and how the SESSION object is added to
+the REQUEST in afterSetUp().
+
+$Id$
+"""
+
+import os
+
+from Testing import ZopeTestCase
+
+from Testing.ZopeTestCase import layer
+from Testing.ZopeTestCase import utils
+from Testing.ZopeTestCase import transaction
+
+here = os.path.dirname(ZopeTestCase.__file__)
+examples_path = os.path.join(here, 'testimport', 'Examples.zexp')
+
+
+class ShoppingCartLayer(layer.ZopeLite):
+
+ @classmethod
+ def setUp(cls):
+ # Set up sessioning objects
+ utils.appcall(utils.setupCoreSessions)
+
+ # Set up example applications
+ utils.appcall(utils.importObjectFromFile, examples_path, quiet=1)
+
+ @classmethod
+ def tearDown(cls):
+ def cleanup(app):
+ app._delObject('Examples')
+ transaction.commit()
+ utils.appcall(cleanup)
+
+
+class DummyOrder:
+ '''Construct an order we can add to the cart'''
+ __allow_access_to_unprotected_subobjects__ = 1
+
+ def __init__(self, id, quantity):
+ self.id = id
+ self.quantity = quantity
+
+
+class TestShoppingCart(ZopeTestCase.ZopeTestCase):
+ '''Test the ShoppingCart example application'''
+
+ _setup_fixture = 0 # No default fixture
+
+ layer = ShoppingCartLayer
+
+ def afterSetUp(self):
+ self.cart = self.app.Examples.ShoppingCart
+ # Put SESSION object into REQUEST
+ request = self.app.REQUEST
+ sdm = self.app.session_data_manager
+ request.set('SESSION', sdm.getSessionData())
+ self.session = request.SESSION
+
+ def testSession(self):
+ # Session should work
+ self.session.set('boring', 'boring')
+ self.assertEqual(self.session.get('boring'), 'boring')
+
+ def testCartIsEmpty(self):
+ # Cart should be empty
+ self.assertEqual(len(self.cart.currentItems()), 0)
+
+ def testAddItems(self):
+ # Adding to the cart should work
+ self.cart.addItems([DummyOrder('510-115', 1),])
+ self.assertEqual(len(self.cart.currentItems()), 1)
+
+ def testDeleteItems(self):
+ # Deleting from the cart should work
+ self.cart.addItems([DummyOrder('510-115', 1),])
+ self.cart.deleteItems(['510-115'])
+ self.assertEqual(len(self.cart.currentItems()), 0)
+
+ def testAddQuantity(self):
+ # Adding to quantity should work
+ self.cart.addItems([DummyOrder('510-115', 1),])
+ self.cart.addItems([DummyOrder('510-115', 2),])
+ self.cart.addItems([DummyOrder('510-115', 3),])
+ self.assertEqual(self.cart.currentItems()[0]['quantity'], 6)
+
+ def testGetTotal(self):
+ # Totals should be computed correctly
+ self.cart.addItems([DummyOrder('510-115', 1),])
+ self.cart.addItems([DummyOrder('510-122', 2),])
+ self.cart.addItems([DummyOrder('510-007', 2),])
+ self.assertEqual(self.cart.getTotal(), 149.95)
+
+ def testGetItem(self):
+ # Getting an item from the "database" should work
+ item = self.cart.getItem('510-115')
+ self.assertEqual(item['id'], '510-115')
+ self.assertEqual(item['title'], 'Econo Feeder')
+ self.assertEqual(item['price'], 7.95)
+
+ def testEight(self):
+ # Additional test to trigger connection pool depletion bug
+ pass
+
+
+class TestSandboxedShoppingCart(ZopeTestCase.Sandboxed, TestShoppingCart):
+ '''Demonstrate that sessions work in sandboxes'''
+
+
+def test_suite():
+ from unittest import TestSuite, makeSuite
+ suite = TestSuite()
+ suite.addTest(makeSuite(TestShoppingCart))
+ suite.addTest(makeSuite(TestSandboxedShoppingCart))
+ return suite
+
Modified: Zope/trunk/src/Testing/ZopeTestCase/testZopeTestCase.py
===================================================================
--- Zope/trunk/src/Testing/ZopeTestCase/testZopeTestCase.py 2009-03-07 22:04:50 UTC (rev 97642)
+++ Zope/trunk/src/Testing/ZopeTestCase/testZopeTestCase.py 2009-03-07 22:26:44 UTC (rev 97643)
@@ -15,8 +15,9 @@
NOTE: This is *not* an example TestCase. Do not
use this file as a blueprint for your own tests!
-See testPythonScript.py for example test cases. See testSkeleton.py for a
-quick way of getting started.
+See testPythonScript.py and testShoppingCart.py for
+example test cases. See testSkeleton.py for a quick
+way of getting started.
$Id$
"""
Added: Zope/trunk/src/Testing/ZopeTestCase/testimport/Examples.zexp
===================================================================
(Binary files differ)
Property changes on: Zope/trunk/src/Testing/ZopeTestCase/testimport/Examples.zexp
___________________________________________________________________
Added: svn:mime-type
+ application/octet-stream
More information about the Zope-Checkins
mailing list