[Zope3-checkins] SVN: Zope3/branches/jinty-zodbless/src/zope/app/ Remove the dependency of the publication tests on ZODB (Now we only import ZODB.POSException). Move and add some tests to zope.app.zodb.

Brian Sutherland jinty at web.de
Sun Apr 8 19:44:29 EDT 2007


Log message for revision 74042:
  Remove the dependency of the publication tests on ZODB (Now we only import ZODB.POSException). Move and add some tests to zope.app.zodb.

Changed:
  U   Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_browserpublication.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_xmlrpcpublication.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_zopepublication.py
  U   Zope3/branches/jinty-zodbless/src/zope/app/zodb/app.py
  A   Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/
  A   Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/__init__.py
  A   Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/test_app.py

-=-
Modified: Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_browserpublication.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_browserpublication.py	2007-04-08 19:46:09 UTC (rev 74041)
+++ Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_browserpublication.py	2007-04-08 23:44:28 UTC (rev 74042)
@@ -117,7 +117,7 @@
         # so that the classes can be pickled.
         import transaction
 
-        pub = BrowserPublication(self.db)
+        pub = self.publication
 
         ztapi.browserView(I1, 'view', DummyView)
         ztapi.setDefaultViewName(I1, 'view')
@@ -131,13 +131,9 @@
 
         # now place our object inside the application
 
-        connection = self.db.open()
-        app = connection.root()['Application']
-        app.somepath = ob
-        transaction.commit()
-        connection.close()
+        self.app.somepath = ob
 
-        defineChecker(app.__class__, NamesChecker(somepath='xxx'))
+        defineChecker(self.app.__class__, NamesChecker(somepath='xxx'))
 
         req = self._createRequest(url, pub)
         response = req.response
@@ -174,7 +170,7 @@
         ob = mydict()
         ob['bruce'] = SimpleObject('bruce')
         ob['bruce2'] = SimpleObject('bruce2')
-        pub = self.klass(self.db)
+        pub = self.publication
         ob2 = pub.traverseName(self._createRequest('/bruce', pub), ob, 'bruce')
         self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v')
         self.assertEqual(removeSecurityProxy(ob2).v, 'bruce')
@@ -193,14 +189,14 @@
         ob = mydict()
         ob['bruce'] = SimpleObject('bruce')
         ob['bruce2'] = SimpleObject('bruce2')
-        pub = self.klass(self.db)
+        pub = self.publication
         ob2, x = pub.getDefaultTraversal(self._createRequest('/bruce',pub), ob)
         self.assertEqual(x, 'dummy')
         self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v')
         self.assertEqual(removeSecurityProxy(ob2).v, 'bruce')
 
     def testTraverseName(self):
-        pub = self.klass(self.db)
+        pub = self.publication
         class C(object):
             x = SimpleObject(1)
         ob = C()
@@ -211,7 +207,7 @@
         self.assertEqual(removeSecurityProxy(ob2).v, 1)
 
     def testTraverseNameView(self):
-        pub = self.klass(self.db)
+        pub = self.publication
         class I(Interface): pass
         class C(object):
             implements(I)
@@ -224,7 +220,7 @@
         self.assertEqual(ob2.__class__, V)
 
     def testTraverseNameSiteManager(self):
-        pub = self.klass(self.db)
+        pub = self.publication
         class C(object):
             def getSiteManager(self):
                 return SimpleObject(1)
@@ -234,21 +230,8 @@
         self.assertRaises(ForbiddenAttribute, getattr, ob2, 'v')
         self.assertEqual(removeSecurityProxy(ob2).v, 1)
 
-    def testTraverseNameApplicationControl(self):
-        from zope.app.applicationcontrol.applicationcontrol \
-             import applicationController, applicationControllerRoot
-        pub = self.klass(self.db)
-        r = self._createRequest('/++etc++process',pub)
-        ac = pub.traverseName(r,
-                              applicationControllerRoot,
-                              '++etc++process')
-        self.assertEqual(ac, applicationController)
-        r = self._createRequest('/++etc++process',pub)
-        app = r.publication.getApplication(r)
-        self.assertEqual(app, applicationControllerRoot)
-
     def testHEADFuxup(self):
