comparison test/test_db.py @ 1222:bc3bc3248dd1

added Class.find() unit test, fixed implementations
author Richard Jones <richard@users.sourceforge.net>
date Thu, 26 Sep 2002 03:04:24 +0000
parents 1c5bc0e2ed7d
children 3a028d2f7830
comparison
equal deleted inserted replaced
1221:778297033003 1222:bc3bc3248dd1
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.55 2002-09-24 01:59:44 richard Exp $ 18 # $Id: test_db.py,v 1.56 2002-09-26 03:04:24 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
427 self.db.commit() 427 self.db.commit()
428 self.db.issue.set(id, status='2') 428 self.db.issue.set(id, status='2')
429 self.db.commit() 429 self.db.commit()
430 430
431 # sleep for at least a second, then get a date to pack at 431 # sleep for at least a second, then get a date to pack at
432 time.sleep(2) 432 time.sleep(1)
433 pack_before = date.Date('.') 433 pack_before = date.Date('.')
434 time.sleep(2) 434
435 435 # wait another second and add one more entry
436 # one more entry 436 time.sleep(1)
437 self.db.issue.set(id, status='3') 437 self.db.issue.set(id, status='3')
438 self.db.commit() 438 self.db.commit()
439 jlen = len(self.db.getjournal('issue', id))
439 440
440 # pack 441 # pack
441 self.db.pack(pack_before) 442 self.db.pack(pack_before)
442 journal = self.db.getjournal('issue', id)
443 443
444 # we should have the create and last set entries now 444 # we should have the create and last set entries now
445 self.assertEqual(2, len(journal)) 445 self.assertEqual(jlen-1, len(self.db.getjournal('issue', id)))
446 446
447 def testIDGeneration(self): 447 def testIDGeneration(self):
448 id1 = self.db.issue.create(title="spam", status='1') 448 id1 = self.db.issue.create(title="spam", status='1')
449 id2 = self.db2.issue.create(title="eggs", status='2') 449 id2 = self.db2.issue.create(title="eggs", status='2')
450 self.assertNotEqual(id1, id2) 450 self.assertNotEqual(id1, id2)
484 self.db.indexer.force_reindex() 484 self.db.indexer.force_reindex()
485 self.db.post_init() 485 self.db.post_init()
486 self.db.indexer.quiet = 9 486 self.db.indexer.quiet = 9
487 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue), 487 self.assertEquals(self.db.indexer.search(['flebble'], self.db.issue),
488 {'1': {}}) 488 {'1': {}})
489
490 #
491 # searching tests follow
492 #
493 def testFind(self):
494 self.db.user.create(username='test')
495 ids = []
496 ids.append(self.db.issue.create(status="1", nosy=['1']))
497 oddid = self.db.issue.create(status="2", nosy=['2'])
498 ids.append(self.db.issue.create(status="1", nosy=['1','2']))
499 self.db.issue.create(status="3", nosy=['1'])
500 ids.sort()
501
502 # should match first and third
503 got = self.db.issue.find(status='1')
504 got.sort()
505 self.assertEqual(got, ids)
506
507 # none
508 self.assertEqual(self.db.issue.find(status='4'), [])
509
510 # should match first three
511 got = self.db.issue.find(status='1', nosy='2')
512 got.sort()
513 ids.append(oddid)
514 ids.sort()
515 self.assertEqual(got, ids)
516
517 # none
518 self.assertEqual(self.db.issue.find(status='4', nosy='3'), [])
489 519
490 def testStringFind(self): 520 def testStringFind(self):
491 ids = [] 521 ids = []
492 ids.append(self.db.issue.create(title="spam")) 522 ids.append(self.db.issue.create(title="spam"))
493 self.db.issue.create(title="not spam") 523 self.db.issue.create(title="not spam")
627 def testIDGeneration(self): 657 def testIDGeneration(self):
628 id1 = self.db.issue.create(title="spam", status='1') 658 id1 = self.db.issue.create(title="spam", status='1')
629 id2 = self.db.issue.create(title="eggs", status='2') 659 id2 = self.db.issue.create(title="eggs", status='2')
630 self.assertNotEqual(id1, id2) 660 self.assertNotEqual(id1, id2)
631 661
662 def testFilteringString(self):
663 ae, filt = self.filteringSetup()
664 ae(filt(None, {'title': 'issue one'}, ('+','id'), (None,None)), ['1'])
665 # XXX gadfly can't do substring LIKE searches
666 #ae(filt(None, {'title': 'issue'}, ('+','id'), (None,None)),
667 # ['1','2','3'])
668
632 class gadflyReadOnlyDBTestCase(anydbmReadOnlyDBTestCase): 669 class gadflyReadOnlyDBTestCase(anydbmReadOnlyDBTestCase):
633 def setUp(self): 670 def setUp(self):
634 from roundup.backends import gadfly 671 from roundup.backends import gadfly
635 # remove previous test, ignore errors 672 # remove previous test, ignore errors
636 if os.path.exists(config.DATABASE): 673 if os.path.exists(config.DATABASE):

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