Skip to content

Commit df00655

Browse files
author
Richard Jones
committed
Cleaned up the hyperdb tests
1 parent 500dbdd commit df00655

File tree

1 file changed

+61
-33
lines changed

1 file changed

+61
-33
lines changed

test/test_db.py

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
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.22 2002-05-21 05:52:11 richard Exp $
18+
# $Id: test_db.py,v 1.23 2002-06-20 23:51:48 richard Exp $
1919

2020
import unittest, os, shutil
2121

@@ -27,15 +27,15 @@
2727
def setupSchema(db, create):
2828
status = Class(db, "status", name=String())
2929
status.setkey("name")
30+
user = Class(db, "user", username=String(), password=Password())
31+
file = FileClass(db, "file", name=String(), type=String())
32+
issue = Class(db, "issue", title=String(), status=Link("status"),
33+
nosy=Multilink("user"), deadline=Date(), foo=Interval())
3034
if create:
3135
status.create(name="unread")
3236
status.create(name="in-progress")
3337
status.create(name="testing")
3438
status.create(name="resolved")
35-
Class(db, "user", username=String(), password=Password())
36-
Class(db, "issue", title=String(), status=Link("status"),
37-
nosy=Multilink("user"), deadline=Date(), foo=Interval())
38-
FileClass(db, "file", name=String(), type=String())
3939
db.commit()
4040

4141
class MyTestCase(unittest.TestCase):
@@ -69,40 +69,65 @@ def setUp(self):
6969
self.db2 = anydbm.Database(config, 'test')
7070
setupSchema(self.db2, 0)
7171

72-
def testChanges(self):
72+
def testStringChange(self):
73+
self.db.issue.create(title="spam", status='1')
74+
self.assertEqual(self.db.issue.get('1', 'title'), 'spam')
75+
self.db.issue.set('1', title='eggs')
76+
self.assertEqual(self.db.issue.get('1', 'title'), 'eggs')
77+
self.db.commit()
78+
self.assertEqual(self.db.issue.get('1', 'title'), 'eggs')
79+
self.db.issue.create(title="spam", status='1')
80+
self.db.commit()
81+
self.assertEqual(self.db.issue.get('2', 'title'), 'spam')
82+
self.db.issue.set('2', title='ham')
83+
self.assertEqual(self.db.issue.get('2', 'title'), 'ham')
84+
self.db.commit()
85+
self.assertEqual(self.db.issue.get('2', 'title'), 'ham')
86+
87+
def testLinkChange(self):
88+
self.db.issue.create(title="spam", status='1')
89+
self.assertEqual(self.db.issue.get('1', "status"), '1')
90+
self.db.issue.set('1', status='2')
91+
self.assertEqual(self.db.issue.get('1', "status"), '2')
92+
93+
def testDateChange(self):
94+
self.db.issue.create(title="spam", status='1')
95+
a = self.db.issue.get('1', "deadline")
96+
self.db.issue.set('1', deadline=date.Date())
97+
b = self.db.issue.get('1', "deadline")
98+
self.db.commit()
99+
self.assertNotEqual(a, b)
100+
self.assertNotEqual(b, date.Date('1970-1-1 00:00:00'))
101+
self.db.issue.set('1', deadline=date.Date())
102+
103+
def testIntervalChange(self):
104+
self.db.issue.create(title="spam", status='1')
105+
a = self.db.issue.get('1', "foo")
106+
self.db.issue.set('1', foo=date.Interval('-1d'))
107+
self.assertNotEqual(self.db.issue.get('1', "foo"), a)
108+
109+
def testNewProperty(self):
73110
self.db.issue.create(title="spam", status='1')
74-
self.db.issue.create(title="eggs", status='2')
75-
self.db.issue.create(title="ham", status='4')
76-
self.db.issue.create(title="arguments", status='2')
77-
self.db.issue.create(title="abuse", status='1')
78111
self.db.issue.addprop(fixer=Link("user"))
79112
props = self.db.issue.getprops()
80113
keys = props.keys()
81114
keys.sort()
82115
self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'id', 'nosy',
83116
'status', 'title'])
84-
self.db.issue.set('5', status='2')
85-
self.db.issue.get('5', "status")
86-
87-
a = self.db.issue.get('5', "deadline")
88-
self.db.issue.set('5', deadline=date.Date())
89-
b = self.db.issue.get('5', "deadline")
90-
self.db.commit()
91-
self.assertNotEqual(a, b)
92-
self.assertNotEqual(b, date.Date('1970-1-1 00:00:00'))
93-
self.db.issue.set('5', deadline=date.Date())
94-
95-
a = self.db.issue.get('5', "foo")
96-
self.db.issue.set('5', foo=date.Interval('-1d'))
97-
self.assertNotEqual(a, self.db.issue.get('5', "foo"))
117+
self.assertEqual(self.db.issue.get('1', "fixer"), None)
98118

99-
self.db.status.get('2', "name")
100-
self.db.issue.get('5', "title")
101-
self.db.issue.find(status = self.db.status.lookup("in-progress"))
119+
def testRetire(self):
120+
self.db.issue.create(title="spam", status='1')
121+
b = self.db.status.get('1', 'name')
122+
a = self.db.status.list()
123+
self.db.status.retire('1')
124+
# make sure the list is different
125+
self.assertNotEqual(a, self.db.status.list())
126+
# can still access the node if necessary
127+
self.assertEqual(self.db.status.get('1', 'name'), b)
102128
self.db.commit()
103-
self.db.issue.history('5')
104-
self.db.status.history('1')
105-
self.db.status.history('2')
129+
self.assertEqual(self.db.status.get('1', 'name'), b)
130+
self.assertNotEqual(a, self.db.status.list())
106131

107132
def testSerialisation(self):
108133
self.db.issue.create(title="spam", status='1',
@@ -266,9 +291,6 @@ def testPack(self):
266291
journal = self.db.getjournal('issue', '1')
267292
self.assertEqual(2, len(journal))
268293

269-
def testRetire(self):
270-
pass
271-
272294
def testIDGeneration(self):
273295
id1 = self.db.issue.create(title="spam", status='1')
274296
id2 = self.db2.issue.create(title="eggs", status='2')
@@ -377,6 +399,12 @@ def suite():
377399

378400
#
379401
# $Log: not supported by cvs2svn $
402+
# Revision 1.22 2002/05/21 05:52:11 richard
403+
# Well whadya know, bsddb3 works again.
404+
# The backend is implemented _exactly_ the same as bsddb - so there's no
405+
# using its transaction or locking support. It'd be nice to use those some
406+
# day I suppose.
407+
#
380408
# Revision 1.21 2002/04/15 23:25:15 richard
381409
# . node ids are now generated from a lockable store - no more race conditions
382410
#

0 commit comments

Comments
 (0)