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.7 2001-10-28 22:51:38 richard Exp $
20 import unittest, os, shutil, errno, imp, sys
22 from roundup.init import init
24 class MyTestCase(unittest.TestCase):
25 count = 0
26 def setUp(self):
27 MyTestCase.count = MyTestCase.count + 1
28 self.dirname = '_test_%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(self.dirname, 'classic', self.backend, 'sekrit')
48 # check we can load the package
49 instance = imp.load_package(self.dirname, self.dirname)
51 # and open the database
52 db = instance.open()
54 # check the basics of the schema and initial data set
55 l = db.priority.list()
56 ae(l, ['1', '2', '3', '4', '5'])
57 l = db.status.list()
58 ae(l, ['1', '2', '3', '4', '5', '6', '7', '8'])
59 l = db.keyword.list()
60 ae(l, [])
61 l = db.user.list()
62 ae(l, ['1'])
63 l = db.msg.list()
64 ae(l, [])
65 l = db.file.list()
66 ae(l, [])
67 l = db.issue.list()
68 ae(l, [])
70 class ExtendedTestCase(MyTestCase):
71 backend = 'anydbm'
72 def testCreation(self):
73 ae = self.assertEqual
75 # create the instance
76 init(self.dirname, 'extended', self.backend, 'sekrit')
78 # check we can load the package
79 instance = imp.load_package(self.dirname, self.dirname)
81 # and open the database
82 db = instance.open()
84 # check the basics of the schema and initial data set
85 l = db.priority.list()
86 ae(l, ['1', '2', '3', '4'])
87 l = db.status.list()
88 ae(l, ['1', '2', '3', '4', '5', '6', '7', '8'])
89 l = db.keyword.list()
90 ae(l, [])
91 l = db.user.list()
92 ae(l, ['1'])
93 l = db.msg.list()
94 ae(l, [])
95 l = db.file.list()
96 ae(l, [])
97 l = db.issue.list()
98 ae(l, [])
99 l = db.support.list()
100 ae(l, [])
101 l = db.rate.list()
102 ae(l, ['1', '2', '3'])
103 l = db.source.list()
104 ae(l, ['1', '2', '3', '4'])
105 l = db.platform.list()
106 ae(l, ['1', '2', '3'])
107 l = db.timelog.list()
108 ae(l, [])
110 def suite():
111 l = [unittest.makeSuite(ClassicTestCase, 'test'),
112 unittest.makeSuite(ExtendedTestCase, 'test')]
113 try:
114 import bsddb
115 x = ClassicTestCase
116 x.backend = 'bsddb'
117 l.append(unittest.makeSuite(x, 'test'))
118 x = ExtendedTestCase
119 x.backend = 'bsddb'
120 l.append(unittest.makeSuite(x, 'test'))
121 except:
122 print 'bsddb module not found, skipping bsddb DBTestCase'
124 # try:
125 # import bsddb3
126 # x = ClassicTestCase
127 # x.backend = 'bsddb3'
128 # l.append(unittest.makeSuite(x, 'test'))
129 # x = ExtendedTestCase
130 # x.backend = 'bsddb3'
131 # l.append(unittest.makeSuite(x, 'test'))
132 # except:
133 # print 'bsddb3 module not found, skipping bsddb3 DBTestCase'
135 return unittest.TestSuite(l)
137 #
138 # $Log: not supported by cvs2svn $
139 # Revision 1.6 2001/09/29 23:48:06 richard
140 # Bug fix for test_init on Windows.
141 # More documenation!!
142 #
143 # Revision 1.5 2001/08/29 06:23:59 richard
144 # Disabled the bsddb3 module entirely in the unit testing. See CHANGES for
145 # details.
146 #
147 # Revision 1.4 2001/08/07 00:24:43 richard
148 # stupid typo
149 #
150 # Revision 1.3 2001/08/07 00:15:51 richard
151 # Added the copyright/license notice to (nearly) all files at request of
152 # Bizar Software.
153 #
154 # Revision 1.2 2001/08/05 07:45:27 richard
155 # Added tests for instance initialisation
156 #
157 # Revision 1.1 2001/08/05 07:07:58 richard
158 # added tests for roundup.init - but they're disabled until I can figure _if_
159 # we can run them (import problems).
160 #
161 #
162 #
163 # vim: set filetype=python ts=4 sw=4 et si