|
15 | 15 | # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
16 | 16 | # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
17 | 17 | # |
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 $ |
19 | 19 |
|
20 | 20 | import unittest, os, shutil |
21 | 21 |
|
|
27 | 27 | def setupSchema(db, create): |
28 | 28 | status = Class(db, "status", name=String()) |
29 | 29 | 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()) |
30 | 34 | if create: |
31 | 35 | status.create(name="unread") |
32 | 36 | status.create(name="in-progress") |
33 | 37 | status.create(name="testing") |
34 | 38 | 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()) |
39 | 39 | db.commit() |
40 | 40 |
|
41 | 41 | class MyTestCase(unittest.TestCase): |
@@ -69,40 +69,65 @@ def setUp(self): |
69 | 69 | self.db2 = anydbm.Database(config, 'test') |
70 | 70 | setupSchema(self.db2, 0) |
71 | 71 |
|
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): |
73 | 110 | 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') |
78 | 111 | self.db.issue.addprop(fixer=Link("user")) |
79 | 112 | props = self.db.issue.getprops() |
80 | 113 | keys = props.keys() |
81 | 114 | keys.sort() |
82 | 115 | self.assertEqual(keys, ['deadline', 'fixer', 'foo', 'id', 'nosy', |
83 | 116 | '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) |
98 | 118 |
|
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) |
102 | 128 | 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()) |
106 | 131 |
|
107 | 132 | def testSerialisation(self): |
108 | 133 | self.db.issue.create(title="spam", status='1', |
@@ -266,9 +291,6 @@ def testPack(self): |
266 | 291 | journal = self.db.getjournal('issue', '1') |
267 | 292 | self.assertEqual(2, len(journal)) |
268 | 293 |
|
269 | | - def testRetire(self): |
270 | | - pass |
271 | | - |
272 | 294 | def testIDGeneration(self): |
273 | 295 | id1 = self.db.issue.create(title="spam", status='1') |
274 | 296 | id2 = self.db2.issue.create(title="eggs", status='2') |
@@ -377,6 +399,12 @@ def suite(): |
377 | 399 |
|
378 | 400 | # |
379 | 401 | # $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 | +# |
380 | 408 | # Revision 1.21 2002/04/15 23:25:15 richard |
381 | 409 | # . node ids are now generated from a lockable store - no more race conditions |
382 | 410 | # |
|
0 commit comments