1 #
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/)
3 # This module is free software, and you may redistribute it and/or modify
4 # under the same terms as Python, so long as this copyright message and
5 # disclaimer are retained in their original form.
6 #
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE
10 # POSSIBILITY OF SUCH DAMAGE.
11 #
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING,
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"
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
17 #
18 # $Id: test_init.py,v 1.17 2002-09-10 01:27:13 richard Exp $
20 import unittest, os, shutil, errno, imp, sys
22 from roundup import init
24 class MyTestCase(unittest.TestCase):
25 count = 0
26 def setUp(self):
27 MyTestCase.count = MyTestCase.count + 1
28 self.dirname = '_test_init_%s'%self.count
29 try:
30 shutil.rmtree(self.dirname)
31 except OSError, error:
32 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
34 def tearDown(self):
35 try:
36 shutil.rmtree(self.dirname)
37 except OSError, error:
38 if error.errno not in (errno.ENOENT, errno.ESRCH): raise
40 class ClassicTestCase(MyTestCase):
41 backend = 'anydbm'
42 def testCreation(self):
43 ae = self.assertEqual
45 # create the instance
46 init.install(self.dirname, 'classic', self.backend)
47 init.initialise(self.dirname, 'sekrit')
49 # check we can load the package
50 instance = imp.load_package(self.dirname, self.dirname)
52 # and open the database
53 db = instance.open()
55 # check the basics of the schema and initial data set
56 l = db.priority.list()
57 ae(l, ['1', '2', '3', '4', '5'])
58 l = db.status.list()
59 ae(l, ['1', '2', '3', '4', '5', '6', '7', '8'])
60 l = db.keyword.list()
61 ae(l, [])
62 l = db.user.list()
63 ae(l, ['1', '2'])
64 l = db.msg.list()
65 ae(l, [])
66 l = db.file.list()
67 ae(l, [])
68 l = db.issue.list()
69 ae(l, [])
71 class bsddbClassicTestCase(ClassicTestCase):
72 backend = 'bsddb'
74 class bsddb3ClassicTestCase(ClassicTestCase):
75 backend = 'bsddb3'
77 class metakitClassicTestCase(ClassicTestCase):
78 backend = 'metakit'
80 def suite():
81 l = [
82 unittest.makeSuite(ClassicTestCase, 'test'),
83 ]
85 try:
86 import bsddb
87 l.append(unittest.makeSuite(bsddbClassicTestCase, 'test'))
88 except:
89 print 'bsddb module not found, skipping bsddb DBTestCase'
91 try:
92 import bsddb3
93 l.append(unittest.makeSuite(bsddb3ClassicTestCase, 'test'))
94 except:
95 print 'bsddb3 module not found, skipping bsddb3 DBTestCase'
97 try:
98 import metakit
99 l.append(unittest.makeSuite(metakitClassicTestCase, 'test'))
100 except:
101 print 'metakit module not found, skipping metakit DBTestCase'
103 return unittest.TestSuite(l)
105 # vim: set filetype=python ts=4 sw=4 et si