comparison test/test_db.py @ 1333:80d27b7d6db5

implemented whole-database locking
author Richard Jones <richard@users.sourceforge.net>
date Thu, 12 Dec 2002 09:31:04 +0000
parents d8de80de9fc4
children b94cc62090be
comparison
equal deleted inserted replaced
1332:e2d51ba4f6b1 1333:80d27b7d6db5
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.62 2002-11-06 11:45:25 richard Exp $ 18 # $Id: test_db.py,v 1.63 2002-12-12 09:31:04 richard Exp $
19 19
20 import unittest, os, shutil, time 20 import unittest, os, shutil, time
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, Boolean, Number 23 Interval, DatabaseError, Boolean, Number
47 db.commit() 47 db.commit()
48 48
49 class MyTestCase(unittest.TestCase): 49 class MyTestCase(unittest.TestCase):
50 def tearDown(self): 50 def tearDown(self):
51 self.db.close() 51 self.db.close()
52 if hasattr(self, 'db2'):
53 self.db2.close()
54 if os.path.exists('_test_dir'): 52 if os.path.exists('_test_dir'):
55 shutil.rmtree('_test_dir') 53 shutil.rmtree('_test_dir')
56 54
57 class config: 55 class config:
58 DATABASE='_test_dir' 56 DATABASE='_test_dir'
75 if os.path.exists(config.DATABASE): 73 if os.path.exists(config.DATABASE):
76 shutil.rmtree(config.DATABASE) 74 shutil.rmtree(config.DATABASE)
77 os.makedirs(config.DATABASE + '/files') 75 os.makedirs(config.DATABASE + '/files')
78 self.db = anydbm.Database(config, 'admin') 76 self.db = anydbm.Database(config, 'admin')
79 setupSchema(self.db, 1, anydbm) 77 setupSchema(self.db, 1, anydbm)
80 self.db2 = anydbm.Database(config, 'admin') 78
81 setupSchema(self.db2, 0, anydbm) 79 def testIDGeneration(self):
80 id1 = self.db.issue.create(title="spam", status='1')
81 id2 = self.db.issue.create(title="eggs", status='2')
82 self.assertNotEqual(id1, id2)
82 83
83 def testStringChange(self): 84 def testStringChange(self):
84 for commit in (0,1): 85 for commit in (0,1):
85 # test set & retrieve 86 # test set & retrieve
86 nid = self.db.issue.create(title="spam", status='1') 87 nid = self.db.issue.create(title="spam", status='1')
473 self.db.pack(pack_before) 474 self.db.pack(pack_before)
474 475
475 # we should have the create and last set entries now 476 # we should have the create and last set entries now
476 self.assertEqual(jlen-1, len(self.db.getjournal('issue', id))) 477 self.assertEqual(jlen-1, len(self.db.getjournal('issue', id)))
477 478
478 def testIDGeneration(self):
479 id1 = self.db.issue.create(title="spam", status='1')
480 id2 = self.db2.issue.create(title="eggs", status='2')
481 self.assertNotEqual(id1, id2)
482
483 def testSearching(self): 479 def testSearching(self):
484 self.db.file.create(content='hello', type="text/plain") 480 self.db.file.create(content='hello', type="text/plain")
485 self.db.file.create(content='world', type="text/frozz", 481 self.db.file.create(content='world', type="text/frozz",
486 comment='blah blah') 482 comment='blah blah')
487 self.db.issue.create(files=['1', '2'], title="flebble plop") 483 self.db.issue.create(files=['1', '2'], title="flebble plop")
600 if os.path.exists(config.DATABASE): 596 if os.path.exists(config.DATABASE):
601 shutil.rmtree(config.DATABASE) 597 shutil.rmtree(config.DATABASE)
602 os.makedirs(config.DATABASE + '/files') 598 os.makedirs(config.DATABASE + '/files')
603 db = anydbm.Database(config, 'admin') 599 db = anydbm.Database(config, 'admin')
604 setupSchema(db, 1, anydbm) 600 setupSchema(db, 1, anydbm)
601 db.close()
605 self.db = anydbm.Database(config) 602 self.db = anydbm.Database(config)
606 setupSchema(self.db, 0, anydbm) 603 setupSchema(self.db, 0, anydbm)
607 self.db2 = anydbm.Database(config, 'admin')
608 setupSchema(self.db2, 0, anydbm)
609 604
610 def testExceptions(self): 605 def testExceptions(self):
611 # this tests the exceptions that should be raised 606 # this tests the exceptions that should be raised
612 ar = self.assertRaises 607 ar = self.assertRaises
613 608
624 if os.path.exists(config.DATABASE): 619 if os.path.exists(config.DATABASE):
625 shutil.rmtree(config.DATABASE) 620 shutil.rmtree(config.DATABASE)
626 os.makedirs(config.DATABASE + '/files') 621 os.makedirs(config.DATABASE + '/files')
627 self.db = bsddb.Database(config, 'admin') 622 self.db = bsddb.Database(config, 'admin')
628 setupSchema(self.db, 1, bsddb) 623 setupSchema(self.db, 1, bsddb)
629 self.db2 = bsddb.Database(config, 'admin')
630 setupSchema(self.db2, 0, bsddb)
631 624
632 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): 625 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
633 def setUp(self): 626 def setUp(self):
634 from roundup.backends import bsddb 627 from roundup.backends import bsddb
635 # remove previous test, ignore errors 628 # remove previous test, ignore errors
636 if os.path.exists(config.DATABASE): 629 if os.path.exists(config.DATABASE):
637 shutil.rmtree(config.DATABASE) 630 shutil.rmtree(config.DATABASE)
638 os.makedirs(config.DATABASE + '/files') 631 os.makedirs(config.DATABASE + '/files')
639 db = bsddb.Database(config, 'admin') 632 db = bsddb.Database(config, 'admin')
640 setupSchema(db, 1, bsddb) 633 setupSchema(db, 1, bsddb)
634 db.close()
641 self.db = bsddb.Database(config) 635 self.db = bsddb.Database(config)
642 setupSchema(self.db, 0, bsddb) 636 setupSchema(self.db, 0, bsddb)
643 self.db2 = bsddb.Database(config, 'admin')
644 setupSchema(self.db2, 0, bsddb)
645 637
646 638
647 class bsddb3DBTestCase(anydbmDBTestCase): 639 class bsddb3DBTestCase(anydbmDBTestCase):
648 def setUp(self): 640 def setUp(self):
649 from roundup.backends import bsddb3 641 from roundup.backends import bsddb3
651 if os.path.exists(config.DATABASE): 643 if os.path.exists(config.DATABASE):
652 shutil.rmtree(config.DATABASE) 644 shutil.rmtree(config.DATABASE)
653 os.makedirs(config.DATABASE + '/files') 645 os.makedirs(config.DATABASE + '/files')
654 self.db = bsddb3.Database(config, 'admin') 646 self.db = bsddb3.Database(config, 'admin')
655 setupSchema(self.db, 1, bsddb3) 647 setupSchema(self.db, 1, bsddb3)
656 self.db2 = bsddb3.Database(config, 'admin')
657 setupSchema(self.db2, 0, bsddb3)
658 648
659 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): 649 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
660 def setUp(self): 650 def setUp(self):
661 from roundup.backends import bsddb3 651 from roundup.backends import bsddb3
662 # remove previous test, ignore errors 652 # remove previous test, ignore errors
663 if os.path.exists(config.DATABASE): 653 if os.path.exists(config.DATABASE):
664 shutil.rmtree(config.DATABASE) 654 shutil.rmtree(config.DATABASE)
665 os.makedirs(config.DATABASE + '/files') 655 os.makedirs(config.DATABASE + '/files')
666 db = bsddb3.Database(config, 'admin') 656 db = bsddb3.Database(config, 'admin')
667 setupSchema(db, 1, bsddb3) 657 setupSchema(db, 1, bsddb3)
658 db.close()
668 self.db = bsddb3.Database(config) 659 self.db = bsddb3.Database(config)
669 setupSchema(self.db, 0, bsddb3) 660 setupSchema(self.db, 0, bsddb3)
670 self.db2 = bsddb3.Database(config, 'admin')
671 setupSchema(self.db2, 0, bsddb3)
672 661
673 662
674 class gadflyDBTestCase(anydbmDBTestCase): 663 class gadflyDBTestCase(anydbmDBTestCase):
675 ''' Gadfly doesn't support multiple connections to the one local 664 ''' Gadfly doesn't support multiple connections to the one local
676 database 665 database
682 shutil.rmtree(config.DATABASE) 671 shutil.rmtree(config.DATABASE)
683 config.GADFLY_DATABASE = ('test', config.DATABASE) 672 config.GADFLY_DATABASE = ('test', config.DATABASE)
684 os.makedirs(config.DATABASE + '/files') 673 os.makedirs(config.DATABASE + '/files')
685 self.db = gadfly.Database(config, 'admin') 674 self.db = gadfly.Database(config, 'admin')
686 setupSchema(self.db, 1, gadfly) 675 setupSchema(self.db, 1, gadfly)
687
688 def testIDGeneration(self):
689 id1 = self.db.issue.create(title="spam", status='1')
690 id2 = self.db.issue.create(title="eggs", status='2')
691 self.assertNotEqual(id1, id2)
692 676
693 def testFilteringString(self): 677 def testFilteringString(self):
694 ae, filt = self.filteringSetup() 678 ae, filt = self.filteringSetup()
695 ae(filt(None, {'title': 'issue one'}, ('+','id'), (None,None)), ['1']) 679 ae(filt(None, {'title': 'issue one'}, ('+','id'), (None,None)), ['1'])
696 # XXX gadfly can't do substring LIKE searches 680 # XXX gadfly can't do substring LIKE searches
705 shutil.rmtree(config.DATABASE) 689 shutil.rmtree(config.DATABASE)
706 config.GADFLY_DATABASE = ('test', config.DATABASE) 690 config.GADFLY_DATABASE = ('test', config.DATABASE)
707 os.makedirs(config.DATABASE + '/files') 691 os.makedirs(config.DATABASE + '/files')
708 db = gadfly.Database(config, 'admin') 692 db = gadfly.Database(config, 'admin')
709 setupSchema(db, 1, gadfly) 693 setupSchema(db, 1, gadfly)
694 db.close()
710 self.db = gadfly.Database(config) 695 self.db = gadfly.Database(config)
711 setupSchema(self.db, 0, gadfly) 696 setupSchema(self.db, 0, gadfly)
712 697
713 698
714 class sqliteDBTestCase(anydbmDBTestCase): 699 class sqliteDBTestCase(anydbmDBTestCase):
731 if os.path.exists(config.DATABASE): 716 if os.path.exists(config.DATABASE):
732 shutil.rmtree(config.DATABASE) 717 shutil.rmtree(config.DATABASE)
733 os.makedirs(config.DATABASE + '/files') 718 os.makedirs(config.DATABASE + '/files')
734 db = sqlite.Database(config, 'admin') 719 db = sqlite.Database(config, 'admin')
735 setupSchema(db, 1, sqlite) 720 setupSchema(db, 1, sqlite)
721 db.close()
736 self.db = sqlite.Database(config) 722 self.db = sqlite.Database(config)
737 setupSchema(self.db, 0, sqlite) 723 setupSchema(self.db, 0, sqlite)
738 724
739 725
740 class metakitDBTestCase(anydbmDBTestCase): 726 class metakitDBTestCase(anydbmDBTestCase):
746 if os.path.exists(config.DATABASE): 732 if os.path.exists(config.DATABASE):
747 shutil.rmtree(config.DATABASE) 733 shutil.rmtree(config.DATABASE)
748 os.makedirs(config.DATABASE + '/files') 734 os.makedirs(config.DATABASE + '/files')
749 self.db = metakit.Database(config, 'admin') 735 self.db = metakit.Database(config, 'admin')
750 setupSchema(self.db, 1, metakit) 736 setupSchema(self.db, 1, metakit)
751
752 def testIDGeneration(self):
753 id1 = self.db.issue.create(title="spam", status='1')
754 id2 = self.db.issue.create(title="eggs", status='2')
755 self.assertNotEqual(id1, id2)
756 737
757 def testTransactions(self): 738 def testTransactions(self):
758 # remember the number of items we started 739 # remember the number of items we started
759 num_issues = len(self.db.issue.list()) 740 num_issues = len(self.db.issue.list())
760 self.db.issue.create(title="don't commit me!", status='1') 741 self.db.issue.create(title="don't commit me!", status='1')
794 if os.path.exists(config.DATABASE): 775 if os.path.exists(config.DATABASE):
795 shutil.rmtree(config.DATABASE) 776 shutil.rmtree(config.DATABASE)
796 os.makedirs(config.DATABASE + '/files') 777 os.makedirs(config.DATABASE + '/files')
797 db = metakit.Database(config, 'admin') 778 db = metakit.Database(config, 'admin')
798 setupSchema(db, 1, metakit) 779 setupSchema(db, 1, metakit)
780 db.close()
799 self.db = metakit.Database(config) 781 self.db = metakit.Database(config)
800 setupSchema(self.db, 0, metakit) 782 setupSchema(self.db, 0, metakit)
801 783
802 def suite(): 784 def suite():
803 l = [ 785 l = [

Roundup Issue Tracker: http://roundup-tracker.org/