]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
extra tests...
authorMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 May 2006 19:02:09 +0000 (19:02 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Sun, 28 May 2006 19:02:09 +0000 (19:02 +0000)
lib/sqlalchemy/engine/threadlocal.py
test/parseconnect.py
test/testbase.py
test/transaction.py

index d909cbeda2a75ccf5c9c155136f64b4932764a39..84e5a7dc427b5839527a1940fdf716013011bb10 100644 (file)
@@ -14,7 +14,12 @@ class TLSession(object):
         try:
             return self.__transaction
         except AttributeError:
-            return base.Connection(self.engine, close_with_result=close_with_result)
+            return TLConnection(self, close_with_result=close_with_result)
+    def set_transaction(self, tlconnection, trans):
+        if self.__tcount == 0:
+            self.__transaction = tlconnection
+            self.__trans = trans
+        self.__tcount += 1
     def begin(self):
         if self.__tcount == 0:
             self.__transaction = self.get_connection()
@@ -41,7 +46,12 @@ class TLSession(object):
     def is_begun(self):
         return self.__tcount > 0
 
-    
+class TLConnection(base.Connection):
+    def __init__(self, session, close_with_result):
+        base.Connection.__init__(self, session.engine, close_with_result=close_with_result)
+        self.__session = session
+    # TODO: get begin() to communicate with the Session to maintain the same transactional state
+       
 class TLEngine(base.ComposedSQLEngine):
     """a ComposedSQLEngine that includes support for thread-local managed transactions.  This engine
     is better suited to be used with threadlocal Pool object."""
index e1f50e8c91ef7da129208808803beaed8c6ef497..97061a683430bd1f2a518eae1aeee65cd48cdf1e 100644 (file)
@@ -17,10 +17,12 @@ class ParseConnectTest(PersistTest):
             'dbtype:///:memory:',
             'dbtype:///foo/bar/im/a/file',
             'dbtype:///E:/work/src/LEM/db/hello.db',
-            'dbtype://'
+            'dbtype://',
+            'dbtype://username:password@/db'
         ):
             u = url.make_url(text)
             print u, text
+            print u.username, u.password,  u.database
             assert str(u) == text
 
             
index 17e42906b5a91ba8b88d00b8fb69a0b3365639fb..57fcb58c30e2add6dc30251c3b289fe210f203e6 100644 (file)
@@ -157,8 +157,6 @@ class MockPool(pool.Pool):
         raise "Invalid"
 
     def do_get(self):
-        if getattr(self, 'breakpoint', False):
-            raise "breakpoint"
         assert self.connection is not None
         c = self.connection
         self.connection = None
index a009c447ca8e95d6ce5b74033183aeef4f9aef91..42baff46d6f56790a6f4fd96735ede57d94e3901 100644 (file)
@@ -143,6 +143,13 @@ class TLTransactionTest(testbase.PersistTest):
             self.assert_(external_connection.scalar("select count(1) from query_users") == 0)
         finally:
             external_connection.close()
+    
+    def testconnections(self):
+        """tests that contextual_connect is threadlocal"""
+        c1 = tlengine.contextual_connect()
+        c2 = tlengine.contextual_connect()
+        assert c1.connection is c2.connection
+        c1.close()
         
 if __name__ == "__main__":
     testbase.main()