[Zope3-checkins] CVS: Zope3/lib/python/Zope/App/RDB/tests - testZopeConnection.py:1.4 testZopeDBTransactionManager.py:1.3

Jeremy Hylton jeremy@zope.com
Wed, 24 Jul 2002 19:17:05 -0400


Update of /cvs-repository/Zope3/lib/python/Zope/App/RDB/tests
In directory cvs.zope.org:/tmp/cvs-serv5275/Zope/App/RDB/tests

Modified Files:
	testZopeConnection.py testZopeDBTransactionManager.py 
Log Message:
Implement new Transaction API for RDB.

There is still a fair amount of needless complexity here.
XXX Refactor to eliminate excess classes and interfaces.






=== Zope3/lib/python/Zope/App/RDB/tests/testZopeConnection.py 1.3 => 1.4 ===
 class ZopeConnectionTests(TestCase):
 
     def test_cursor(self):
-        "ZopeConnection.cursor() should return an IZopeCursor"
         zc = ZopeConnection(ConnectionStub())
         cursor = zc.cursor()
         
@@ -32,28 +31,21 @@
                         "cursor is not what we expected")
 
     def test_connection_txn_registration(self):
-
         t = get_transaction()
         t.begin()
 
         zc = ZopeConnection(ConnectionStub())
         cursor = zc.cursor()
         cursor.execute('select * from blah')
-        
-        self.failUnless(zc._txn_registered == 1,
-                        """connection was not registered for txn (conn)""")
 
-        self.failUnless(len(t._objects) == 1,
-                        """connection was not registered for txn (txn) """)
+        self.assertEqual(zc._txn_registered, True)
+        self.assertEqual(len(t._resources), 1)
 
     def test_getattr(self):
-        "ZopeConnection must reveal Connection's methods"
-
         zc = ZopeConnection(ConnectionStub())
         cursor = zc.cursor()
 
-        self.failUnless(zc.answer() == 42, "Cannot see the connection")
-
+        self.assertEqual(zc.answer(), 42)
 
     def tearDown(self):
         "Abort the transaction"


=== Zope3/lib/python/Zope/App/RDB/tests/testZopeDBTransactionManager.py 1.2 => 1.3 ===
 # FOR A PARTICULAR PURPOSE.
 #
 ##############################################################################
-"""XXX short summary goes here.
-
-XXX longer description goes here.
-
+"""
 $Id$
 """
 
 from unittest import TestCase, TestSuite, main, makeSuite
 from Transaction import get_transaction
+from Transaction.tests.abstestIDataManager import IDataManagerTests
 from Zope.App.RDB.ZopeDBTransactionManager import ZopeDBTransactionManager
 from Zope.App.RDB.ZopeConnection import ZopeConnection
 from Stubs import *
 
-class TxnMgrTest(TestCase):
-    """
-    test txn integration.
-    """
+class TxnMgrTest(IDataManagerTests, TestCase):
+
+    def setUp(self):
+        self.conn = ConnectionStub()
+        zc = ZopeConnection(self.conn)
+        self.datamgr = ZopeDBTransactionManager(zc)
+        zc.registerForTxn()
+        self.txn_factory = get_transaction
 
     def tearDown(self):
         """ make sure the global env is clean"""
         get_transaction().abort()
 
     def test_abort(self):
-	
-        conn = ConnectionStub()
-        zc = ZopeConnection(conn)
-        tm = ZopeDBTransactionManager(zc)
-
-        zc.registerForTxn()
-        
-        t = get_transaction()
-        t.abort()
-
-        self.failUnless(conn._called.get('rollback')==1,
-                        """ abort failed """)
+        get_transaction().abort()
+        self.assertEqual(self.conn._called.get('rollback'), 1)
 
     def test_commit(self):
-        
-        conn = ConnectionStub()
-        zc = ZopeConnection(conn)
-        tm = ZopeDBTransactionManager(zc)
-
-        zc.registerForTxn()
-        
-        t = get_transaction()
-        t.commit()
-
-        self.failUnless(conn._called.get('commit')==1,
-                        """ commit failed """)
+        get_transaction().commit()
+        self.assertEqual(self.conn._called.get('commit'), 1)
 
 def test_suite():
     return makeSuite(TxnMgrTest)