comparison test/db_test_base.py @ 1927:f5e8aeb1382d

Add 'safeget' method to hyperdb, including tests... ...and use it to simplify code in roundupdb.
author Johannes Gijsbers <jlgijsbers@users.sourceforge.net>
date Sun, 16 Nov 2003 19:59:10 +0000
parents f9316d2cd5ba
children b7912efc7f57
comparison
equal deleted inserted replaced
1926:3bdd34547fa7 1927:f5e8aeb1382d
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: db_test_base.py,v 1.8 2003-11-14 00:11:19 richard Exp $ 18 # $Id: db_test_base.py,v 1.9 2003-11-16 19:59:06 jlgijsbers Exp $
19 19
20 import unittest, os, shutil, errno, imp, sys, time, pprint 20 import unittest, os, shutil, errno, imp, sys, time, pprint
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, Node 23 Interval, DatabaseError, Boolean, Number, Node
796 796
797 # make sure the retired items are actually imported 797 # make sure the retired items are actually imported
798 ae(self.db.user.get('3', 'username'), 'blop') 798 ae(self.db.user.get('3', 'username'), 'blop')
799 ae(self.db.issue.get('2', 'title'), 'issue two') 799 ae(self.db.issue.get('2', 'title'), 'issue two')
800 800
801 def testSafeGet(self):
802 # existent nodeid, existent property
803 self.assertEqual(self.db.user.safeget('1', 'username'), 'admin')
804 # existent nodeid, nonexistent property
805 self.assertEqual(self.db.user.safeget('1', 'nonexistent'), None)
806 # nonexistent nodeid, existent property
807 self.assertEqual(self.db.user.safeget('999', 'username'), None)
808 # nonexistent nodeid, nonexistent property
809 self.assertEqual(self.db.user.safeget('999', 'nonexistent'), None)
810 # different default
811 self.assertEqual(self.db.issue.safeget('999', 'nosy', []), [])
812
801 class ROTest(MyTestCase): 813 class ROTest(MyTestCase):
802 def setUp(self): 814 def setUp(self):
803 # remove previous test, ignore errors 815 # remove previous test, ignore errors
804 if os.path.exists(config.DATABASE): 816 if os.path.exists(config.DATABASE):
805 shutil.rmtree(config.DATABASE) 817 shutil.rmtree(config.DATABASE)

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