1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: test_db.py,v 1.39 2002-07-31 23:57:37 richard Exp $
18+ # $Id: test_db.py,v 1.40 2002-08-23 04:48:36 richard Exp $
1919
2020import unittest , os , shutil , time
2121
@@ -144,6 +144,8 @@ def testNumberChange(self):
144144 def testNewProperty (self ):
145145 self .db .issue .create (title = "spam" , status = '1' )
146146 self .db .issue .addprop (fixer = Link ("user" ))
147+ # force any post-init stuff to happen
148+ self .db .post_init ()
147149 props = self .db .issue .getprops ()
148150 keys = props .keys ()
149151 keys .sort ()
@@ -327,7 +329,6 @@ def testExceptions(self):
327329 ar (TypeError , self .db .user .set , '3' , username = 'foo' , assignable = 'true' )
328330
329331 def testJournals (self ):
330- self .db .issue .addprop (fixer = Link ("user" , do_journal = 'yes' ))
331332 self .db .user .create (username = "mary" )
332333 self .db .user .create (username = "pete" )
333334 self .db .issue .create (title = "spam" , status = '1' )
@@ -342,10 +343,9 @@ def testJournals(self):
342343 self .assertEqual (action , 'create' )
343344 keys = params .keys ()
344345 keys .sort ()
345- self .assertEqual (keys , ['assignedto' , 'deadline' , 'files' , 'fixer' ,
346+ self .assertEqual (keys , ['assignedto' , 'deadline' , 'files' ,
346347 'foo' , 'messages' , 'nosy' , 'status' , 'superseder' , 'title' ])
347348 self .assertEqual (None ,params ['deadline' ])
348- self .assertEqual (None ,params ['fixer' ])
349349 self .assertEqual (None ,params ['foo' ])
350350 self .assertEqual ([],params ['nosy' ])
351351 self .assertEqual ('1' ,params ['status' ])
@@ -354,26 +354,26 @@ def testJournals(self):
354354 # journal entry for link
355355 journal = self .db .getjournal ('user' , '1' )
356356 self .assertEqual (1 , len (journal ))
357- self .db .issue .set ('1' , fixer = '1' )
357+ self .db .issue .set ('1' , assignedto = '1' )
358358 self .db .commit ()
359359 journal = self .db .getjournal ('user' , '1' )
360360 self .assertEqual (2 , len (journal ))
361361 (nodeid , date_stamp , journaltag , action , params ) = journal [1 ]
362362 self .assertEqual ('1' , nodeid )
363363 self .assertEqual ('test' , journaltag )
364364 self .assertEqual ('link' , action )
365- self .assertEqual (('issue' , '1' , 'fixer ' ), params )
365+ self .assertEqual (('issue' , '1' , 'assignedto ' ), params )
366366
367367 # journal entry for unlink
368- self .db .issue .set ('1' , fixer = '2' )
368+ self .db .issue .set ('1' , assignedto = '2' )
369369 self .db .commit ()
370370 journal = self .db .getjournal ('user' , '1' )
371371 self .assertEqual (3 , len (journal ))
372372 (nodeid , date_stamp , journaltag , action , params ) = journal [2 ]
373373 self .assertEqual ('1' , nodeid )
374374 self .assertEqual ('test' , journaltag )
375375 self .assertEqual ('unlink' , action )
376- self .assertEqual (('issue' , '1' , 'fixer ' ), params )
376+ self .assertEqual (('issue' , '1' , 'assignedto ' ), params )
377377
378378 # test disabling journalling
379379 # ... get the last entry
@@ -400,12 +400,21 @@ def testPack(self):
400400 self .db .commit ()
401401 self .db .issue .set ('1' , status = '2' )
402402 self .db .commit ()
403+
404+ # sleep for at least a second, then get a date to pack at
405+ time .sleep (1 )
406+ pack_before = date .Date ('.' )
407+
408+ # one more entry
403409 self .db .issue .set ('1' , status = '3' )
404410 self .db .commit ()
405- pack_before = date .Date (". + 1d" )
411+
412+ # pack
406413 self .db .pack (pack_before )
407414 journal = self .db .getjournal ('issue' , '1' )
408- self .assertEqual (2 , len (journal ))
415+
416+ # we should have one entry now
417+ self .assertEqual (1 , len (journal ))
409418
410419 def testIDGeneration (self ):
411420 id1 = self .db .issue .create (title = "spam" , status = '1' )
@@ -528,6 +537,43 @@ def setUp(self):
528537 setupSchema (self .db2 , 0 , bsddb3 )
529538
530539
540+ class gadflyDBTestCase (anydbmDBTestCase ):
541+ ''' Gadfly doesn't support multiple connections to the one local
542+ database
543+ '''
544+ def setUp (self ):
545+ from roundup .backends import gadfly
546+ # remove previous test, ignore errors
547+ if os .path .exists (config .DATABASE ):
548+ shutil .rmtree (config .DATABASE )
549+ config .GADFLY_DATABASE = ('test' , config .DATABASE )
550+ os .makedirs (config .DATABASE + '/files' )
551+ self .db = gadfly .Database (config , 'test' )
552+ setupSchema (self .db , 1 , gadfly )
553+
554+ def testIDGeneration (self ):
555+ id1 = self .db .issue .create (title = "spam" , status = '1' )
556+ id2 = self .db .issue .create (title = "eggs" , status = '2' )
557+ self .assertNotEqual (id1 , id2 )
558+
559+ def testNewProperty (self ):
560+ # gadfly doesn't have an ALTER TABLE command :(
561+ pass
562+
563+ class gadflyReadOnlyDBTestCase (anydbmReadOnlyDBTestCase ):
564+ def setUp (self ):
565+ from roundup .backends import gadfly
566+ # remove previous test, ignore errors
567+ if os .path .exists (config .DATABASE ):
568+ shutil .rmtree (config .DATABASE )
569+ config .GADFLY_DATABASE = ('test' , config .DATABASE )
570+ os .makedirs (config .DATABASE + '/files' )
571+ db = gadfly .Database (config , 'test' )
572+ setupSchema (db , 1 , gadfly )
573+ self .db = gadfly .Database (config )
574+ setupSchema (self .db , 0 , gadfly )
575+
576+
531577class metakitDBTestCase (anydbmDBTestCase ):
532578 def setUp (self ):
533579 from roundup .backends import metakit
@@ -604,6 +650,13 @@ def suite():
604650 except :
605651 print 'bsddb3 module not found, skipping bsddb3 DBTestCase'
606652
653+ try :
654+ import gadfly
655+ l .append (unittest .makeSuite (gadflyDBTestCase , 'test' ))
656+ l .append (unittest .makeSuite (gadflyReadOnlyDBTestCase , 'test' ))
657+ except :
658+ print 'gadfly module not found, skipping gadfly DBTestCase'
659+
607660 try :
608661 import metakit
609662 l .append (unittest .makeSuite (metakitDBTestCase , 'test' ))
@@ -615,6 +668,9 @@ def suite():
615668
616669#
617670# $Log: not supported by cvs2svn $
671+ # Revision 1.39 2002/07/31 23:57:37 richard
672+ # . web forms may now unset Link values (like assignedto)
673+ #
618674# Revision 1.38 2002/07/26 08:27:00 richard
619675# Very close now. The cgi and mailgw now use the new security API. The two
620676# templates have been migrated to that setup. Lots of unit tests. Still some
0 commit comments