comparison test/test_db.py @ 888:976316fcca66

oops
author Richard Jones <richard@users.sourceforge.net>
date Thu, 18 Jul 2002 11:52:00 +0000
parents e7169d6e6e45
children a568596dbea7
comparison
equal deleted inserted replaced
887:e7169d6e6e45 888:976316fcca66
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.33 2002-07-18 11:50:58 richard Exp $ 18 # $Id: test_db.py,v 1.34 2002-07-18 11:52:00 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
71 self.db = anydbm.Database(config, 'test') 71 self.db = anydbm.Database(config, 'test')
72 setupSchema(self.db, 1, anydbm) 72 setupSchema(self.db, 1, anydbm)
73 self.db2 = anydbm.Database(config, 'test') 73 self.db2 = anydbm.Database(config, 'test')
74 setupSchema(self.db2, 0, anydbm) 74 setupSchema(self.db2, 0, anydbm)
75 75
76 def xtestStringChange(self): 76 def testStringChange(self):
77 self.db.issue.create(title="spam", status='1') 77 self.db.issue.create(title="spam", status='1')
78 self.assertEqual(self.db.issue.get('1', 'title'), 'spam') 78 self.assertEqual(self.db.issue.get('1', 'title'), 'spam')
79 self.db.issue.set('1', title='eggs') 79 self.db.issue.set('1', title='eggs')
80 self.assertEqual(self.db.issue.get('1', 'title'), 'eggs') 80 self.assertEqual(self.db.issue.get('1', 'title'), 'eggs')
81 self.db.commit() 81 self.db.commit()
86 self.db.issue.set('2', title='ham') 86 self.db.issue.set('2', title='ham')
87 self.assertEqual(self.db.issue.get('2', 'title'), 'ham') 87 self.assertEqual(self.db.issue.get('2', 'title'), 'ham')
88 self.db.commit() 88 self.db.commit()
89 self.assertEqual(self.db.issue.get('2', 'title'), 'ham') 89 self.assertEqual(self.db.issue.get('2', 'title'), 'ham')
90 90
91 def xtestLinkChange(self): 91 def testLinkChange(self):
92 self.db.issue.create(title="spam", status='1') 92 self.db.issue.create(title="spam", status='1')
93 self.assertEqual(self.db.issue.get('1', "status"), '1') 93 self.assertEqual(self.db.issue.get('1', "status"), '1')
94 self.db.issue.set('1', status='2') 94 self.db.issue.set('1', status='2')
95 self.assertEqual(self.db.issue.get('1', "status"), '2') 95 self.assertEqual(self.db.issue.get('1', "status"), '2')
96 96
97 def xtestDateChange(self): 97 def testDateChange(self):
98 self.db.issue.create(title="spam", status='1') 98 self.db.issue.create(title="spam", status='1')
99 a = self.db.issue.get('1', "deadline") 99 a = self.db.issue.get('1', "deadline")
100 self.db.issue.set('1', deadline=date.Date()) 100 self.db.issue.set('1', deadline=date.Date())
101 b = self.db.issue.get('1', "deadline") 101 b = self.db.issue.get('1', "deadline")
102 self.db.commit() 102 self.db.commit()
103 self.assertNotEqual(a, b) 103 self.assertNotEqual(a, b)
104 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00')) 104 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00'))
105 self.db.issue.set('1', deadline=date.Date()) 105 self.db.issue.set('1', deadline=date.Date())
106 106
107 def xtestIntervalChange(self): 107 def testIntervalChange(self):
108 self.db.issue.create(title="spam", status='1') 108 self.db.issue.create(title="spam", status='1')
109 a = self.db.issue.get('1', "foo") 109 a = self.db.issue.get('1', "foo")
110 self.db.issue.set('1', foo=date.Interval('-1d')) 110 self.db.issue.set('1', foo=date.Interval('-1d'))
111 self.assertNotEqual(self.db.issue.get('1', "foo"), a) 111 self.assertNotEqual(self.db.issue.get('1', "foo"), a)
112 112
127 a = self.db.user.get('1', 'age') 127 a = self.db.user.get('1', 'age')
128 self.db.user.set('1', age='3') 128 self.db.user.set('1', age='3')
129 self.assertNotEqual(self.db.user.get('1', 'age'), a) 129 self.assertNotEqual(self.db.user.get('1', 'age'), a)
130 self.db.user.set('1', age='1.0') 130 self.db.user.set('1', age='1.0')
131 131
132 def xtestNewProperty(self): 132 def testNewProperty(self):
133 ' make sure a new property is added ok ' 133 ' make sure a new property is added ok '
134 self.db.issue.create(title="spam", status='1') 134 self.db.issue.create(title="spam", status='1')
135 self.db.issue.addprop(fixer=Link("user")) 135 self.db.issue.addprop(fixer=Link("user"))
136 props = self.db.issue.getprops() 136 props = self.db.issue.getprops()
137 keys = props.keys() 137 keys = props.keys()
139 self.assertEqual(keys, ['activity', 'creation', 'creator', 'deadline', 139 self.assertEqual(keys, ['activity', 'creation', 'creator', 'deadline',
140 'files', 'fixer', 'foo', 'id', 'messages', 'nosy', 'status', 140 'files', 'fixer', 'foo', 'id', 'messages', 'nosy', 'status',
141 'superseder', 'title']) 141 'superseder', 'title'])
142 self.assertEqual(self.db.issue.get('1', "fixer"), None) 142 self.assertEqual(self.db.issue.get('1', "fixer"), None)
143 143
144 def xtestRetire(self): 144 def testRetire(self):
145 self.db.issue.create(title="spam", status='1') 145 self.db.issue.create(title="spam", status='1')
146 b = self.db.status.get('1', 'name') 146 b = self.db.status.get('1', 'name')
147 a = self.db.status.list() 147 a = self.db.status.list()
148 self.db.status.retire('1') 148 self.db.status.retire('1')
149 # make sure the list is different 149 # make sure the list is different
152 self.assertEqual(self.db.status.get('1', 'name'), b) 152 self.assertEqual(self.db.status.get('1', 'name'), b)
153 self.db.commit() 153 self.db.commit()
154 self.assertEqual(self.db.status.get('1', 'name'), b) 154 self.assertEqual(self.db.status.get('1', 'name'), b)
155 self.assertNotEqual(a, self.db.status.list()) 155 self.assertNotEqual(a, self.db.status.list())
156 156
157 def xtestSerialisation(self): 157 def testSerialisation(self):
158 self.db.issue.create(title="spam", status='1', 158 self.db.issue.create(title="spam", status='1',
159 deadline=date.Date(), foo=date.Interval('-1d')) 159 deadline=date.Date(), foo=date.Interval('-1d'))
160 self.db.commit() 160 self.db.commit()
161 assert isinstance(self.db.issue.get('1', 'deadline'), date.Date) 161 assert isinstance(self.db.issue.get('1', 'deadline'), date.Date)
162 assert isinstance(self.db.issue.get('1', 'foo'), date.Interval) 162 assert isinstance(self.db.issue.get('1', 'foo'), date.Interval)
163 self.db.user.create(username="fozzy", 163 self.db.user.create(username="fozzy",
164 password=password.Password('t. bear')) 164 password=password.Password('t. bear'))
165 self.db.commit() 165 self.db.commit()
166 assert isinstance(self.db.user.get('1', 'password'), password.Password) 166 assert isinstance(self.db.user.get('1', 'password'), password.Password)
167 167
168 def xtestTransactions(self): 168 def testTransactions(self):
169 # remember the number of items we started 169 # remember the number of items we started
170 num_issues = len(self.db.issue.list()) 170 num_issues = len(self.db.issue.list())
171 num_files = self.db.numfiles() 171 num_files = self.db.numfiles()
172 self.db.issue.create(title="don't commit me!", status='1') 172 self.db.issue.create(title="don't commit me!", status='1')
173 self.assertNotEqual(num_issues, len(self.db.issue.list())) 173 self.assertNotEqual(num_issues, len(self.db.issue.list()))
270 # invalid number value 270 # invalid number value
271 ar(TypeError, self.db.user.set, '3', username='foo', age='a') 271 ar(TypeError, self.db.user.set, '3', username='foo', age='a')
272 # invalid boolean value 272 # invalid boolean value
273 ar(TypeError, self.db.user.set, '3', username='foo', assignable='fubar') 273 ar(TypeError, self.db.user.set, '3', username='foo', assignable='fubar')
274 274
275 def xtestJournals(self): 275 def testJournals(self):
276 self.db.issue.addprop(fixer=Link("user", do_journal='yes')) 276 self.db.issue.addprop(fixer=Link("user", do_journal='yes'))
277 self.db.user.create(username="mary") 277 self.db.user.create(username="mary")
278 self.db.user.create(username="pete") 278 self.db.user.create(username="pete")
279 self.db.issue.create(title="spam", status='1') 279 self.db.issue.create(title="spam", status='1')
280 self.db.commit() 280 self.db.commit()
339 entry = self.db.getjournal('issue', '1')[-1] 339 entry = self.db.getjournal('issue', '1')[-1]
340 (x, date_stamp2, x, x, x) = entry 340 (x, date_stamp2, x, x, x) = entry
341 # see if the change was journalled 341 # see if the change was journalled
342 self.assertNotEqual(date_stamp, date_stamp2) 342 self.assertNotEqual(date_stamp, date_stamp2)
343 343
344 def xtestPack(self): 344 def testPack(self):
345 self.db.issue.create(title="spam", status='1') 345 self.db.issue.create(title="spam", status='1')
346 self.db.commit() 346 self.db.commit()
347 self.db.issue.set('1', status='2') 347 self.db.issue.set('1', status='2')
348 self.db.commit() 348 self.db.commit()
349 self.db.issue.set('1', status='3') 349 self.db.issue.set('1', status='3')
351 pack_before = date.Date(". + 1d") 351 pack_before = date.Date(". + 1d")
352 self.db.pack(pack_before) 352 self.db.pack(pack_before)
353 journal = self.db.getjournal('issue', '1') 353 journal = self.db.getjournal('issue', '1')
354 self.assertEqual(2, len(journal)) 354 self.assertEqual(2, len(journal))
355 355
356 def xtestIDGeneration(self): 356 def testIDGeneration(self):
357 id1 = self.db.issue.create(title="spam", status='1') 357 id1 = self.db.issue.create(title="spam", status='1')
358 id2 = self.db2.issue.create(title="eggs", status='2') 358 id2 = self.db2.issue.create(title="eggs", status='2')
359 self.assertNotEqual(id1, id2) 359 self.assertNotEqual(id1, id2)
360 360
361 def xtestSearching(self): 361 def testSearching(self):
362 self.db.file.create(content='hello', type="text/plain") 362 self.db.file.create(content='hello', type="text/plain")
363 self.db.file.create(content='world', type="text/frozz", 363 self.db.file.create(content='world', type="text/frozz",
364 comment='blah blah') 364 comment='blah blah')
365 self.db.issue.create(files=['1', '2'], title="flebble plop") 365 self.db.issue.create(files=['1', '2'], title="flebble plop")
366 self.db.issue.create(title="flebble frooz") 366 self.db.issue.create(title="flebble frooz")
371 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue), 371 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue),
372 {'2': {}}) 372 {'2': {}})
373 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue), 373 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
374 {'2': {}, '1': {}}) 374 {'2': {}, '1': {}})
375 375
376 def xtestReindexing(self): 376 def testReindexing(self):
377 self.db.issue.create(title="frooz") 377 self.db.issue.create(title="frooz")
378 self.db.commit() 378 self.db.commit()
379 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue), 379 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue),
380 {'1': {}}) 380 {'1': {}})
381 self.db.issue.set('1', title="dooble") 381 self.db.issue.set('1', title="dooble")
382 self.db.commit() 382 self.db.commit()
383 self.assertEquals(self.db.indexer.search(['dooble'], self.db.issue), 383 self.assertEquals(self.db.indexer.search(['dooble'], self.db.issue),
384 {'1': {}}) 384 {'1': {}})
385 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue), {}) 385 self.assertEquals(self.db.indexer.search(['frooz'], self.db.issue), {})
386 386
387 def xtestForcedReindexing(self): 387 def testForcedReindexing(self):
388 self.db.issue.create(title="flebble frooz") 388 self.db.issue.create(title="flebble frooz")
389 self.db.commit() 389 self.db.commit()
390 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue), 390 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
391 {'1': {}}) 391 {'1': {}})
392 self.db.indexer.quiet = 1 392 self.db.indexer.quiet = 1
408 self.db = anydbm.Database(config) 408 self.db = anydbm.Database(config)
409 setupSchema(self.db, 0, anydbm) 409 setupSchema(self.db, 0, anydbm)
410 self.db2 = anydbm.Database(config, 'test') 410 self.db2 = anydbm.Database(config, 'test')
411 setupSchema(self.db2, 0, anydbm) 411 setupSchema(self.db2, 0, anydbm)
412 412
413 def xtestExceptions(self): 413 def testExceptions(self):
414 ' make sure exceptions are raised on writes to a read-only db ' 414 ' make sure exceptions are raised on writes to a read-only db '
415 # this tests the exceptions that should be raised 415 # this tests the exceptions that should be raised
416 ar = self.assertRaises 416 ar = self.assertRaises
417 417
418 # this tests the exceptions that should be raised 418 # this tests the exceptions that should be raised
487 self.db = metakit.Database(config, 'test') 487 self.db = metakit.Database(config, 'test')
488 setupSchema(self.db, 1, metakit) 488 setupSchema(self.db, 1, metakit)
489 self.db2 = metakit.Database(config, 'test') 489 self.db2 = metakit.Database(config, 'test')
490 setupSchema(self.db2, 0, metakit) 490 setupSchema(self.db2, 0, metakit)
491 491
492 def xtestTransactions(self): 492 def testTransactions(self):
493 # remember the number of items we started 493 # remember the number of items we started
494 num_issues = len(self.db.issue.list()) 494 num_issues = len(self.db.issue.list())
495 self.db.issue.create(title="don't commit me!", status='1') 495 self.db.issue.create(title="don't commit me!", status='1')
496 self.assertNotEqual(num_issues, len(self.db.issue.list())) 496 self.assertNotEqual(num_issues, len(self.db.issue.list()))
497 self.db.rollback() 497 self.db.rollback()
533 def suite(): 533 def suite():
534 l = [ 534 l = [
535 unittest.makeSuite(anydbmDBTestCase, 'test'), 535 unittest.makeSuite(anydbmDBTestCase, 'test'),
536 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test') 536 unittest.makeSuite(anydbmReadOnlyDBTestCase, 'test')
537 ] 537 ]
538 return unittest.TestSuite(l) 538 # return unittest.TestSuite(l)
539 539
540 try: 540 try:
541 import bsddb 541 import bsddb
542 l.append(unittest.makeSuite(bsddbDBTestCase, 'test')) 542 l.append(unittest.makeSuite(bsddbDBTestCase, 'test'))
543 l.append(unittest.makeSuite(bsddbReadOnlyDBTestCase, 'test')) 543 l.append(unittest.makeSuite(bsddbReadOnlyDBTestCase, 'test'))
560 560
561 return unittest.TestSuite(l) 561 return unittest.TestSuite(l)
562 562
563 # 563 #
564 # $Log: not supported by cvs2svn $ 564 # $Log: not supported by cvs2svn $
565 # Revision 1.33 2002/07/18 11:50:58 richard
566 # added tests for number type too
567 #
565 # Revision 1.32 2002/07/18 11:41:10 richard 568 # Revision 1.32 2002/07/18 11:41:10 richard
566 # added tests for boolean type, and fixes to anydbm backend 569 # added tests for boolean type, and fixes to anydbm backend
567 # 570 #
568 # Revision 1.31 2002/07/14 23:17:45 richard 571 # Revision 1.31 2002/07/14 23:17:45 richard
569 # minor change to make testing easier 572 # minor change to make testing easier

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