-        pub = self.klass(self.db)
+        pub = self.publication
 
         class User(object):
             id = 'bob'
@@ -303,7 +286,7 @@
         factoryRegistry.register('HEAD', '*', 'BROWSER', 10, BrowserFactory())
 
     def testGetBackSamePublication(self):
-        factory = HTTPPublicationRequestFactory(db=self.db)
+        factory = HTTPPublicationRequestFactory(db=self.resource_factory)
         args = (StringIO(''), {})
         self.assert_(id(factory(*args).publication) ==
                      id(factory(*args).publication))

Modified: Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_xmlrpcpublication.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_xmlrpcpublication.py	2007-04-08 19:46:09 UTC (rev 74041)
+++ Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_xmlrpcpublication.py	2007-04-08 23:44:28 UTC (rev 74042)
@@ -46,7 +46,7 @@
         return request
 
     def testTraverseName(self):
-        pub = self.klass(self.db)
+        pub = self.publication
         class C(object):
             x = SimpleObject(1)
         ob = C()
@@ -57,7 +57,7 @@
         self.assertEqual(removeAllProxies(ob2).v, 1)
 
     def testDenyDirectMethodAccess(self):
-        pub = self.klass(self.db)
+        pub = self.publication
         class I(Interface):
             pass
 
@@ -81,7 +81,7 @@
 
 
     def testTraverseNameView(self):
-        pub = self.klass(self.db)
+        pub = self.publication
 
         class I(Interface):
             pass
@@ -114,7 +114,7 @@
         
 
     def testTraverseNameSiteManager(self):
-        pub = self.klass(self.db)
+        pub = self.publication
         class C(object):
             def getSiteManager(self):
                 return SimpleObject(1)

Modified: Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_zopepublication.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_zopepublication.py	2007-04-08 19:46:09 UTC (rev 74041)
+++ Zope3/branches/jinty-zodbless/src/zope/app/publication/tests/test_zopepublication.py	2007-04-08 23:44:28 UTC (rev 74042)
@@ -19,10 +19,6 @@
 import sys
 from cStringIO import StringIO
 
-from persistent import Persistent
-from ZODB.interfaces import IDatabase
-from ZODB.DB import DB
-from ZODB.DemoStorage import DemoStorage
 import transaction
 
 import zope.component
@@ -47,11 +43,19 @@
 from zope.app.security.interfaces import IUnauthenticatedPrincipal, IPrincipal
 from zope.app.publication.zopepublication import ZopePublication
 from zope.app.publication.interfaces import IResourceFactory
-from zope.app.zodb.app import ZODBApplicationFactory
 from zope.app.folder import Folder, rootFolder
 from zope.location import Location
 from zope.app.security.interfaces import IAuthenticationUtility
 
+class ResourceFactoryStub:
+    implements(IResourceFactory)
+
+    def __init__(self, app):
+        self.app = app
+
+    def __call__(self, request):
+        return self.app
+
 class Principal(object):
     implements(IPrincipal)
     def __init__(self, id):
@@ -103,33 +107,20 @@
 
 class BasePublicationTests(PlacelessSetup, unittest.TestCase):
 
+    klass = ZopePublication
+
     def setUp(self):
         super(BasePublicationTests, self).setUp()
         from zope.security.management import endInteraction
         endInteraction()
         ztapi.provideAdapter(IHTTPRequest, IUserPreferredCharsets,
                              HTTPCharsets)
-        ztapi.provideAdapter(IDatabase, IResourceFactory,
-                             ZODBApplicationFactory)
         self.policy = setSecurityPolicy(
             simplepolicies.PermissiveSecurityPolicy
             )
-        self.storage = DemoStorage('test_storage')
-        self.db = db = DB(self.storage)
 
-        connection = db.open()
-        root = connection.root()
-        app = getattr(root, ZopePublication.root_name, None)
+        self.app = rootFolder()
 
-        if app is None:
-            from zope.app.folder import rootFolder
-            app = rootFolder()
-            root[ZopePublication.root_name] = app
-            transaction.commit()
-
-        connection.close()
-        self.app = app
-
         from zope.traversing.namespace import view, resource, etc
         ztapi.provideNamespaceHandler('view', view)
         ztapi.provideNamespaceHandler('resource', resource)
