comparison test/test_db.py @ 1481:31cc79f966ac maint-0.5

backport of rdbms backend fix
author Richard Jones <richard@users.sourceforge.net>
date Thu, 27 Feb 2003 11:21:04 +0000
parents 83f33642d220
children ba2812e0edc5
comparison
equal deleted inserted replaced
1460:115490358190 1481:31cc79f966ac
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.63 2002-12-12 09:31:04 richard Exp $ 18 # $Id: test_db.py,v 1.63.2.1 2003-02-27 11:21:04 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
74 shutil.rmtree(config.DATABASE) 74 shutil.rmtree(config.DATABASE)
75 os.makedirs(config.DATABASE + '/files') 75 os.makedirs(config.DATABASE + '/files')
76 self.db = anydbm.Database(config, 'admin') 76 self.db = anydbm.Database(config, 'admin')
77 setupSchema(self.db, 1, anydbm) 77 setupSchema(self.db, 1, anydbm)
78 78
79 def testIDGeneration(self): 79 #
80 id1 = self.db.issue.create(title="spam", status='1') 80 # schema mutation
81 id2 = self.db.issue.create(title="eggs", status='2') 81 #
82 self.assertNotEqual(id1, id2) 82 def testAddProperty(self):
83
84 def testStringChange(self):
85 for commit in (0,1):
86 # test set & retrieve
87 nid = self.db.issue.create(title="spam", status='1')
88 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam')
89
90 # change and make sure we retrieve the correct value
91 self.db.issue.set(nid, title='eggs')
92 if commit: self.db.commit()
93 self.assertEqual(self.db.issue.get(nid, 'title'), 'eggs')
94
95 def testStringUnset(self):
96 for commit in (0,1):
97 nid = self.db.issue.create(title="spam", status='1')
98 if commit: self.db.commit()
99 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam')
100 # make sure we can unset
101 self.db.issue.set(nid, title=None)
102 if commit: self.db.commit()
103 self.assertEqual(self.db.issue.get(nid, "title"), None)
104
105 def testLinkChange(self):
106 for commit in (0,1):
107 nid = self.db.issue.create(title="spam", status='1')
108 if commit: self.db.commit()
109 self.assertEqual(self.db.issue.get(nid, "status"), '1')
110 self.db.issue.set(nid, status='2')
111 if commit: self.db.commit()
112 self.assertEqual(self.db.issue.get(nid, "status"), '2')
113
114 def testLinkUnset(self):
115 for commit in (0,1):
116 nid = self.db.issue.create(title="spam", status='1')
117 if commit: self.db.commit()
118 self.db.issue.set(nid, status=None)
119 if commit: self.db.commit()
120 self.assertEqual(self.db.issue.get(nid, "status"), None)
121
122 def testMultilinkChange(self):
123 for commit in (0,1):
124 u1 = self.db.user.create(username='foo%s'%commit)
125 u2 = self.db.user.create(username='bar%s'%commit)
126 nid = self.db.issue.create(title="spam", nosy=[u1])
127 if commit: self.db.commit()
128 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1])
129 self.db.issue.set(nid, nosy=[])
130 if commit: self.db.commit()
131 self.assertEqual(self.db.issue.get(nid, "nosy"), [])
132 self.db.issue.set(nid, nosy=[u1,u2])
133 if commit: self.db.commit()
134 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1,u2])
135
136 def testDateChange(self):
137 for commit in (0,1):
138 nid = self.db.issue.create(title="spam", status='1')
139 a = self.db.issue.get(nid, "deadline")
140 if commit: self.db.commit()
141 self.db.issue.set(nid, deadline=date.Date())
142 b = self.db.issue.get(nid, "deadline")
143 if commit: self.db.commit()
144 self.assertNotEqual(a, b)
145 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00'))
146
147 def testDateUnset(self):
148 for commit in (0,1):
149 nid = self.db.issue.create(title="spam", status='1')
150 self.db.issue.set(nid, deadline=date.Date())
151 if commit: self.db.commit()
152 self.assertNotEqual(self.db.issue.get(nid, "deadline"), None)
153 self.db.issue.set(nid, deadline=None)
154 if commit: self.db.commit()
155 self.assertEqual(self.db.issue.get(nid, "deadline"), None)
156
157 def testIntervalChange(self):
158 for commit in (0,1):
159 nid = self.db.issue.create(title="spam", status='1')
160 if commit: self.db.commit()
161 a = self.db.issue.get(nid, "foo")
162 i = date.Interval('-1d')
163 self.db.issue.set(nid, foo=i)
164 if commit: self.db.commit()
165 self.assertNotEqual(self.db.issue.get(nid, "foo"), a)
166 self.assertEqual(i, self.db.issue.get(nid, "foo"))
167 j = date.Interval('1y')
168 self.db.issue.set(nid, foo=j)
169 if commit: self.db.commit()
170 self.assertNotEqual(self.db.issue.get(nid, "foo"), i)
171 self.assertEqual(j, self.db.issue.get(nid, "foo"))
172
173 def testIntervalUnset(self):
174 for commit in (0,1):
175 nid = self.db.issue.create(title="spam", status='1')
176 self.db.issue.set(nid, foo=date.Interval('-1d'))
177 if commit: self.db.commit()
178 self.assertNotEqual(self.db.issue.get(nid, "foo"), None)
179 self.db.issue.set(nid, foo=None)
180 if commit: self.db.commit()
181 self.assertEqual(self.db.issue.get(nid, "foo"), None)
182
183 def testBooleanChange(self):
184 userid = self.db.user.create(username='foo', assignable=1)
185 self.assertEqual(1, self.db.user.get(userid, 'assignable'))
186 self.db.user.set(userid, assignable=0)
187 self.assertEqual(self.db.user.get(userid, 'assignable'), 0)
188 self.db.user.set(userid, assignable=None)
189 self.assertEqual(self.db.user.get('1', "assignable"), None)
190
191 def testNumberChange(self):
192 nid = self.db.user.create(username='foo', age=1)
193 self.assertEqual(1, self.db.user.get(nid, 'age'))
194 self.db.user.set('1', age=3)
195 self.assertNotEqual(self.db.user.get('1', 'age'), 1)
196 self.db.user.set('1', age=1.0)
197 self.db.user.set('1', age=None)
198 self.assertEqual(self.db.user.get('1', "age"), None)
199
200 def testKeyValue(self):
201 newid = self.db.user.create(username="spam")
202 self.assertEqual(self.db.user.lookup('spam'), newid)
203 self.db.commit()
204 self.assertEqual(self.db.user.lookup('spam'), newid)
205 self.db.user.retire(newid)
206 self.assertRaises(KeyError, self.db.user.lookup, 'spam')
207
208 def testNewProperty(self):
209 self.db.issue.create(title="spam", status='1') 83 self.db.issue.create(title="spam", status='1')
84 self.db.commit()
85
210 self.db.issue.addprop(fixer=Link("user")) 86 self.db.issue.addprop(fixer=Link("user"))
211 # force any post-init stuff to happen 87 # force any post-init stuff to happen
212 self.db.post_init() 88 self.db.post_init()
213 props = self.db.issue.getprops() 89 props = self.db.issue.getprops()
214 keys = props.keys() 90 keys = props.keys()
215 keys.sort() 91 keys.sort()
216 self.assertEqual(keys, ['activity', 'assignedto', 'creation', 92 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
217 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages', 93 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
218 'nosy', 'status', 'superseder', 'title']) 94 'nosy', 'status', 'superseder', 'title'])
219 self.assertEqual(self.db.issue.get('1', "fixer"), None) 95 self.assertEqual(self.db.issue.get('1', "fixer"), None)
96
97 def testRemoveProperty(self):
98 self.db.issue.create(title="spam", status='1')
99 self.db.commit()
100
101 del self.db.issue.properties['title']
102 self.db.post_init()
103 props = self.db.issue.getprops()
104 keys = props.keys()
105 keys.sort()
106 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
107 'creator', 'deadline', 'files', 'foo', 'id', 'messages',
108 'nosy', 'status', 'superseder'])
109 self.assertEqual(self.db.issue.list(), ['1'])
110
111 def testAddRemoveProperty(self):
112 self.db.issue.create(title="spam", status='1')
113 self.db.commit()
114
115 self.db.issue.addprop(fixer=Link("user"))
116 del self.db.issue.properties['title']
117 self.db.post_init()
118 props = self.db.issue.getprops()
119 keys = props.keys()
120 keys.sort()
121 self.assertEqual(keys, ['activity', 'assignedto', 'creation',
122 'creator', 'deadline', 'files', 'fixer', 'foo', 'id', 'messages',
123 'nosy', 'status', 'superseder'])
124 self.assertEqual(self.db.issue.list(), ['1'])
125
126 def testIDGeneration(self):
127 id1 = self.db.issue.create(title="spam", status='1')
128 id2 = self.db.issue.create(title="eggs", status='2')
129 self.assertNotEqual(id1, id2)
130
131 def testStringChange(self):
132 for commit in (0,1):
133 # test set & retrieve
134 nid = self.db.issue.create(title="spam", status='1')
135 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam')
136
137 # change and make sure we retrieve the correct value
138 self.db.issue.set(nid, title='eggs')
139 if commit: self.db.commit()
140 self.assertEqual(self.db.issue.get(nid, 'title'), 'eggs')
141
142 def testStringUnset(self):
143 for commit in (0,1):
144 nid = self.db.issue.create(title="spam", status='1')
145 if commit: self.db.commit()
146 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam')
147 # make sure we can unset
148 self.db.issue.set(nid, title=None)
149 if commit: self.db.commit()
150 self.assertEqual(self.db.issue.get(nid, "title"), None)
151
152 def testLinkChange(self):
153 for commit in (0,1):
154 nid = self.db.issue.create(title="spam", status='1')
155 if commit: self.db.commit()
156 self.assertEqual(self.db.issue.get(nid, "status"), '1')
157 self.db.issue.set(nid, status='2')
158 if commit: self.db.commit()
159 self.assertEqual(self.db.issue.get(nid, "status"), '2')
160
161 def testLinkUnset(self):
162 for commit in (0,1):
163 nid = self.db.issue.create(title="spam", status='1')
164 if commit: self.db.commit()
165 self.db.issue.set(nid, status=None)
166 if commit: self.db.commit()
167 self.assertEqual(self.db.issue.get(nid, "status"), None)
168
169 def testMultilinkChange(self):
170 for commit in (0,1):
171 u1 = self.db.user.create(username='foo%s'%commit)
172 u2 = self.db.user.create(username='bar%s'%commit)
173 nid = self.db.issue.create(title="spam", nosy=[u1])
174 if commit: self.db.commit()
175 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1])
176 self.db.issue.set(nid, nosy=[])
177 if commit: self.db.commit()
178 self.assertEqual(self.db.issue.get(nid, "nosy"), [])
179 self.db.issue.set(nid, nosy=[u1,u2])
180 if commit: self.db.commit()
181 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1,u2])
182
183 def testDateChange(self):
184 for commit in (0,1):
185 nid = self.db.issue.create(title="spam", status='1')
186 a = self.db.issue.get(nid, "deadline")
187 if commit: self.db.commit()
188 self.db.issue.set(nid, deadline=date.Date())
189 b = self.db.issue.get(nid, "deadline")
190 if commit: self.db.commit()
191 self.assertNotEqual(a, b)
192 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00'))
193
194 def testDateUnset(self):
195 for commit in (0,1):
196 nid = self.db.issue.create(title="spam", status='1')
197 self.db.issue.set(nid, deadline=date.Date())
198 if commit: self.db.commit()
199 self.assertNotEqual(self.db.issue.get(nid, "deadline"), None)
200 self.db.issue.set(nid, deadline=None)
201 if commit: self.db.commit()
202 self.assertEqual(self.db.issue.get(nid, "deadline"), None)
203
204 def testIntervalChange(self):
205 for commit in (0,1):
206 nid = self.db.issue.create(title="spam", status='1')
207 if commit: self.db.commit()
208 a = self.db.issue.get(nid, "foo")
209 i = date.Interval('-1d')
210 self.db.issue.set(nid, foo=i)
211 if commit: self.db.commit()
212 self.assertNotEqual(self.db.issue.get(nid, "foo"), a)
213 self.assertEqual(i, self.db.issue.get(nid, "foo"))
214 j = date.Interval('1y')
215 self.db.issue.set(nid, foo=j)
216 if commit: self.db.commit()
217 self.assertNotEqual(self.db.issue.get(nid, "foo"), i)
218 self.assertEqual(j, self.db.issue.get(nid, "foo"))
219
220 def testIntervalUnset(self):
221 for commit in (0,1):
222 nid = self.db.issue.create(title="spam", status='1')
223 self.db.issue.set(nid, foo=date.Interval('-1d'))
224 if commit: self.db.commit()
225 self.assertNotEqual(self.db.issue.get(nid, "foo"), None)
226 self.db.issue.set(nid, foo=None)
227 if commit: self.db.commit()
228 self.assertEqual(self.db.issue.get(nid, "foo"), None)
229
230 def testBooleanChange(self):
231 userid = self.db.user.create(username='foo', assignable=1)
232 self.assertEqual(1, self.db.user.get(userid, 'assignable'))
233 self.db.user.set(userid, assignable=0)
234 self.assertEqual(self.db.user.get(userid, 'assignable'), 0)
235 self.db.user.set(userid, assignable=None)
236 self.assertEqual(self.db.user.get('1', "assignable"), None)
237
238 def testNumberChange(self):
239 nid = self.db.user.create(username='foo', age=1)
240 self.assertEqual(1, self.db.user.get(nid, 'age'))
241 self.db.user.set('1', age=3)
242 self.assertNotEqual(self.db.user.get('1', 'age'), 1)
243 self.db.user.set('1', age=1.0)
244 self.db.user.set('1', age=None)
245 self.assertEqual(self.db.user.get('1', "age"), None)
246
247 def testKeyValue(self):
248 newid = self.db.user.create(username="spam")
249 self.assertEqual(self.db.user.lookup('spam'), newid)
250 self.db.commit()
251 self.assertEqual(self.db.user.lookup('spam'), newid)
252 self.db.user.retire(newid)
253 self.assertRaises(KeyError, self.db.user.lookup, 'spam')
220 254
221 def testRetire(self): 255 def testRetire(self):
222 self.db.issue.create(title="spam", status='1') 256 self.db.issue.create(title="spam", status='1')
223 b = self.db.status.get('1', 'name') 257 b = self.db.status.get('1', 'name')
224 a = self.db.status.list() 258 a = self.db.status.list()

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