Mercurial > p > roundup > code
comparison test/test_db.py @ 858:2dd862af72ee
all storage-specific code (ie. backend) is now implemented by the backends
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sun, 14 Jul 2002 02:05:54 +0000 |
| parents | 3cdfa5d86cec |
| children | eb924e614934 |
comparison
equal
deleted
inserted
replaced
| 857:6dd691e37aa8 | 858:2dd862af72ee |
|---|---|
| 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.26 2002-07-11 01:11:03 richard Exp $ | 18 # $Id: test_db.py,v 1.27 2002-07-14 02:05:54 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, DatabaseError, Class | 23 Interval, DatabaseError |
| 24 from roundup.roundupdb import FileClass | |
| 25 from roundup import date, password | 24 from roundup import date, password |
| 26 from roundup.indexer import Indexer | 25 from roundup.indexer import Indexer |
| 27 | 26 |
| 28 def setupSchema(db, create, Class, FileClass): | 27 def setupSchema(db, create, module): |
| 29 status = Class(db, "status", name=String()) | 28 status = module.Class(db, "status", name=String()) |
| 30 status.setkey("name") | 29 status.setkey("name") |
| 31 user = Class(db, "user", username=String(), password=Password()) | 30 user = module.Class(db, "user", username=String(), password=Password()) |
| 32 file = FileClass(db, "file", name=String(), type=String(), | 31 file = module.FileClass(db, "file", name=String(), type=String(), |
| 33 comment=String(indexme="yes")) | 32 comment=String(indexme="yes")) |
| 34 issue = Class(db, "issue", title=String(indexme="yes"), | 33 issue = module.IssueClass(db, "issue", title=String(indexme="yes"), |
| 35 status=Link("status"), nosy=Multilink("user"), deadline=Date(), | 34 status=Link("status"), nosy=Multilink("user"), deadline=Date(), |
| 36 foo=Interval(), files=Multilink("file")) | 35 foo=Interval(), files=Multilink("file")) |
| 37 db.post_init() | 36 db.post_init() |
| 38 if create: | 37 if create: |
| 39 status.create(name="unread") | 38 status.create(name="unread") |
| 67 # remove previous test, ignore errors | 66 # remove previous test, ignore errors |
| 68 if os.path.exists(config.DATABASE): | 67 if os.path.exists(config.DATABASE): |
| 69 shutil.rmtree(config.DATABASE) | 68 shutil.rmtree(config.DATABASE) |
| 70 os.makedirs(config.DATABASE + '/files') | 69 os.makedirs(config.DATABASE + '/files') |
| 71 self.db = anydbm.Database(config, 'test') | 70 self.db = anydbm.Database(config, 'test') |
| 72 setupSchema(self.db, 1, Class, FileClass) | 71 setupSchema(self.db, 1, anydbm) |
| 73 self.db2 = anydbm.Database(config, 'test') | 72 self.db2 = anydbm.Database(config, 'test') |
| 74 setupSchema(self.db2, 0, Class, FileClass) | 73 setupSchema(self.db2, 0, anydbm) |
| 75 | 74 |
| 76 def testStringChange(self): | 75 def testStringChange(self): |
| 77 self.db.issue.create(title="spam", status='1') | 76 self.db.issue.create(title="spam", status='1') |
| 78 self.assertEqual(self.db.issue.get('1', 'title'), 'spam') | 77 self.assertEqual(self.db.issue.get('1', 'title'), 'spam') |
| 79 self.db.issue.set('1', title='eggs') | 78 self.db.issue.set('1', title='eggs') |
| 115 self.db.issue.create(title="spam", status='1') | 114 self.db.issue.create(title="spam", status='1') |
| 116 self.db.issue.addprop(fixer=Link("user")) | 115 self.db.issue.addprop(fixer=Link("user")) |
| 117 props = self.db.issue.getprops() | 116 props = self.db.issue.getprops() |
| 118 keys = props.keys() | 117 keys = props.keys() |
| 119 keys.sort() | 118 keys.sort() |
| 120 self.assertEqual(keys, ['deadline', 'files', 'fixer', 'foo', 'id', | 119 self.assertEqual(keys, ['activity', 'creation', 'creator', 'deadline', |
| 121 'nosy', 'status', 'title']) | 120 'files', 'fixer', 'foo', 'id', 'messages', 'nosy', 'status', |
| 121 'superseder', 'title']) | |
| 122 self.assertEqual(self.db.issue.get('1', "fixer"), None) | 122 self.assertEqual(self.db.issue.get('1', "fixer"), None) |
| 123 | 123 |
| 124 def testRetire(self): | 124 def testRetire(self): |
| 125 self.db.issue.create(title="spam", status='1') | 125 self.db.issue.create(title="spam", status='1') |
| 126 b = self.db.status.get('1', 'name') | 126 b = self.db.status.get('1', 'name') |
| 249 self.assertEqual(nodeid, '1') | 249 self.assertEqual(nodeid, '1') |
| 250 self.assertEqual(journaltag, 'test') | 250 self.assertEqual(journaltag, 'test') |
| 251 self.assertEqual(action, 'create') | 251 self.assertEqual(action, 'create') |
| 252 keys = params.keys() | 252 keys = params.keys() |
| 253 keys.sort() | 253 keys.sort() |
| 254 self.assertEqual(keys, ['deadline', 'files', 'fixer', 'foo', 'nosy', | 254 self.assertEqual(keys, ['deadline', 'files', 'fixer', 'foo', |
| 255 'status', 'title']) | 255 'messages', 'nosy', 'status', 'superseder', 'title']) |
| 256 self.assertEqual(None,params['deadline']) | 256 self.assertEqual(None,params['deadline']) |
| 257 self.assertEqual(None,params['fixer']) | 257 self.assertEqual(None,params['fixer']) |
| 258 self.assertEqual(None,params['foo']) | 258 self.assertEqual(None,params['foo']) |
| 259 self.assertEqual([],params['nosy']) | 259 self.assertEqual([],params['nosy']) |
| 260 self.assertEqual('1',params['status']) | 260 self.assertEqual('1',params['status']) |
| 345 # remove previous test, ignore errors | 345 # remove previous test, ignore errors |
| 346 if os.path.exists(config.DATABASE): | 346 if os.path.exists(config.DATABASE): |
| 347 shutil.rmtree(config.DATABASE) | 347 shutil.rmtree(config.DATABASE) |
| 348 os.makedirs(config.DATABASE + '/files') | 348 os.makedirs(config.DATABASE + '/files') |
| 349 db = anydbm.Database(config, 'test') | 349 db = anydbm.Database(config, 'test') |
| 350 setupSchema(db, 1, Class, FileClass) | 350 setupSchema(db, 1, anydbm) |
| 351 self.db = anydbm.Database(config) | 351 self.db = anydbm.Database(config) |
| 352 setupSchema(self.db, 0, Class, FileClass) | 352 setupSchema(self.db, 0, anydbm) |
| 353 self.db2 = anydbm.Database(config, 'test') | 353 self.db2 = anydbm.Database(config, 'test') |
| 354 setupSchema(self.db2, 0, Class, FileClass) | 354 setupSchema(self.db2, 0, anydbm) |
| 355 | 355 |
| 356 def testExceptions(self): | 356 def testExceptions(self): |
| 357 ' make sure exceptions are raised on writes to a read-only db ' | 357 ' make sure exceptions are raised on writes to a read-only db ' |
| 358 # this tests the exceptions that should be raised | 358 # this tests the exceptions that should be raised |
| 359 ar = self.assertRaises | 359 ar = self.assertRaises |
| 370 # remove previous test, ignore errors | 370 # remove previous test, ignore errors |
| 371 if os.path.exists(config.DATABASE): | 371 if os.path.exists(config.DATABASE): |
| 372 shutil.rmtree(config.DATABASE) | 372 shutil.rmtree(config.DATABASE) |
| 373 os.makedirs(config.DATABASE + '/files') | 373 os.makedirs(config.DATABASE + '/files') |
| 374 self.db = bsddb.Database(config, 'test') | 374 self.db = bsddb.Database(config, 'test') |
| 375 setupSchema(self.db, 1, Class, FileClass) | 375 setupSchema(self.db, 1, bsddb) |
| 376 self.db2 = bsddb.Database(config, 'test') | 376 self.db2 = bsddb.Database(config, 'test') |
| 377 setupSchema(self.db2, 0, Class, FileClass) | 377 setupSchema(self.db2, 0, bsddb) |
| 378 | 378 |
| 379 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): | 379 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): |
| 380 def setUp(self): | 380 def setUp(self): |
| 381 from roundup.backends import bsddb | 381 from roundup.backends import bsddb |
| 382 # remove previous test, ignore errors | 382 # remove previous test, ignore errors |
| 383 if os.path.exists(config.DATABASE): | 383 if os.path.exists(config.DATABASE): |
| 384 shutil.rmtree(config.DATABASE) | 384 shutil.rmtree(config.DATABASE) |
| 385 os.makedirs(config.DATABASE + '/files') | 385 os.makedirs(config.DATABASE + '/files') |
| 386 db = bsddb.Database(config, 'test') | 386 db = bsddb.Database(config, 'test') |
| 387 setupSchema(db, 1, Class, FileClass) | 387 setupSchema(db, 1, bsddb) |
| 388 self.db = bsddb.Database(config) | 388 self.db = bsddb.Database(config) |
| 389 setupSchema(self.db, 0, Class, FileClass) | 389 setupSchema(self.db, 0, bsddb) |
| 390 self.db2 = bsddb.Database(config, 'test') | 390 self.db2 = bsddb.Database(config, 'test') |
| 391 setupSchema(self.db2, 0, Class, FileClass) | 391 setupSchema(self.db2, 0, bsddb) |
| 392 | 392 |
| 393 | 393 |
| 394 class bsddb3DBTestCase(anydbmDBTestCase): | 394 class bsddb3DBTestCase(anydbmDBTestCase): |
| 395 def setUp(self): | 395 def setUp(self): |
| 396 from roundup.backends import bsddb3 | 396 from roundup.backends import bsddb3 |
| 397 # remove previous test, ignore errors | 397 # remove previous test, ignore errors |
| 398 if os.path.exists(config.DATABASE): | 398 if os.path.exists(config.DATABASE): |
| 399 shutil.rmtree(config.DATABASE) | 399 shutil.rmtree(config.DATABASE) |
| 400 os.makedirs(config.DATABASE + '/files') | 400 os.makedirs(config.DATABASE + '/files') |
| 401 self.db = bsddb3.Database(config, 'test') | 401 self.db = bsddb3.Database(config, 'test') |
| 402 setupSchema(self.db, 1, Class, FileClass) | 402 setupSchema(self.db, 1, bsddb3) |
| 403 self.db2 = bsddb3.Database(config, 'test') | 403 self.db2 = bsddb3.Database(config, 'test') |
| 404 setupSchema(self.db2, 0, Class, FileClass) | 404 setupSchema(self.db2, 0, bsddb3) |
| 405 | 405 |
| 406 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): | 406 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): |
| 407 def setUp(self): | 407 def setUp(self): |
| 408 from roundup.backends import bsddb3 | 408 from roundup.backends import bsddb3 |
| 409 # remove previous test, ignore errors | 409 # remove previous test, ignore errors |
| 410 if os.path.exists(config.DATABASE): | 410 if os.path.exists(config.DATABASE): |
| 411 shutil.rmtree(config.DATABASE) | 411 shutil.rmtree(config.DATABASE) |
| 412 os.makedirs(config.DATABASE + '/files') | 412 os.makedirs(config.DATABASE + '/files') |
| 413 db = bsddb3.Database(config, 'test') | 413 db = bsddb3.Database(config, 'test') |
| 414 setupSchema(db, 1, Class, FileClass) | 414 setupSchema(db, 1, bsddb3) |
| 415 self.db = bsddb3.Database(config) | 415 self.db = bsddb3.Database(config) |
| 416 setupSchema(self.db, 0, Class, FileClass) | 416 setupSchema(self.db, 0, bsddb3) |
| 417 self.db2 = bsddb3.Database(config, 'test') | 417 self.db2 = bsddb3.Database(config, 'test') |
| 418 setupSchema(self.db2, 0, Class, FileClass) | 418 setupSchema(self.db2, 0, bsddb3) |
| 419 | 419 |
| 420 | 420 |
| 421 class metakitDBTestCase(anydbmDBTestCase): | 421 class metakitDBTestCase(anydbmDBTestCase): |
| 422 def setUp(self): | 422 def setUp(self): |
| 423 from roundup.backends import metakit | 423 from roundup.backends import metakit |
| 426 # remove previous test, ignore errors | 426 # remove previous test, ignore errors |
| 427 if os.path.exists(config.DATABASE): | 427 if os.path.exists(config.DATABASE): |
| 428 shutil.rmtree(config.DATABASE) | 428 shutil.rmtree(config.DATABASE) |
| 429 os.makedirs(config.DATABASE + '/files') | 429 os.makedirs(config.DATABASE + '/files') |
| 430 self.db = metakit.Database(config, 'test') | 430 self.db = metakit.Database(config, 'test') |
| 431 setupSchema(self.db, 1, metakit.Class, metakit.FileClass) | 431 setupSchema(self.db, 1, metakit) |
| 432 self.db2 = metakit.Database(config, 'test') | 432 self.db2 = metakit.Database(config, 'test') |
| 433 setupSchema(self.db2, 0, metakit.Class, metakit.FileClass) | 433 setupSchema(self.db2, 0, metakit) |
| 434 | 434 |
| 435 def testTransactions(self): | 435 def testTransactions(self): |
| 436 # remember the number of items we started | 436 # remember the number of items we started |
| 437 num_issues = len(self.db.issue.list()) | 437 num_issues = len(self.db.issue.list()) |
| 438 self.db.issue.create(title="don't commit me!", status='1') | 438 self.db.issue.create(title="don't commit me!", status='1') |
| 478 # remove previous test, ignore errors | 478 # remove previous test, ignore errors |
| 479 if os.path.exists(config.DATABASE): | 479 if os.path.exists(config.DATABASE): |
| 480 shutil.rmtree(config.DATABASE) | 480 shutil.rmtree(config.DATABASE) |
| 481 os.makedirs(config.DATABASE + '/files') | 481 os.makedirs(config.DATABASE + '/files') |
| 482 db = metakit.Database(config, 'test') | 482 db = metakit.Database(config, 'test') |
| 483 setupSchema(db, 1, metakit.Class, metakit.FileClass) | 483 setupSchema(db, 1, metakit) |
| 484 self.db = metakit.Database(config) | 484 self.db = metakit.Database(config) |
| 485 setupSchema(self.db, 0, metakit.Class, metakit.FileClass) | 485 setupSchema(self.db, 0, metakit) |
| 486 self.db2 = metakit.Database(config, 'test') | 486 self.db2 = metakit.Database(config, 'test') |
| 487 setupSchema(self.db2, 0, metakit.Class, metakit.FileClass) | 487 setupSchema(self.db2, 0, metakit) |
| 488 | 488 |
| 489 def suite(): | 489 def suite(): |
| 490 l = [ | 490 l = [ |
| 491 unittest.makeSuite(anydbmDBTestCase, 'test'), | 491 unittest.makeSuite(anydbmDBTestCase, 'test'), |
| 492 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') | 492 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') |
| 515 | 515 |
| 516 return unittest.TestSuite(l) | 516 return unittest.TestSuite(l) |
| 517 | 517 |
| 518 # | 518 # |
| 519 # $Log: not supported by cvs2svn $ | 519 # $Log: not supported by cvs2svn $ |
| 520 # Revision 1.26 2002/07/11 01:11:03 richard | |
| 521 # Added metakit backend to the db tests and fixed the more easily fixable test | |
| 522 # failures. | |
| 523 # | |
| 520 # Revision 1.25 2002/07/09 04:19:09 richard | 524 # Revision 1.25 2002/07/09 04:19:09 richard |
| 521 # Added reindex command to roundup-admin. | 525 # Added reindex command to roundup-admin. |
| 522 # Fixed reindex on first access. | 526 # Fixed reindex on first access. |
| 523 # Also fixed reindexing of entries that change. | 527 # Also fixed reindexing of entries that change. |
| 524 # | 528 # |
