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_db.py,v 1.36 2002-07-19 03:36:34 richard Exp $
20 import unittest, os, shutil, time
22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \
23 Interval, DatabaseError, Boolean, Number
24 from roundup import date, password
25 from roundup.indexer import Indexer
27 def setupSchema(db, create, module):
28 status = module.Class(db, "status", name=String())
29 status.setkey("name")
30 user = module.Class(db, "user", username=String(), password=Password(),
31 assignable=Boolean(), age=Number())
32 file = module.FileClass(db, "file", name=String(), type=String(),
33 comment=String(indexme="yes"))
34 issue = module.IssueClass(db, "issue", title=String(indexme="yes"),
35 status=Link("status"), nosy=Multilink("user"), deadline=Date(),
36 foo=Interval(), files=Multilink("file"))
37 session = module.Class(db, 'session', title=String())
38 session.disableJournalling()
39 db.post_init()
40 if create:
41 status.create(name="unread")
42 status.create(name="in-progress")
43 status.create(name="testing")
44 status.create(name="resolved")
45 db.commit()
47 class MyTestCase(unittest.TestCase):
48 def tearDown(self):
49 if os.path.exists('_test_dir'):
50 shutil.rmtree('_test_dir')
52 class config:
53 DATABASE='_test_dir'
54 MAILHOST = 'localhost'
55 MAIL_DOMAIN = 'fill.me.in.'
56 INSTANCE_NAME = 'Roundup issue tracker'
57 ISSUE_TRACKER_EMAIL = 'issue_tracker@%s'%MAIL_DOMAIN
58 ISSUE_TRACKER_WEB = 'http://some.useful.url/'
59 ADMIN_EMAIL = 'roundup-admin@%s'%MAIL_DOMAIN
60 FILTER_POSITION = 'bottom' # one of 'top', 'bottom', 'top and bottom'
61 ANONYMOUS_ACCESS = 'deny' # either 'deny' or 'allow'
62 ANONYMOUS_REGISTER = 'deny' # either 'deny' or 'allow'
63 MESSAGES_TO_AUTHOR = 'no' # either 'yes' or 'no'
64 EMAIL_SIGNATURE_POSITION = 'bottom'
66 class anydbmDBTestCase(MyTestCase):
67 def setUp(self):
68 from roundup.backends import anydbm
69 # remove previous test, ignore errors
70 if os.path.exists(config.DATABASE):
71 shutil.rmtree(config.DATABASE)
72 os.makedirs(config.DATABASE + '/files')
73 self.db = anydbm.Database(config, 'test')
74 setupSchema(self.db, 1, anydbm)
75 self.db2 = anydbm.Database(config, 'test')
76 setupSchema(self.db2, 0, anydbm)
78 def testStringChange(self):
79 self.db.issue.create(title="spam", status='1')
80 self.assertEqual(self.db.issue.get('1', 'title'), 'spam')
81 self.db.issue.set('1', title='eggs')
82 self.assertEqual(self.db.issue.get('1', 'title'), 'eggs')
83 self.db.commit()
84 self.assertEqual(self.db.issue.get('1', 'title'), 'eggs')
85 self.db.issue.create(title="spam", status='1')
86 self.db.commit()
87 self.assertEqual(self.db.issue.get('2', 'title'), 'spam')
88 self.db.issue.set('2', title='ham')
89 self.assertEqual(self.db.issue.get('2', 'title'), 'ham')
90 self.db.commit()
91 self.assertEqual(self.db.issue.get('2', 'title'), 'ham')
93 def testLinkChange(self):
94 self.db.issue.create(title="spam", status='1')
95 self.assertEqual(self.db.issue.get('1', "status"), '1')
96 self.db.issue.set('1', status='2')
97 self.assertEqual(self.db.issue.get('1', "status"), '2')
99 def testDateChange(self):
100 self.db.issue.create(title="spam", status='1')
101 a = self.db.issue.get('1', "deadline")
102 self.db.issue.set('1', deadline=date.Date())
103 b = self.db.issue.get('1', "deadline")
104 self.db.commit()
105 self.assertNotEqual(a, b)
106 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00'))
107 self.db.issue.set('1', deadline=date.Date())
109 def testIntervalChange(self):
110 self.db.issue.create(title="spam", status='1')
111 a = self.db.issue.get('1', "foo")
112 self.db.issue.set('1', foo=date.Interval('-1d'))
113 self.assertNotEqual(self.db.issue.get('1', "foo"), a)
115 def testBooleanChange(self):
116 self.db.user.create(username='foo', assignable=1)
117 self.db.user.create(username='foo', assignable=0)
118 a = self.db.user.get('1', 'assignable')
119 self.db.user.set('1', assignable=0)
120 self.assertNotEqual(self.db.user.get('1', 'assignable'), a)
121 self.db.user.set('1', assignable=0)
122 self.db.user.set('1', assignable=1)
124 def testNumberChange(self):
125 self.db.user.create(username='foo', age='1')
126 a = self.db.user.get('1', 'age')
127 self.db.user.set('1', age='3')
128 self.assertNotEqual(self.db.user.get('1', 'age'), a)
129 self.db.user.set('1', age='1.0')
131 def testNewProperty(self):
132 ' make sure a new property is added ok '
133 self.db.issue.create(title="spam", status='1')
134 self.db.issue.addprop(fixer=Link("user"))
135 props = self.db.issue.getprops()
136 keys = props.keys()
137 keys.sort()
138 self.assertEqual(keys, ['activity', 'creation', 'creator', 'deadline',
139 'files', 'fixer', 'foo', 'id', 'messages', 'nosy', 'status',
140 'superseder', 'title'])
141 self.assertEqual(self.db.issue.get('1', "fixer"), None)
143 def testRetire(self):
144 self.db.issue.create(title="spam", status='1')
145 b = self.db.status.get('1', 'name')
146 a = self.db.status.list()
147 self.db.status.retire('1')
148 # make sure the list is different
149 self.assertNotEqual(a, self.db.status.list())
150 # can still access the node if necessary
151 self.assertEqual(self.db.status.get('1', 'name'), b)
152 self.db.commit()
153 self.assertEqual(self.db.status.get('1', 'name'), b)
154 self.assertNotEqual(a, self.db.status.list())
156 def testSerialisation(self):
157 self.db.issue.create(title="spam", status='1',
158 deadline=date.Date(), foo=date.Interval('-1d'))
159 self.db.commit()
160 assert isinstance(self.db.issue.get('1', 'deadline'), date.Date)
161 assert isinstance(self.db.issue.get('1', 'foo'), date.Interval)
162 self.db.user.create(username="fozzy",
163 password=password.Password('t. bear'))
164 self.db.commit()
165 assert isinstance(self.db.user.get('1', 'password'), password.Password)
167 def testTransactions(self):
168 # remember the number of items we started
169 num_issues = len(self.db.issue.list())
170 num_files = self.db.numfiles()
171 self.db.issue.create(title="don't commit me!", status='1')
172 self.assertNotEqual(num_issues, len(self.db.issue.list()))
173 self.db.rollback()
174 self.assertEqual(num_issues, len(self.db.issue.list()))
175 self.db.issue.create(title="please commit me!", status='1')
176 self.assertNotEqual(num_issues, len(self.db.issue.list()))
177 self.db.commit()
178 self.assertNotEqual(num_issues, len(self.db.issue.list()))
179 self.db.rollback()
180 self.assertNotEqual(num_issues, len(self.db.issue.list()))
181 self.db.file.create(name="test", type="text/plain", content="hi")
182 self.db.rollback()
183 self.assertEqual(num_files, self.db.numfiles())
184 for i in range(10):
185 self.db.file.create(name="test", type="text/plain",
186 content="hi %d"%(i))
187 self.db.commit()
188 num_files2 = self.db.numfiles()
189 self.assertNotEqual(num_files, num_files2)
190 self.db.file.create(name="test", type="text/plain", content="hi")
191 self.db.rollback()
192 self.assertNotEqual(num_files, self.db.numfiles())
193 self.assertEqual(num_files2, self.db.numfiles())
195 def testDestroyNoJournalling(self):
196 ' test destroy on a class with no journalling '
197 self.innerTestDestroy(klass=self.db.session)
199 def testDestroyJournalling(self):
200 ' test destroy on a class with journalling '
201 self.innerTestDestroy(klass=self.db.issue)
203 def innerTestDestroy(self, klass):
204 newid = klass.create(title='Mr Friendly')
205 n = len(klass.list())
206 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
207 klass.destroy(newid)
208 self.assertRaises(IndexError, klass.get, newid, 'title')
209 self.assertNotEqual(len(klass.list()), n)
210 if klass.do_journal:
211 self.assertRaises(IndexError, klass.history, newid)
213 # now with a commit
214 newid = klass.create(title='Mr Friendly')
215 n = len(klass.list())
216 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
217 self.db.commit()
218 klass.destroy(newid)
219 self.assertRaises(IndexError, klass.get, newid, 'title')
220 self.db.commit()
221 self.assertRaises(IndexError, klass.get, newid, 'title')
222 self.assertNotEqual(len(klass.list()), n)
223 if klass.do_journal:
224 self.assertRaises(IndexError, klass.history, newid)
226 # now with a rollback
227 newid = klass.create(title='Mr Friendly')
228 n = len(klass.list())
229 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
230 self.db.commit()
231 klass.destroy(newid)
232 self.assertNotEqual(len(klass.list()), n)
233 self.assertRaises(IndexError, klass.get, newid, 'title')
234 self.db.rollback()
235 self.assertEqual(klass.get(newid, 'title'), 'Mr Friendly')
236 self.assertEqual(len(klass.list()), n)
237 if klass.do_journal:
238 self.assertNotEqual(klass.history(newid), [])
240 def testExceptions(self):
241 # this tests the exceptions that should be raised
242 ar = self.assertRaises
244 #
245 # class create
246 #
247 # string property
248 ar(TypeError, self.db.status.create, name=1)
249 # invalid property name
250 ar(KeyError, self.db.status.create, foo='foo')
251 # key name clash
252 ar(ValueError, self.db.status.create, name='unread')
253 # invalid link index
254 ar(IndexError, self.db.issue.create, title='foo', status='bar')
255 # invalid link value
256 ar(ValueError, self.db.issue.create, title='foo', status=1)
257 # invalid multilink type
258 ar(TypeError, self.db.issue.create, title='foo', status='1',
259 nosy='hello')
260 # invalid multilink index type
261 ar(ValueError, self.db.issue.create, title='foo', status='1',
262 nosy=[1])
263 # invalid multilink index
264 ar(IndexError, self.db.issue.create, title='foo', status='1',
265 nosy=['10'])
267 #
268 # key property
269 #
270 # key must be a String
271 ar(TypeError, self.db.user.setkey, 'password')
272 # key must exist
273 ar(KeyError, self.db.user.setkey, 'fubar')
275 #
276 # class get
277 #
278 # invalid node id
279 ar(IndexError, self.db.issue.get, '1', 'title')
280 # invalid property name
281 ar(KeyError, self.db.status.get, '2', 'foo')
283 #
284 # class set
285 #
286 # invalid node id
287 ar(IndexError, self.db.issue.set, '1', title='foo')
288 # invalid property name
289 ar(KeyError, self.db.status.set, '1', foo='foo')
290 # string property
291 ar(TypeError, self.db.status.set, '1', name=1)
292 # key name clash
293 ar(ValueError, self.db.status.set, '2', name='unread')
294 # set up a valid issue for me to work on
295 self.db.issue.create(title="spam", status='1')
296 # invalid link index
297 ar(IndexError, self.db.issue.set, '6', title='foo', status='bar')
298 # invalid link value
299 ar(ValueError, self.db.issue.set, '6', title='foo', status=1)
300 # invalid multilink type
301 ar(TypeError, self.db.issue.set, '6', title='foo', status='1',
302 nosy='hello')
303 # invalid multilink index type
304 ar(ValueError, self.db.issue.set, '6', title='foo', status='1',
305 nosy=[1])
306 # invalid multilink index
307 ar(IndexError, self.db.issue.set, '6', title='foo', status='1',
308 nosy=['10'])
309 # invalid number value
310 ar(TypeError, self.db.user.create, username='foo', age='a')
311 # invalid boolean value
312 ar(TypeError, self.db.user.create, username='foo', assignable='true')
313 self.db.user.create(username='foo')
314 # invalid number value
315 ar(TypeError, self.db.user.set, '3', username='foo', age='a')
316 # invalid boolean value
317 ar(TypeError, self.db.user.set, '3', username='foo', assignable='true')
319 def testJournals(self):
320 self.db.issue.addprop(fixer=Link("user", do_journal='yes'))
321 self.db.user.create(username="mary")
322 self.db.user.create(username="pete")
323 self.db.issue.create(title="spam", status='1')
324 self.db.commit()
326 # journal entry for issue create
327 journal = self.db.getjournal('issue', '1')
328 self.assertEqual(1, len(journal))
329 (nodeid, date_stamp, journaltag, action, params) = journal[0]
330 self.assertEqual(nodeid, '1')
331 self.assertEqual(journaltag, 'test')
332 self.assertEqual(action, 'create')
333 keys = params.keys()
334 keys.sort()
335 self.assertEqual(keys, ['deadline', 'files', 'fixer', 'foo',
336 'messages', 'nosy', 'status', 'superseder', 'title'])
337 self.assertEqual(None,params['deadline'])
338 self.assertEqual(None,params['fixer'])
339 self.assertEqual(None,params['foo'])
340 self.assertEqual([],params['nosy'])
341 self.assertEqual('1',params['status'])
342 self.assertEqual('spam',params['title'])
344 # journal entry for link
345 journal = self.db.getjournal('user', '1')
346 self.assertEqual(1, len(journal))
347 self.db.issue.set('1', fixer='1')
348 self.db.commit()
349 journal = self.db.getjournal('user', '1')
350 self.assertEqual(2, len(journal))
351 (nodeid, date_stamp, journaltag, action, params) = journal[1]
352 self.assertEqual('1', nodeid)
353 self.assertEqual('test', journaltag)
354 self.assertEqual('link', action)
355 self.assertEqual(('issue', '1', 'fixer'), params)
357 # journal entry for unlink
358 self.db.issue.set('1', fixer='2')
359 self.db.commit()
360 journal = self.db.getjournal('user', '1')
361 self.assertEqual(3, len(journal))
362 (nodeid, date_stamp, journaltag, action, params) = journal[2]
363 self.assertEqual('1', nodeid)
364 self.assertEqual('test', journaltag)
365 self.assertEqual('unlink', action)
366 self.assertEqual(('issue', '1', 'fixer'), params)
368 # test disabling journalling
369 # ... get the last entry
370 time.sleep(1)
371 entry = self.db.getjournal('issue', '1')[-1]
372 (x, date_stamp, x, x, x) = entry
373 self.db.issue.disableJournalling()
374 self.db.issue.set('1', title='hello world')
375 self.db.commit()
376 entry = self.db.getjournal('issue', '1')[-1]
377 (x, date_stamp2, x, x, x) = entry
378 # see if the change was journalled when it shouldn't have been
379 self.assertEqual(date_stamp, date_stamp2)
380 self.db.issue.enableJournalling()
381 self.db.issue.set('1', title='hello world 2')
382 self.db.commit()
383 entry = self.db.getjournal('issue', '1')[-1]
384 (x, date_stamp2, x, x, x) = entry
385 # see if the change was journalled
386 self.assertNotEqual(date_stamp, date_stamp2)
388 def testPack(self):
389 self.db.issue.create(title="spam", status='1')
390 self.db.commit()
391 self.db.issue.set('1', status='2')
392 self.db.commit()
393 self.db.issue.set('1', status='3')
394 self.db.commit()
395 pack_before = date.Date(". + 1d")
396 self.db.pack(pack_before)
397 journal = self.db.getjournal('issue', '1')
398 self.assertEqual(2, len(journal))
400 def testIDGeneration(self):
401 id1 = self.db.issue.create(title="spam", status='1')
402 id2 = self.db2.issue.create(title="eggs", status='2')
403 self.assertNotEqual(id1, id2)
405 def testSearching(self):
406 self.db.file.create(content='hello', type="text/plain")
407 self.db.file.create(content='world', type="text/frozz",
408 comment='blah blah')
409 self.db.issue.create(files=['1', '2'], title="flebble plop")
410 self.db.issue.create(title="flebble frooz")
411 self.db.commit()
412 self.assertEquals(self.db.indexer.search(['hello'], self.db.issue),
413 {'1': {'files': ['1']}})
414 self.assertEquals(self.db.indexer.search(['world'], self.db.issue), {})
415 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue),
416 {'2': {}})
417 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
418 {'2': {}, '1': {}})
420 def testReindexing(self):
421 self.db.issue.create(title="frooz")
422 self.db.commit()
423 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue),
424 {'1': {}})
425 self.db.issue.set('1', title="dooble")
426 self.db.commit()
427 self.assertEquals(self.db.indexer.search(['dooble'], self.db.issue),
428 {'1': {}})
429 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue), {})
431 def testForcedReindexing(self):
432 self.db.issue.create(title="flebble frooz")
433 self.db.commit()
434 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
435 {'1': {}})
436 self.db.indexer.quiet = 1
437 self.db.indexer.force_reindex()
438 self.db.post_init()
439 self.db.indexer.quiet = 9
440 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
441 {'1': {}})
443 class anydbmReadOnlyDBTestCase(MyTestCase):
444 def setUp(self):
445 from roundup.backends import anydbm
446 # remove previous test, ignore errors
447 if os.path.exists(config.DATABASE):
448 shutil.rmtree(config.DATABASE)
449 os.makedirs(config.DATABASE + '/files')
450 db = anydbm.Database(config, 'test')
451 setupSchema(db, 1, anydbm)
452 self.db = anydbm.Database(config)
453 setupSchema(self.db, 0, anydbm)
454 self.db2 = anydbm.Database(config, 'test')
455 setupSchema(self.db2, 0, anydbm)
457 def testExceptions(self):
458 ' make sure exceptions are raised on writes to a read-only db '
459 # this tests the exceptions that should be raised
460 ar = self.assertRaises
462 # this tests the exceptions that should be raised
463 ar(DatabaseError, self.db.status.create, name="foo")
464 ar(DatabaseError, self.db.status.set, '1', name="foo")
465 ar(DatabaseError, self.db.status.retire, '1')
468 class bsddbDBTestCase(anydbmDBTestCase):
469 def setUp(self):
470 from roundup.backends import bsddb
471 # remove previous test, ignore errors
472 if os.path.exists(config.DATABASE):
473 shutil.rmtree(config.DATABASE)
474 os.makedirs(config.DATABASE + '/files')
475 self.db = bsddb.Database(config, 'test')
476 setupSchema(self.db, 1, bsddb)
477 self.db2 = bsddb.Database(config, 'test')
478 setupSchema(self.db2, 0, bsddb)
480 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
481 def setUp(self):
482 from roundup.backends import bsddb
483 # remove previous test, ignore errors
484 if os.path.exists(config.DATABASE):
485 shutil.rmtree(config.DATABASE)
486 os.makedirs(config.DATABASE + '/files')
487 db = bsddb.Database(config, 'test')
488 setupSchema(db, 1, bsddb)
489 self.db = bsddb.Database(config)
490 setupSchema(self.db, 0, bsddb)
491 self.db2 = bsddb.Database(config, 'test')
492 setupSchema(self.db2, 0, bsddb)
495 class bsddb3DBTestCase(anydbmDBTestCase):
496 def setUp(self):
497 from roundup.backends import bsddb3
498 # remove previous test, ignore errors
499 if os.path.exists(config.DATABASE):
500 shutil.rmtree(config.DATABASE)
501 os.makedirs(config.DATABASE + '/files')
502 self.db = bsddb3.Database(config, 'test')
503 setupSchema(self.db, 1, bsddb3)
504 self.db2 = bsddb3.Database(config, 'test')
505 setupSchema(self.db2, 0, bsddb3)
507 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
508 def setUp(self):
509 from roundup.backends import bsddb3
510 # remove previous test, ignore errors
511 if os.path.exists(config.DATABASE):
512 shutil.rmtree(config.DATABASE)
513 os.makedirs(config.DATABASE + '/files')
514 db = bsddb3.Database(config, 'test')
515 setupSchema(db, 1, bsddb3)
516 self.db = bsddb3.Database(config)
517 setupSchema(self.db, 0, bsddb3)
518 self.db2 = bsddb3.Database(config, 'test')
519 setupSchema(self.db2, 0, bsddb3)
522 class metakitDBTestCase(anydbmDBTestCase):
523 def setUp(self):
524 from roundup.backends import metakit
525 import weakref
526 metakit._instances = weakref.WeakValueDictionary()
527 # remove previous test, ignore errors
528 if os.path.exists(config.DATABASE):
529 shutil.rmtree(config.DATABASE)
530 os.makedirs(config.DATABASE + '/files')
531 self.db = metakit.Database(config, 'test')
532 setupSchema(self.db, 1, metakit)
533 self.db2 = metakit.Database(config, 'test')
534 setupSchema(self.db2, 0, metakit)
536 def testTransactions(self):
537 # remember the number of items we started
538 num_issues = len(self.db.issue.list())
539 self.db.issue.create(title="don't commit me!", status='1')
540 self.assertNotEqual(num_issues, len(self.db.issue.list()))
541 self.db.rollback()
542 self.assertEqual(num_issues, len(self.db.issue.list()))
543 self.db.issue.create(title="please commit me!", status='1')
544 self.assertNotEqual(num_issues, len(self.db.issue.list()))
545 self.db.commit()
546 self.assertNotEqual(num_issues, len(self.db.issue.list()))
547 self.db.rollback()
548 self.assertNotEqual(num_issues, len(self.db.issue.list()))
549 self.db.file.create(name="test", type="text/plain", content="hi")
550 self.db.rollback()
551 for i in range(10):
552 self.db.file.create(name="test", type="text/plain",
553 content="hi %d"%(i))
554 self.db.commit()
555 # TODO: would be good to be able to ensure the file is not on disk after
556 # a rollback...
557 self.assertNotEqual(num_files, num_files2)
558 self.db.file.create(name="test", type="text/plain", content="hi")
559 self.db.rollback()
561 class metakitReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
562 def setUp(self):
563 from roundup.backends import metakit
564 import weakref
565 metakit._instances = weakref.WeakValueDictionary()
566 # remove previous test, ignore errors
567 if os.path.exists(config.DATABASE):
568 shutil.rmtree(config.DATABASE)
569 os.makedirs(config.DATABASE + '/files')
570 db = metakit.Database(config, 'test')
571 setupSchema(db, 1, metakit)
572 self.db = metakit.Database(config)
573 setupSchema(self.db, 0, metakit)
574 self.db2 = metakit.Database(config, 'test')
575 setupSchema(self.db2, 0, metakit)
577 def suite():
578 l = [
579 unittest.makeSuite(anydbmDBTestCase, 'test'),
580 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test')
581 ]
582 # return unittest.TestSuite(l)
584 try:
585 import bsddb
586 l.append(unittest.makeSuite(bsddbDBTestCase, 'test'))
587 l.append(unittest.makeSuite(bsddbReadOnlyDBTestCase, 'test'))
588 except:
589 print 'bsddb module not found, skipping bsddb DBTestCase'
591 try:
592 import bsddb3
593 l.append(unittest.makeSuite(bsddb3DBTestCase, 'test'))
594 l.append(unittest.makeSuite(bsddb3ReadOnlyDBTestCase, 'test'))
595 except:
596 print 'bsddb3 module not found, skipping bsddb3 DBTestCase'
598 try:
599 import metakit
600 l.append(unittest.makeSuite(metakitDBTestCase, 'test'))
601 l.append(unittest.makeSuite(metakitReadOnlyDBTestCase, 'test'))
602 except:
603 print 'metakit module not found, skipping metakit DBTestCase'
605 return unittest.TestSuite(l)
607 #
608 # $Log: not supported by cvs2svn $
609 # Revision 1.35 2002/07/18 23:07:08 richard
610 # Unit tests and a few fixes.
611 #
612 # Revision 1.34 2002/07/18 11:52:00 richard
613 # oops
614 #
615 # Revision 1.33 2002/07/18 11:50:58 richard
616 # added tests for number type too
617 #
618 # Revision 1.32 2002/07/18 11:41:10 richard
619 # added tests for boolean type, and fixes to anydbm backend
620 #
621 # Revision 1.31 2002/07/14 23:17:45 richard
622 # minor change to make testing easier
623 #
624 # Revision 1.30 2002/07/14 06:06:34 richard
625 # Did some old TODOs
626 #
627 # Revision 1.29 2002/07/14 04:03:15 richard
628 # Implemented a switch to disable journalling for a Class. CGI session
629 # database now uses it.
630 #
631 # Revision 1.28 2002/07/14 02:16:29 richard
632 # Fixes for the metakit backend (removed the cut-n-paste IssueClass, removed
633 # a special case for it in testing)
634 #
635 # Revision 1.27 2002/07/14 02:05:54 richard
636 # . all storage-specific code (ie. backend) is now implemented by the backends
637 #
638 # Revision 1.26 2002/07/11 01:11:03 richard
639 # Added metakit backend to the db tests and fixed the more easily fixable test
640 # failures.
641 #
642 # Revision 1.25 2002/07/09 04:19:09 richard
643 # Added reindex command to roundup-admin.
644 # Fixed reindex on first access.
645 # Also fixed reindexing of entries that change.
646 #
647 # Revision 1.24 2002/07/09 03:02:53 richard
648 # More indexer work:
649 # - all String properties may now be indexed too. Currently there's a bit of
650 # "issue" specific code in the actual searching which needs to be
651 # addressed. In a nutshell:
652 # + pass 'indexme="yes"' as a String() property initialisation arg, eg:
653 # file = FileClass(db, "file", name=String(), type=String(),
654 # comment=String(indexme="yes"))
655 # + the comment will then be indexed and be searchable, with the results
656 # related back to the issue that the file is linked to
657 # - as a result of this work, the FileClass has a default MIME type that may
658 # be overridden in a subclass, or by the use of a "type" property as is
659 # done in the default templates.
660 # - the regeneration of the indexes (if necessary) is done once the schema is
661 # set up in the dbinit.
662 #
663 # Revision 1.23 2002/06/20 23:51:48 richard
664 # Cleaned up the hyperdb tests
665 #
666 # Revision 1.22 2002/05/21 05:52:11 richard
667 # Well whadya know, bsddb3 works again.
668 # The backend is implemented _exactly_ the same as bsddb - so there's no
669 # using its transaction or locking support. It'd be nice to use those some
670 # day I suppose.
671 #
672 # Revision 1.21 2002/04/15 23:25:15 richard
673 # . node ids are now generated from a lockable store - no more race conditions
674 #
675 # We're using the portalocker code by Jonathan Feinberg that was contributed
676 # to the ASPN Python cookbook. This gives us locking across Unix and Windows.
677 #
678 # Revision 1.20 2002/04/03 05:54:31 richard
679 # Fixed serialisation problem by moving the serialisation step out of the
680 # hyperdb.Class (get, set) into the hyperdb.Database.
681 #
682 # Also fixed htmltemplate after the showid changes I made yesterday.
683 #
684 # Unit tests for all of the above written.
685 #
686 # Revision 1.19 2002/02/25 14:34:31 grubert
687 # . use blobfiles in back_anydbm which is used in back_bsddb.
688 # change test_db as dirlist does not work for subdirectories.
689 # ATTENTION: blobfiles now creates subdirectories for files.
690 #
691 # Revision 1.18 2002/01/22 07:21:13 richard
692 # . fixed back_bsddb so it passed the journal tests
693 #
694 # ... it didn't seem happy using the back_anydbm _open method, which is odd.
695 # Yet another occurrance of whichdb not being able to recognise older bsddb
696 # databases. Yadda yadda. Made the HYPERDBDEBUG stuff more sane in the
697 # process.
698 #
699 # Revision 1.17 2002/01/22 05:06:09 rochecompaan
700 # We need to keep the last 'set' entry in the journal to preserve
701 # information on 'activity' for nodes.
702 #
703 # Revision 1.16 2002/01/21 16:33:20 rochecompaan
704 # You can now use the roundup-admin tool to pack the database
705 #
706 # Revision 1.15 2002/01/19 13:16:04 rochecompaan
707 # Journal entries for link and multilink properties can now be switched on
708 # or off.
709 #
710 # Revision 1.14 2002/01/16 07:02:57 richard
711 # . lots of date/interval related changes:
712 # - more relaxed date format for input
713 #
714 # Revision 1.13 2002/01/14 02:20:15 richard
715 # . changed all config accesses so they access either the instance or the
716 # config attriubute on the db. This means that all config is obtained from
717 # instance_config instead of the mish-mash of classes. This will make
718 # switching to a ConfigParser setup easier too, I hope.
719 #
720 # At a minimum, this makes migration a _little_ easier (a lot easier in the
721 # 0.5.0 switch, I hope!)
722 #
723 # Revision 1.12 2001/12/17 03:52:48 richard
724 # Implemented file store rollback. As a bonus, the hyperdb is now capable of
725 # storing more than one file per node - if a property name is supplied,
726 # the file is called designator.property.
727 # I decided not to migrate the existing files stored over to the new naming
728 # scheme - the FileClass just doesn't specify the property name.
729 #
730 # Revision 1.11 2001/12/10 23:17:20 richard
731 # Added transaction tests to test_db
732 #
733 # Revision 1.10 2001/12/03 21:33:39 richard
734 # Fixes so the tests use commit and not close
735 #
736 # Revision 1.9 2001/12/02 05:06:16 richard
737 # . We now use weakrefs in the Classes to keep the database reference, so
738 # the close() method on the database is no longer needed.
739 # I bumped the minimum python requirement up to 2.1 accordingly.
740 # . #487480 ] roundup-server
741 # . #487476 ] INSTALL.txt
742 #
743 # I also cleaned up the change message / post-edit stuff in the cgi client.
744 # There's now a clearly marked "TODO: append the change note" where I believe
745 # the change note should be added there. The "changes" list will obviously
746 # have to be modified to be a dict of the changes, or somesuch.
747 #
748 # More testing needed.
749 #
750 # Revision 1.8 2001/10/09 07:25:59 richard
751 # Added the Password property type. See "pydoc roundup.password" for
752 # implementation details. Have updated some of the documentation too.
753 #
754 # Revision 1.7 2001/08/29 06:23:59 richard
755 # Disabled the bsddb3 module entirely in the unit testing. See CHANGES for
756 # details.
757 #
758 # Revision 1.6 2001/08/07 00:24:43 richard
759 # stupid typo
760 #
761 # Revision 1.5 2001/08/07 00:15:51 richard
762 # Added the copyright/license notice to (nearly) all files at request of
763 # Bizar Software.
764 #
765 # Revision 1.4 2001/07/30 03:45:56 richard
766 # Added more DB to test_db. Can skip tests where imports fail.
767 #
768 # Revision 1.3 2001/07/29 07:01:39 richard
769 # Added vim command to all source so that we don't get no steenkin' tabs :)
770 #
771 # Revision 1.2 2001/07/29 04:09:20 richard
772 # Added the fabricated property "id" to all hyperdb classes.
773 #
774 # Revision 1.1 2001/07/27 06:55:07 richard
775 # moving tests -> test
776 #
777 # Revision 1.7 2001/07/27 06:26:43 richard
778 # oops - wasn't deleting the test dir after the read-only tests
779 #
780 # Revision 1.6 2001/07/27 06:23:59 richard
781 # consistency
782 #
783 # Revision 1.5 2001/07/27 06:23:09 richard
784 # Added some new hyperdb tests to make sure we raise the right exceptions.
785 #
786 # Revision 1.4 2001/07/25 04:34:31 richard
787 # Added id and log to tests files...
788 #
789 #
790 # vim: set filetype=python ts=4 sw=4 et si