@@ -142,7 +133,8 @@
         self.presentation_type = Interface
         self.request._presentation_type = self.presentation_type
         self.object = object()
-        self.publication = ZopePublication(self.db)
+        self.resource_factory = ResourceFactoryStub(self.app)
+        self.publication = self.klass(self.resource_factory)
 
     def tearDown(self):
         # Close the request, otherwise a Cleanup object will start logging
@@ -383,13 +375,17 @@
         self.assert_(txn is not transaction.get())
 
     def testAbortTransactionWithErrorReportingUtility(self):
+        self.committed = False
+        def hook(status, self):
+            self.committed = True
+        txn = transaction.get()
+        txn.addAfterCommitHook(hook, (self, ))
         # provide our fake error reporting utility
         zope.component.provideUtility(ErrorReportingUtility())
 
         class FooError(Exception):
             pass
 
-        last_txn_info = self.db.undoInfo()[0]
         try:
             raise FooError
         except FooError:
@@ -397,9 +393,10 @@
         self.publication.handleException(
             self.object, self.request, sys.exc_info(), retry_allowed=False)
 
-        # assert that the last transaction is NOT our transaction
-        new_txn_info = self.db.undoInfo()[0]
-        self.assertEqual(last_txn_info, new_txn_info)
+        # assert that we get a new transaction
+        self.assert_(txn is not transaction.get())
+        # No transaction should be committed
+        self.assertEqual(self.committed, False)
 
         # instead, we expect a message in our logging utility
         error_log = zope.component.getUtility(IErrorReportingUtility)
@@ -417,10 +414,8 @@
         setup.setUpSiteManagerLookup()
         principalRegistry.defineDefaultPrincipal('anonymous', '')
 
-        root = self.db.open().root()
-        app = root[ZopePublication.root_name]
-        app['f1'] = rootFolder()
-        f1 = app['f1']
+        self.app['f1'] = rootFolder()
+        f1 = self.app['f1']
         f1['f2'] = Folder()
         sm1 = setup.createSiteManager(f1)
         setup.addUtility(sm1, '', IAuthenticationUtility, AuthUtility1())
@@ -459,62 +454,58 @@
         self.assertEqual(queryInteraction(), None)
 
     def testTransactionCommitAfterCall(self):
-        root = self.db.open().root()
+        self.committed = False
+        def hook(status, self):
+            self.committed = True
         txn = transaction.get()
-        # we just need a change in the database to make the
-        # transaction notable in the undo log
-        root['foo'] = object()
-        last_txn_info = self.db.undoInfo()[0]
+        txn.addAfterCommitHook(hook, (self, ))
         self.publication.afterCall(self.request, self.object)
+        # Make sure we have a new transaction
         self.assert_(txn is not transaction.get())
-        new_txn_info = self.db.undoInfo()[0]
-        self.failIfEqual(last_txn_info, new_txn_info)
+        # and that the last one was committed
+        self.assertEqual(self.committed, True)
 
     def testDoomedTransaction(self):
-        # Test that a doomed transaction is aborted without error in afterCall
-        root = self.db.open().root()
+        self.committed = False
+        def hook(status, self):
+            self.committed = True
+        # start a new transaction
         txn = transaction.get()
-        # we just need a change in the database to make the
-        # transaction notable in the undo log
-        root['foo'] = object()
-        last_txn_info = self.db.undoInfo()[0]
+        txn.addAfterCommitHook(hook, (self, ))
         # doom the transaction
         txn.doom()
         self.publication.afterCall(self.request, self.object)
         # assert that we get a new transaction
         self.assert_(txn is not transaction.get())
-        new_txn_info = self.db.undoInfo()[0]
         # No transaction should be committed
-        self.assertEqual(last_txn_info, new_txn_info)
+        self.assertEqual(self.committed, False)
 
     def testTransactionAnnotation(self):
         from zope.interface import directlyProvides
         from zope.location.traversing import LocationPhysicallyLocatable
         from zope.location.interfaces import ILocation
         from zope.traversing.interfaces import IPhysicallyLocatable
