Mercurial > p > roundup > code
comparison test/test_db.py @ 441:698534628072
Added transaction tests to test_db
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 10 Dec 2001 23:17:20 +0000 |
| parents | f97415cccb9d |
| children | b579418f7ed1 |
comparison
equal
deleted
inserted
replaced
| 440:de5bf4191f11 | 441:698534628072 |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 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 $ |
| 19 | 19 |
| 20 import unittest, os, shutil | 20 import unittest, os, shutil |
| 21 | 21 |
| 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ | 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ |
| 23 Interval, Class, DatabaseError | 23 Interval, Class, DatabaseError |
| 31 status.create(name="testing") | 31 status.create(name="testing") |
| 32 status.create(name="resolved") | 32 status.create(name="resolved") |
| 33 Class(db, "user", username=String(), password=Password()) | 33 Class(db, "user", username=String(), password=Password()) |
| 34 Class(db, "issue", title=String(), status=Link("status"), | 34 Class(db, "issue", title=String(), status=Link("status"), |
| 35 nosy=Multilink("user")) | 35 nosy=Multilink("user")) |
| 36 | 36 db.commit() |
| 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 | |
| 47 | 37 |
| 48 class MyTestCase(unittest.TestCase): | 38 class MyTestCase(unittest.TestCase): |
| 49 # def defaultTestResult(self): | |
| 50 # return MyTestResult() | |
| 51 def tearDown(self): | 39 def tearDown(self): |
| 52 if self.db is not None: | 40 if os.path.exists('_test_dir'): |
| 53 shutil.rmtree('_test_dir') | 41 shutil.rmtree('_test_dir') |
| 54 | 42 |
| 55 class DBTestCase(MyTestCase): | 43 class anydbmDBTestCase(MyTestCase): |
| 56 def setUp(self): | 44 def setUp(self): |
| 57 from roundup.backends import anydbm | 45 from roundup.backends import anydbm |
| 58 # remove previous test, ignore errors | 46 # remove previous test, ignore errors |
| 59 if os.path.exists('_test_dir'): | 47 if os.path.exists('_test_dir'): |
| 60 shutil.rmtree('_test_dir') | 48 shutil.rmtree('_test_dir') |
| 80 self.db.issue.find(status = self.db.status.lookup("in-progress")) | 68 self.db.issue.find(status = self.db.status.lookup("in-progress")) |
| 81 self.db.commit() | 69 self.db.commit() |
| 82 self.db.issue.history('5') | 70 self.db.issue.history('5') |
| 83 self.db.status.history('1') | 71 self.db.status.history('1') |
| 84 self.db.status.history('2') | 72 self.db.status.history('2') |
| 73 | |
| 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())) | |
| 85 | 86 |
| 86 def testExceptions(self): | 87 def testExceptions(self): |
| 87 # this tests the exceptions that should be raised | 88 # this tests the exceptions that should be raised |
| 88 ar = self.assertRaises | 89 ar = self.assertRaises |
| 89 | 90 |
| 147 | 148 |
| 148 def testRetire(self): | 149 def testRetire(self): |
| 149 pass | 150 pass |
| 150 | 151 |
| 151 | 152 |
| 152 class ReadOnlyDBTestCase(MyTestCase): | 153 class anydbmReadOnlyDBTestCase(MyTestCase): |
| 153 def setUp(self): | 154 def setUp(self): |
| 154 from roundup.backends import anydbm | 155 from roundup.backends import anydbm |
| 155 # remove previous test, ignore errors | 156 # remove previous test, ignore errors |
| 156 if os.path.exists('_test_dir'): | 157 if os.path.exists('_test_dir'): |
| 157 shutil.rmtree('_test_dir') | 158 shutil.rmtree('_test_dir') |
| 169 ar(DatabaseError, self.db.status.create, name="foo") | 170 ar(DatabaseError, self.db.status.create, name="foo") |
| 170 ar(DatabaseError, self.db.status.set, '1', name="foo") | 171 ar(DatabaseError, self.db.status.set, '1', name="foo") |
| 171 ar(DatabaseError, self.db.status.retire, '1') | 172 ar(DatabaseError, self.db.status.retire, '1') |
| 172 | 173 |
| 173 | 174 |
| 174 class bsddbDBTestCase(DBTestCase): | 175 class bsddbDBTestCase(anydbmDBTestCase): |
| 175 def setUp(self): | 176 def setUp(self): |
| 176 from roundup.backends import bsddb | 177 from roundup.backends import bsddb |
| 177 # remove previous test, ignore errors | 178 # remove previous test, ignore errors |
| 178 if os.path.exists('_test_dir'): | 179 if os.path.exists('_test_dir'): |
| 179 shutil.rmtree('_test_dir') | 180 shutil.rmtree('_test_dir') |
| 180 os.mkdir('_test_dir') | 181 os.mkdir('_test_dir') |
| 181 self.db = bsddb.Database('_test_dir', 'test') | 182 self.db = bsddb.Database('_test_dir', 'test') |
| 182 setupSchema(self.db, 1) | 183 setupSchema(self.db, 1) |
| 183 | 184 |
| 184 class bsddbReadOnlyDBTestCase(ReadOnlyDBTestCase): | 185 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): |
| 185 def setUp(self): | 186 def setUp(self): |
| 186 from roundup.backends import bsddb | 187 from roundup.backends import bsddb |
| 187 # remove previous test, ignore errors | 188 # remove previous test, ignore errors |
| 188 if os.path.exists('_test_dir'): | 189 if os.path.exists('_test_dir'): |
| 189 shutil.rmtree('_test_dir') | 190 shutil.rmtree('_test_dir') |
| 192 setupSchema(db, 1) | 193 setupSchema(db, 1) |
| 193 self.db = bsddb.Database('_test_dir') | 194 self.db = bsddb.Database('_test_dir') |
| 194 setupSchema(self.db, 0) | 195 setupSchema(self.db, 0) |
| 195 | 196 |
| 196 | 197 |
| 197 class bsddb3DBTestCase(DBTestCase): | 198 class bsddb3DBTestCase(anydbmDBTestCase): |
| 198 def setUp(self): | 199 def setUp(self): |
| 199 from roundup.backends import bsddb3 | 200 from roundup.backends import bsddb3 |
| 200 # remove previous test, ignore errors | 201 # remove previous test, ignore errors |
| 201 if os.path.exists('_test_dir'): | 202 if os.path.exists('_test_dir'): |
| 202 shutil.rmtree('_test_dir') | 203 shutil.rmtree('_test_dir') |
| 203 os.mkdir('_test_dir') | 204 os.mkdir('_test_dir') |
| 204 self.db = bsddb3.Database('_test_dir', 'test') | 205 self.db = bsddb3.Database('_test_dir', 'test') |
| 205 setupSchema(self.db, 1) | 206 setupSchema(self.db, 1) |
| 206 | 207 |
| 207 class bsddb3ReadOnlyDBTestCase(ReadOnlyDBTestCase): | 208 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): |
| 208 def setUp(self): | 209 def setUp(self): |
| 209 from roundup.backends import bsddb3 | 210 from roundup.backends import bsddb3 |
| 210 # remove previous test, ignore errors | 211 # remove previous test, ignore errors |
| 211 if os.path.exists('_test_dir'): | 212 if os.path.exists('_test_dir'): |
| 212 shutil.rmtree('_test_dir') | 213 shutil.rmtree('_test_dir') |
| 216 self.db = bsddb3.Database('_test_dir') | 217 self.db = bsddb3.Database('_test_dir') |
| 217 setupSchema(self.db, 0) | 218 setupSchema(self.db, 0) |
| 218 | 219 |
| 219 | 220 |
| 220 def suite(): | 221 def suite(): |
| 221 l = [unittest.makeSuite(DBTestCase, 'test'), | 222 l = [unittest.makeSuite(anydbmDBTestCase, 'test'), |
| 222 unittest.makeSuite(ReadOnlyDBTestCase, 'test')] | 223 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') |
| 224 ] | |
| 223 | 225 |
| 224 try: | 226 try: |
| 225 import bsddb | 227 import bsddb |
| 226 l.append(unittest.makeSuite(bsddbDBTestCase, 'test')) | 228 l.append(unittest.makeSuite(bsddbDBTestCase, 'test')) |
| 227 l.append(unittest.makeSuite(bsddbReadOnlyDBTestCase, 'test')) | 229 l.append(unittest.makeSuite(bsddbReadOnlyDBTestCase, 'test')) |
| 237 | 239 |
| 238 return unittest.TestSuite(l) | 240 return unittest.TestSuite(l) |
| 239 | 241 |
| 240 # | 242 # |
| 241 # $Log: not supported by cvs2svn $ | 243 # $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 # | |
| 242 # Revision 1.9 2001/12/02 05:06:16 richard | 247 # Revision 1.9 2001/12/02 05:06:16 richard |
| 243 # . We now use weakrefs in the Classes to keep the database reference, so | 248 # . We now use weakrefs in the Classes to keep the database reference, so |
| 244 # the close() method on the database is no longer needed. | 249 # the close() method on the database is no longer needed. |
| 245 # I bumped the minimum python requirement up to 2.1 accordingly. | 250 # I bumped the minimum python requirement up to 2.1 accordingly. |
| 246 # . #487480 ] roundup-server | 251 # . #487480 ] roundup-server |
