[Checkins] SVN: Products.ZSQLMethods/trunk/ - LP #142501: Only connect upon ZODB load if a new flag ``connect_on_load``

Jens Vagelpohl jens at dataflake.org
Thu Aug 19 07:45:45 EDT 2010


Log message for revision 115794:
  - LP #142501: Only connect upon ZODB load if a new flag ``connect_on_load``
    has been set to a true value (which is its default for backwards 
    compatibility)
  

Changed:
  U   Products.ZSQLMethods/trunk/CHANGES.txt
  U   Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/Connection.py
  A   Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/tests/test_connection.py

-=-
Modified: Products.ZSQLMethods/trunk/CHANGES.txt
===================================================================
--- Products.ZSQLMethods/trunk/CHANGES.txt	2010-08-19 11:08:38 UTC (rev 115793)
+++ Products.ZSQLMethods/trunk/CHANGES.txt	2010-08-19 11:45:44 UTC (rev 115794)
@@ -4,6 +4,10 @@
 2.13.3 (unreleased)
 -------------------
 
+- LP #142501: Only connect upon ZODB load if a new flag ``connect_on_load``
+  has been set to a true value (which is its default for backwards 
+  compatibility)
+
 - LP #142689: Actually use SQL connection titles in the list of 
   connections returned by SQL.SQLConnectionIDs
 

Modified: Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/Connection.py
===================================================================
--- Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/Connection.py	2010-08-19 11:08:38 UTC (rev 115793)
+++ Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/Connection.py	2010-08-19 11:45:44 UTC (rev 115794)
@@ -72,6 +72,9 @@
 
     _v_connected=''
     connection_string=''
+    # Should the database connection be established when the object
+    # is loaded from the ZODB (in __setstate__)?
+    connect_on_load=True
 
     def __init__(self, id, title, connection_string, check=None):
         self.id=str(id)
@@ -79,7 +82,7 @@
 
     def __setstate__(self, state):
         Persistent.__setstate__(self, state)
-        if self.connection_string:
+        if self.connect_on_load and self.connection_string:
             try: self.connect(self.connection_string)
             except:
                 LOG.error('Error connecting to relational database.',

Added: Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/tests/test_connection.py
===================================================================
--- Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/tests/test_connection.py	                        (rev 0)
+++ Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/tests/test_connection.py	2010-08-19 11:45:44 UTC (rev 115794)
@@ -0,0 +1,43 @@
+##############################################################################
+#
+# Copyright (c) 2010 Zope Foundation and Contributors.
+#
+# 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 unittest
+
+def faux_connect(self, connection_string):
+    setattr(self, '_connected_to', connection_string)
+
+
+class ConnectionTests(unittest.TestCase):
+
+    def _getTargetClass(self):
+        from Shared.DC.ZRDB.Connection import Connection
+        Connection.connect = faux_connect
+        return Connection
+
+    def _makeOne(self, *args, **kw):
+        return self._getTargetClass()(*args, **kw)
+
+    def test_connect_on_load(self):
+        conn1 = self._makeOne('conn1', '', 'conn string 1')
+        conn1.__setstate__(None)
+        self.assertEqual(conn1._connected_to, 'conn string 1')
+
+        conn2 = self._makeOne('conn2', '', 'conn string 2')
+        conn2.connect_on_load = False
+        conn2.__setstate__(None)
+        self.failIf(hasattr(conn2, '_connected_to'))
+
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(unittest.makeSuite(ConnectionTests))
+    return suite


Property changes on: Products.ZSQLMethods/trunk/src/Shared/DC/ZRDB/tests/test_connection.py
___________________________________________________________________
Added: svn:keywords
   + Id
Added: svn:eol-style
   + native



More information about the checkins mailing list