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.15 2002-07-29 00:56:06 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 ExtendedTestCase(MyTestCase):
72 backend = 'anydbm'
73 def testCreation(self):
74 ae = self.assertEqual
76 # create the instance
77 init.install(self.dirname, 'extended', self.backend)
78 init.initialise(self.dirname, 'sekrit')
80 # check we can load the package
81 instance = imp.load_package(self.dirname, self.dirname)
83 # and open the database
84 db = instance.open()
86 # check the basics of the schema and initial data set
87 l = db.priority.list()
88 ae(l, ['1', '2', '3', '4'])
89 l = db.status.list()
90 ae(l, ['1', '2', '3', '4', '5', '6', '7', '8'])
91 l = db.keyword.list()
92 ae(l, [])
93 l = db.user.list()
94 ae(l, ['1', '2'])
95 l = db.msg.list()
96 ae(l, [])
97 l = db.file.list()
98 ae(l, [])
99 l = db.issue.list()
100 ae(l, [])
101 l = db.support.list()
102 ae(l, [])
103 l = db.rate.list()
104 ae(l, ['1', '2', '3'])
105 l = db.source.list()
106 ae(l, ['1', '2', '3', '4'])
107 l = db.platform.list()
108 ae(l, ['1', '2', '3'])
109 l = db.timelog.list()
110 ae(l, [])
112 class bsddbClassicTestCase(ClassicTestCase):
113 backend = 'bsddb'
114 class bsddbExtendedTestCase(ExtendedTestCase):
115 backend = 'bsddb'
117 class bsddb3ClassicTestCase(ClassicTestCase):
118 backend = 'bsddb3'
119 class bsddb3ExtendedTestCase(ExtendedTestCase):
120 backend = 'bsddb3'
122 class metakitClassicTestCase(ClassicTestCase):
123 backend = 'metakit'
124 class metakitExtendedTestCase(ExtendedTestCase):
125 backend = 'metakit'
127 def suite():
128 l = [
129 unittest.makeSuite(ClassicTestCase, 'test'),
130 unittest.makeSuite(ExtendedTestCase, 'test')
131 ]
133 try:
134 import bsddb
135 l.append(unittest.makeSuite(bsddbClassicTestCase, 'test'))
136 l.append(unittest.makeSuite(bsddbExtendedTestCase, 'test'))
137 except:
138 print 'bsddb module not found, skipping bsddb DBTestCase'
140 try:
141 import bsddb3
142 l.append(unittest.makeSuite(bsddb3ClassicTestCase, 'test'))
143 l.append(unittest.makeSuite(bsddb3ExtendedTestCase, 'test'))
144 except:
145 print 'bsddb3 module not found, skipping bsddb3 DBTestCase'
147 try:
148 import metakit
149 l.append(unittest.makeSuite(metakitClassicTestCase, 'test'))
150 l.append(unittest.makeSuite(metakitExtendedTestCase, 'test'))
151 except:
152 print 'metakit module not found, skipping metakit DBTestCase'
154 return unittest.TestSuite(l)
156 #
157 # $Log: not supported by cvs2svn $
158 # Revision 1.14 2002/07/26 08:27:00 richard
159 # Very close now. The cgi and mailgw now use the new security API. The two
160 # templates have been migrated to that setup. Lots of unit tests. Still some
161 # issue in the web form for editing Roles assigned to users.
162 #
163 # Revision 1.13 2002/07/14 02:05:54 richard
164 # . all storage-specific code (ie. backend) is now implemented by the backends
165 #
166 # Revision 1.12 2002/07/11 01:13:13 richard
167 # *** empty log message ***
168 #
169 # Revision 1.11 2002/07/11 01:12:34 richard
170 # Forgot to add to init tests
171 #
172 # Revision 1.10 2002/06/11 04:59:14 richard
173 # enabled testing of bsddb in test_init
174 #
175 # Revision 1.9 2002/05/23 04:26:05 richard
176 # 'I must run unit tests before committing\n' * 100
177 #
178 # Revision 1.8 2002/05/15 03:27:16 richard
179 # . fixed SCRIPT_NAME in ZRoundup for instances not at top level of Zope
180 # (thanks dman)
181 # . fixed some sorting issues that were breaking some unit tests under py2.2
182 # . mailgw test output dir was confusing the init test (but only on 2.2 *shrug*)
183 #
184 # fixed bug in the init unit test that meant only the bsddb test ran if it
185 # could (it clobbered the anydbm test)
186 #
187 # Revision 1.7 2001/10/28 22:51:38 richard
188 # Fixed ENOENT/WindowsError thing, thanks Juergen Hermann
189 #
190 # Revision 1.6 2001/09/29 23:48:06 richard
191 # Bug fix for test_init on Windows.
192 # More documenation!!
193 #
194 # Revision 1.5 2001/08/29 06:23:59 richard
195 # Disabled the bsddb3 module entirely in the unit testing. See CHANGES for
196 # details.
197 #
198 # Revision 1.4 2001/08/07 00:24:43 richard
199 # stupid typo
200 #
201 # Revision 1.3 2001/08/07 00:15:51 richard
202 # Added the copyright/license notice to (nearly) all files at request of
203 # Bizar Software.
204 #
205 # Revision 1.2 2001/08/05 07:45:27 richard
206 # Added tests for instance initialisation
207 #
208 # Revision 1.1 2001/08/05 07:07:58 richard
209 # added tests for roundup.init - but they're disabled until I can figure _if_
210 # we can run them (import problems).
211 #
212 #
213 #
214 # vim: set filetype=python ts=4 sw=4 et si