-        from zope.traversing.interfaces import IContainmentRoot
         ztapi.provideAdapter(ILocation, IPhysicallyLocatable,
                              LocationPhysicallyLocatable)
 
-        root = self.db.open().root()
-        root['foo'] = foo = LocatableObject()
-        root['bar'] = bar = LocatableObject()
+        self.app['foo'] = foo = LocatableObject()
+        self.app['bar'] = bar = LocatableObject()
         bar.__name__ = 'bar'
         foo.__name__ = 'foo'
         bar.__parent__ = foo
-        foo.__parent__ = root
-        directlyProvides(root, IContainmentRoot)
+        foo.__parent__ = self.app
 
         from zope.publisher.interfaces import IRequest
         expected_path = "/foo/bar"
         expected_user = "/ " + self.user.id
         expected_request = IRequest.__module__ + '.' + IRequest.getName()
 
+        txn = transaction.get()
         self.publication.afterCall(self.request, bar)
-        txn_info = self.db.undoInfo()[0]
+        txn_info = txn._extension
         self.assertEqual(txn_info['location'], expected_path)
-        self.assertEqual(txn_info['user_name'], expected_user)
         self.assertEqual(txn_info['request_type'], expected_request)
+        self.assertEqual(txn.user, expected_user)
 
         # also, assert that we still get the right location when
         # passing an instance method as object.

Modified: Zope3/branches/jinty-zodbless/src/zope/app/zodb/app.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/zodb/app.py	2007-04-08 19:46:09 UTC (rev 74041)
+++ Zope3/branches/jinty-zodbless/src/zope/app/zodb/app.py	2007-04-08 23:44:28 UTC (rev 74042)
@@ -1,3 +1,16 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
 import logging
 
 from zope.app.appsetup.interfaces import IApplicationFactory

Added: Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/__init__.py
===================================================================


Property changes on: Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/test_app.py
===================================================================
--- Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/test_app.py	2007-04-08 19:46:09 UTC (rev 74041)
+++ Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/test_app.py	2007-04-08 23:44:28 UTC (rev 74042)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.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.
+#
+##############################################################################
+import doctest
+
+import transaction
+from ZODB.DB import DB
+from ZODB.DemoStorage import DemoStorage
+from zope.app.folder import rootFolder
+from zope.publisher.base import TestPublication
+from zope.publisher.browser import TestRequest
+from zope.app.applicationcontrol.applicationcontrol \
+     import applicationController, applicationControllerRoot
+
+from zope.app.zodb import ROOT_NAME
+from zope.app.zodb.app import ZODBApplicationFactory
+
+def setUp(test):
+    transaction.begin()
+
+    storage = DemoStorage('test_storage')
+    db = DB(storage)
+
+    connection = db.open()
+    root = connection.root()
+    app = rootFolder()
+    root[ROOT_NAME] = app
+    transaction.commit()
+
+    connection.close()
+
+    test.globs['app'] = app
+    test.globs['resource_factory'] = ZODBApplicationFactory(db)
+
+def createRequest(path, publication, **kw):
+    request = TestRequest(PATH_INFO=path, **kw)
+    request.setPublication(publication)
+    return request
+
+def testGetApplication():
+    """
+    Make sure that if we call the resource_factory, we get the application
+    object:
+
+        >>> r = createRequest('/foo', TestPublication(None))
+        >>> app is resource_factory(r)
+        True
+    """
+
+def testTraverseNameApplicationControl():
+    # XXX - applicationControllerRoot traversal should not be tested here.
+    #r = self._createRequest('/++etc++process', TestPublication(None))
+    #ac = pub.traverseName(r,
+    #                      applicationControllerRoot,
+    #                      '++etc++process')
+    #self.assertEqual(ac, applicationController)
+    """
+    Make sure that if we traverse to /++etc++process, we get the application controller root.
+
+        >>> r = createRequest('/++etc++process', TestPublication(None))
+        >>> acr = resource_factory(r)
+        >>> acr is applicationControllerRoot
+        True
+    """
+
+def test_suite():
+    return doctest.DocTestSuite(setUp=setUp)


Property changes on: Zope3/branches/jinty-zodbless/src/zope/app/zodb/tests/test_app.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Zope3-Checkins mailing list