comparison test/test_db.py @ 690:509a101305da

node ids are now generated from a lockable store - no more race conditions We're using the portalocker code by Jonathan Feinberg that was contributed to the ASPN Python cookbook. This gives us locking across Unix and Windows.
author Richard Jones <richard@users.sourceforge.net>
date Mon, 15 Apr 2002 23:25:15 +0000
parents bc46480e2a2b
children e3d742c75ac3
comparison
equal deleted inserted replaced
689:456a1ed04650 690:509a101305da
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.20 2002-04-03 05:54:31 richard Exp $ 18 # $Id: test_db.py,v 1.21 2002-04-15 23:25:15 richard Exp $
19 19
20 import unittest, os, shutil 20 import unittest, os, shutil
21 21
22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \ 22 from roundup.hyperdb import String, Password, Link, Multilink, Date, \
23 Interval, Class, DatabaseError 23 Interval, Class, DatabaseError
64 if os.path.exists(config.DATABASE): 64 if os.path.exists(config.DATABASE):
65 shutil.rmtree(config.DATABASE) 65 shutil.rmtree(config.DATABASE)
66 os.makedirs(config.DATABASE + '/files') 66 os.makedirs(config.DATABASE + '/files')
67 self.db = anydbm.Database(config, 'test') 67 self.db = anydbm.Database(config, 'test')
68 setupSchema(self.db, 1) 68 setupSchema(self.db, 1)
69 self.db2 = anydbm.Database(config, 'test')
70 setupSchema(self.db2, 0)
69 71
70 def testChanges(self): 72 def testChanges(self):
71 self.db.issue.create(title="spam", status='1') 73 self.db.issue.create(title="spam", status='1')
72 self.db.issue.create(title="eggs", status='2') 74 self.db.issue.create(title="eggs", status='2')
73 self.db.issue.create(title="ham", status='4') 75 self.db.issue.create(title="ham", status='4')
138 self.assertNotEqual(num_files, num_files2) 140 self.assertNotEqual(num_files, num_files2)
139 self.db.file.create(name="test", type="text/plain", content="hi") 141 self.db.file.create(name="test", type="text/plain", content="hi")
140 self.db.rollback() 142 self.db.rollback()
141 self.assertNotEqual(num_files, self.db.numfiles()) 143 self.assertNotEqual(num_files, self.db.numfiles())
142 self.assertEqual(num_files2, self.db.numfiles()) 144 self.assertEqual(num_files2, self.db.numfiles())
143
144
145 145
146 def testExceptions(self): 146 def testExceptions(self):
147 # this tests the exceptions that should be raised 147 # this tests the exceptions that should be raised
148 ar = self.assertRaises 148 ar = self.assertRaises
149 149
190 # key name clash 190 # key name clash
191 ar(ValueError, self.db.status.set, '2', name='unread') 191 ar(ValueError, self.db.status.set, '2', name='unread')
192 # set up a valid issue for me to work on 192 # set up a valid issue for me to work on
193 self.db.issue.create(title="spam", status='1') 193 self.db.issue.create(title="spam", status='1')
194 # invalid link index 194 # invalid link index
195 ar(IndexError, self.db.issue.set, '1', title='foo', status='bar') 195 ar(IndexError, self.db.issue.set, '6', title='foo', status='bar')
196 # invalid link value 196 # invalid link value
197 ar(ValueError, self.db.issue.set, '1', title='foo', status=1) 197 ar(ValueError, self.db.issue.set, '6', title='foo', status=1)
198 # invalid multilink type 198 # invalid multilink type
199 ar(TypeError, self.db.issue.set, '1', title='foo', status='1', 199 ar(TypeError, self.db.issue.set, '6', title='foo', status='1',
200 nosy='hello') 200 nosy='hello')
201 # invalid multilink index type 201 # invalid multilink index type
202 ar(ValueError, self.db.issue.set, '1', title='foo', status='1', 202 ar(ValueError, self.db.issue.set, '6', title='foo', status='1',
203 nosy=[1]) 203 nosy=[1])
204 # invalid multilink index 204 # invalid multilink index
205 ar(IndexError, self.db.issue.set, '1', title='foo', status='1', 205 ar(IndexError, self.db.issue.set, '6', title='foo', status='1',
206 nosy=['10']) 206 nosy=['10'])
207 207
208 def testJournals(self): 208 def testJournals(self):
209 self.db.issue.addprop(fixer=Link("user", do_journal='yes')) 209 self.db.issue.addprop(fixer=Link("user", do_journal='yes'))
210 self.db.user.create(username="mary") 210 self.db.user.create(username="mary")
267 self.assertEqual(2, len(journal)) 267 self.assertEqual(2, len(journal))
268 268
269 def testRetire(self): 269 def testRetire(self):
270 pass 270 pass
271 271
272 def testIDGeneration(self):
273 id1 = self.db.issue.create(title="spam", status='1')
274 id2 = self.db2.issue.create(title="eggs", status='2')
275 self.assertNotEqual(id1, id2)
276
272 277
273 class anydbmReadOnlyDBTestCase(MyTestCase): 278 class anydbmReadOnlyDBTestCase(MyTestCase):
274 def setUp(self): 279 def setUp(self):
275 from roundup.backends import anydbm 280 from roundup.backends import anydbm
276 # remove previous test, ignore errors 281 # remove previous test, ignore errors
279 os.makedirs(config.DATABASE + '/files') 284 os.makedirs(config.DATABASE + '/files')
280 db = anydbm.Database(config, 'test') 285 db = anydbm.Database(config, 'test')
281 setupSchema(db, 1) 286 setupSchema(db, 1)
282 self.db = anydbm.Database(config) 287 self.db = anydbm.Database(config)
283 setupSchema(self.db, 0) 288 setupSchema(self.db, 0)
289 self.db2 = anydbm.Database(config, 'test')
290 setupSchema(self.db2, 0)
284 291
285 def testExceptions(self): 292 def testExceptions(self):
286 # this tests the exceptions that should be raised 293 # this tests the exceptions that should be raised
287 ar = self.assertRaises 294 ar = self.assertRaises
288 295
299 if os.path.exists(config.DATABASE): 306 if os.path.exists(config.DATABASE):
300 shutil.rmtree(config.DATABASE) 307 shutil.rmtree(config.DATABASE)
301 os.makedirs(config.DATABASE + '/files') 308 os.makedirs(config.DATABASE + '/files')
302 self.db = bsddb.Database(config, 'test') 309 self.db = bsddb.Database(config, 'test')
303 setupSchema(self.db, 1) 310 setupSchema(self.db, 1)
311 self.db2 = bsddb.Database(config, 'test')
312 setupSchema(self.db2, 0)
304 313
305 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): 314 class bsddbReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
306 def setUp(self): 315 def setUp(self):
307 from roundup.backends import bsddb 316 from roundup.backends import bsddb
308 # remove previous test, ignore errors 317 # remove previous test, ignore errors
311 os.makedirs(config.DATABASE + '/files') 320 os.makedirs(config.DATABASE + '/files')
312 db = bsddb.Database(config, 'test') 321 db = bsddb.Database(config, 'test')
313 setupSchema(db, 1) 322 setupSchema(db, 1)
314 self.db = bsddb.Database(config) 323 self.db = bsddb.Database(config)
315 setupSchema(self.db, 0) 324 setupSchema(self.db, 0)
325 self.db2 = bsddb.Database(config, 'test')
326 setupSchema(self.db2, 0)
316 327
317 328
318 class bsddb3DBTestCase(anydbmDBTestCase): 329 class bsddb3DBTestCase(anydbmDBTestCase):
319 def setUp(self): 330 def setUp(self):
320 from roundup.backends import bsddb3 331 from roundup.backends import bsddb3
322 if os.path.exists(config.DATABASE): 333 if os.path.exists(config.DATABASE):
323 shutil.rmtree(config.DATABASE) 334 shutil.rmtree(config.DATABASE)
324 os.makedirs(config.DATABASE + '/files') 335 os.makedirs(config.DATABASE + '/files')
325 self.db = bsddb3.Database(config, 'test') 336 self.db = bsddb3.Database(config, 'test')
326 setupSchema(self.db, 1) 337 setupSchema(self.db, 1)
338 self.db2 = bsddb3.Database(config, 'test')
339 setupSchema(self.db2, 0)
327 340
328 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): 341 class bsddb3ReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
329 def setUp(self): 342 def setUp(self):
330 from roundup.backends import bsddb3 343 from roundup.backends import bsddb3
331 # remove previous test, ignore errors 344 # remove previous test, ignore errors
334 os.makedirs(config.DATABASE + '/files') 347 os.makedirs(config.DATABASE + '/files')
335 db = bsddb3.Database(config, 'test') 348 db = bsddb3.Database(config, 'test')
336 setupSchema(db, 1) 349 setupSchema(db, 1)
337 self.db = bsddb3.Database(config) 350 self.db = bsddb3.Database(config)
338 setupSchema(self.db, 0) 351 setupSchema(self.db, 0)
352 self.db2 = bsddb3.Database(config, 'test')
353 setupSchema(self.db2, 0)
339 354
340 355
341 def suite(): 356 def suite():
342 l = [ 357 l = [
343 unittest.makeSuite(anydbmDBTestCase, 'test'), 358 unittest.makeSuite(anydbmDBTestCase, 'test'),
360 375
361 return unittest.TestSuite(l) 376 return unittest.TestSuite(l)
362 377
363 # 378 #
364 # $Log: not supported by cvs2svn $ 379 # $Log: not supported by cvs2svn $
380 # Revision 1.20 2002/04/03 05:54:31 richard
381 # Fixed serialisation problem by moving the serialisation step out of the
382 # hyperdb.Class (get, set) into the hyperdb.Database.
383 #
384 # Also fixed htmltemplate after the showid changes I made yesterday.
385 #
386 # Unit tests for all of the above written.
387 #
365 # Revision 1.19 2002/02/25 14:34:31 grubert 388 # Revision 1.19 2002/02/25 14:34:31 grubert
366 # . use blobfiles in back_anydbm which is used in back_bsddb. 389 # . use blobfiles in back_anydbm which is used in back_bsddb.
367 # change test_db as dirlist does not work for subdirectories. 390 # change test_db as dirlist does not work for subdirectories.
368 # ATTENTION: blobfiles now creates subdirectories for files. 391 # ATTENTION: blobfiles now creates subdirectories for files.
369 # 392 #

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