[Checkins] SVN: z3c.testing/trunk/src/z3c/testing/ added buffered db test layer

Bernd Dorn bernd.dorn at lovelysystems.com
Thu Mar 1 03:00:58 EST 2007


Log message for revision 72942:
  added buffered db test layer

Changed:
  _U  z3c.testing/trunk/src/z3c/testing/
  A   z3c.testing/trunk/src/z3c/testing/BROWSER.txt
  A   z3c.testing/trunk/src/z3c/testing/ftests.py
  A   z3c.testing/trunk/src/z3c/testing/layer.py
  A   z3c.testing/trunk/src/z3c/testing/test.zcml

-=-

Property changes on: z3c.testing/trunk/src/z3c/testing
___________________________________________________________________
Name: svn:ignore
   + var_*


Added: z3c.testing/trunk/src/z3c/testing/BROWSER.txt
===================================================================
--- z3c.testing/trunk/src/z3c/testing/BROWSER.txt	2007-03-01 06:05:26 UTC (rev 72941)
+++ z3c.testing/trunk/src/z3c/testing/BROWSER.txt	2007-03-01 08:00:57 UTC (rev 72942)
@@ -0,0 +1,3 @@
+=========
+ Browser
+=========


Property changes on: z3c.testing/trunk/src/z3c/testing/BROWSER.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.testing/trunk/src/z3c/testing/ftests.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/ftests.py	2007-03-01 06:05:26 UTC (rev 72941)
+++ z3c.testing/trunk/src/z3c/testing/ftests.py	2007-03-01 08:00:57 UTC (rev 72942)
@@ -0,0 +1,18 @@
+import layer
+from zope.app.testing import functional
+import unittest
+
+MyLayer = layer.createLayer(zcml='test.zcml')
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suites = (
+        functional.FunctionalDocFileSuite('BROWSER.txt'),
+        )
+    for s in suites:
+        s.layer=MyLayer
+        suite.addTest(s)
+        return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')


Property changes on: z3c.testing/trunk/src/z3c/testing/ftests.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: z3c.testing/trunk/src/z3c/testing/layer.py
===================================================================
--- z3c.testing/trunk/src/z3c/testing/layer.py	2007-03-01 06:05:26 UTC (rev 72941)
+++ z3c.testing/trunk/src/z3c/testing/layer.py	2007-03-01 08:00:57 UTC (rev 72942)
@@ -0,0 +1,102 @@
+##############################################################################
+#
+# Copyright (c) 2006 Lovely Systems 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.
+#
+##############################################################################
+"""A test layer to use a saved database.
+
+The testlayer creates a database using a configurator and uses the
+database for all tests.
+
+$Id$
+"""
+__docformat__ = "reStructuredText"
+
+import unittest
+import os
+import transaction
+
+from ZODB.FileStorage import FileStorage
+
+from zope import component
+from zope import schema
+
+from zope.app.appsetup import database
+from zope.app.testing import functional
+from zope.app.publication.zopepublication import ZopePublication
+import sys
+
+class BufferedDatabaseTestLayer(object):
+    """A test layer which creates a filestorage database.
+    
+    The created database is later used without the need to run through the
+    setup again.
+    This speeds up functional tests.
+    """
+
+    __name__ = "BufferedTestLayer"
+    __bases__ = ()
+    path = None
+
+    def __init__(self, config_file=None, module=__module__,
+                 name="BufferedTestLayer"):
+        self.config_file = config_file
+        self.__module__ = module
+        self.__name__ = name
+
+    def setUpApplication(self, app):
+        # to be overridden by subclass
+        pass
+        
+    def setUp(self):
+
+        dbpath = self.path or os.path.dirname(__file__)
+        dbDirName = 'var_%s' % self.__module__
+        if dbDirName not in os.listdir(dbpath):
+            os.mkdir(os.path.join(dbpath, dbDirName))
+        filename = os.path.join(dbpath, dbDirName, 'TestData.fs')
+
+        fsetup = functional.FunctionalTestSetup(self.config_file)
+        self.original = fsetup.base_storage
+
+        if not os.path.exists(filename):
+            import pdb; pdb.set_trace()
+            # Generate a new database from scratch and fill it
+            db = database(filename)
+            connection = db.open()
+            root = connection.root()
+            app = root[ZopePublication.root_name]
+            self.setUpApplication(app)
+            transaction.commit()
+            connection.close()
+            db.close()
+
+        fsetup.base_storage = FileStorage(filename)
+        fsetup.setUp()
+
+    def tearDown(self):
+        fsetup = functional.FunctionalTestSetup()
+        fsetup.base_storage.close()
+        fsetup.base_storage = self.original
+        fsetup.tearDown()
+
+def createLayer(name='BufferedTestLayer', zcml=None, setUp=None):
+    """Helper function for defining layers.
+
+    Usage: defineLayer('foo')
+    """
+    globals = sys._getframe(1).f_globals
+    if zcml is not None:
+        zcml = os.path.join(os.path.split(globals['__file__'])[0], zcml)
+    l = BufferedDatabaseTestLayer(zcml, globals['__name__'], name)
+    if setUp is not None:
+        l.setUpApplication = setUp
+    return l


Property changes on: z3c.testing/trunk/src/z3c/testing/layer.py
___________________________________________________________________
Name: svn:keywords
   + Id
Name: svn:eol-style
   + native

Added: z3c.testing/trunk/src/z3c/testing/test.zcml
===================================================================
--- z3c.testing/trunk/src/z3c/testing/test.zcml	2007-03-01 06:05:26 UTC (rev 72941)
+++ z3c.testing/trunk/src/z3c/testing/test.zcml	2007-03-01 08:00:57 UTC (rev 72942)
@@ -0,0 +1,4 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+  <include package="zope.app"/>
+  
+</configure>
\ No newline at end of file


Property changes on: z3c.testing/trunk/src/z3c/testing/test.zcml
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list