1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: test_db.py,v 1.10 2001-12-03 21:33:39 richard Exp $
18+ # $Id: test_db.py,v 1.11 2001-12-10 23:17:20 richard Exp $
1919
2020import unittest , os , shutil
2121
@@ -33,26 +33,14 @@ def setupSchema(db, create):
3333 Class (db , "user" , username = String (), password = Password ())
3434 Class (db , "issue" , title = String (), status = Link ("status" ),
3535 nosy = Multilink ("user" ))
36-
37- #class MyTestResult(unittest._TestResult):
38- # def addError(self, test, err):
39- # print `err`
40- # TestResult.addError(self, test, err)
41- # if self.showAll:
42- # self.stream.writeln("ERROR")
43- # elif self.dots:
44- # self.stream.write('E')
45- # if err[0] is KeyboardInterrupt:
46- # self.shouldStop = 1
36+ db .commit ()
4737
4838class MyTestCase (unittest .TestCase ):
49- # def defaultTestResult(self):
50- # return MyTestResult()
5139 def tearDown (self ):
52- if self . db is not None :
40+ if os . path . exists ( '_test_dir' ) :
5341 shutil .rmtree ('_test_dir' )
5442
55- class DBTestCase (MyTestCase ):
43+ class anydbmDBTestCase (MyTestCase ):
5644 def setUp (self ):
5745 from roundup .backends import anydbm
5846 # remove previous test, ignore errors
@@ -83,6 +71,19 @@ def testChanges(self):
8371 self .db .status .history ('1' )
8472 self .db .status .history ('2' )
8573
74+ def testTransactions (self ):
75+ num_issues = len (self .db .issue .list ())
76+ self .db .issue .create (title = "don't commit me!" , status = '1' )
77+ self .assertNotEqual (num_issues , len (self .db .issue .list ()))
78+ self .db .rollback ()
79+ self .assertEqual (num_issues , len (self .db .issue .list ()))
80+ self .db .issue .create (title = "please commit me!" , status = '1' )
81+ self .assertNotEqual (num_issues , len (self .db .issue .list ()))
82+ self .db .commit ()
83+ self .assertNotEqual (num_issues , len (self .db .issue .list ()))
84+ self .db .rollback ()
85+ self .assertNotEqual (num_issues , len (self .db .issue .list ()))
86+
8687 def testExceptions (self ):
8788 # this tests the exceptions that should be raised
8889 ar = self .assertRaises
@@ -149,7 +150,7 @@ def testRetire(self):
149150 pass
150151
151152
152- class ReadOnlyDBTestCase (MyTestCase ):
153+ class anydbmReadOnlyDBTestCase (MyTestCase ):
153154 def setUp (self ):
154155 from roundup .backends import anydbm
155156 # remove previous test, ignore errors
@@ -171,7 +172,7 @@ def testExceptions(self):
171172 ar (DatabaseError , self .db .status .retire , '1' )
172173
173174
174- class bsddbDBTestCase (DBTestCase ):
175+ class bsddbDBTestCase (anydbmDBTestCase ):
175176 def setUp (self ):
176177 from roundup .backends import bsddb
177178 # remove previous test, ignore errors
@@ -181,7 +182,7 @@ def setUp(self):
181182 self .db = bsddb .Database ('_test_dir' , 'test' )
182183 setupSchema (self .db , 1 )
183184
184- class bsddbReadOnlyDBTestCase (ReadOnlyDBTestCase ):
185+ class bsddbReadOnlyDBTestCase (anydbmReadOnlyDBTestCase ):
185186 def setUp (self ):
186187 from roundup .backends import bsddb
187188 # remove previous test, ignore errors
@@ -194,7 +195,7 @@ def setUp(self):
194195 setupSchema (self .db , 0 )
195196
196197
197- class bsddb3DBTestCase (DBTestCase ):
198+ class bsddb3DBTestCase (anydbmDBTestCase ):
198199 def setUp (self ):
199200 from roundup .backends import bsddb3
200201 # remove previous test, ignore errors
@@ -204,7 +205,7 @@ def setUp(self):
204205 self .db = bsddb3 .Database ('_test_dir' , 'test' )
205206 setupSchema (self .db , 1 )
206207
207- class bsddb3ReadOnlyDBTestCase (ReadOnlyDBTestCase ):
208+ class bsddb3ReadOnlyDBTestCase (anydbmReadOnlyDBTestCase ):
208209 def setUp (self ):
209210 from roundup .backends import bsddb3
210211 # remove previous test, ignore errors
@@ -218,8 +219,9 @@ def setUp(self):
218219
219220
220221def suite ():
221- l = [unittest .makeSuite (DBTestCase , 'test' ),
222- unittest .makeSuite (ReadOnlyDBTestCase , 'test' )]
222+ l = [unittest .makeSuite (anydbmDBTestCase , 'test' ),
223+ unittest .makeSuite (anydbmReadOnlyDBTestCase , 'test' )
224+ ]
223225
224226 try :
225227 import bsddb
@@ -239,6 +241,9 @@ def suite():
239241
240242#
241243# $Log: not supported by cvs2svn $
244+ # Revision 1.10 2001/12/03 21:33:39 richard
245+ # Fixes so the tests use commit and not close
246+ #
242247# Revision 1.9 2001/12/02 05:06:16 richard
243248# . We now use weakrefs in the Classes to keep the database reference, so
244249# the close() method on the database is no longer needed.
0 commit comments