Mercurial > p > roundup > code
comparison test/test_db.py @ 1264:9e6743c00b5f
more anal unit tests
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 10 Oct 2002 08:04:46 +0000 |
| parents | 85d71588a1cf |
| children | d8de80de9fc4 |
comparison
equal
deleted
inserted
replaced
| 1263:db1ae414f363 | 1264:9e6743c00b5f |
|---|---|
| 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.60 2002-10-10 07:18:03 richard Exp $ | 18 # $Id: test_db.py,v 1.61 2002-10-10 08:04:46 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 |
| 79 setupSchema(self.db, 1, anydbm) | 79 setupSchema(self.db, 1, anydbm) |
| 80 self.db2 = anydbm.Database(config, 'admin') | 80 self.db2 = anydbm.Database(config, 'admin') |
| 81 setupSchema(self.db2, 0, anydbm) | 81 setupSchema(self.db2, 0, anydbm) |
| 82 | 82 |
| 83 def testStringChange(self): | 83 def testStringChange(self): |
| 84 # test set & retrieve | 84 for commit in (0,1): |
| 85 self.db.issue.create(title="spam", status='1') | 85 # test set & retrieve |
| 86 self.assertEqual(self.db.issue.get('1', 'title'), 'spam') | 86 nid = self.db.issue.create(title="spam", status='1') |
| 87 | 87 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam') |
| 88 # change and make sure we retrieve the correct value | 88 |
| 89 self.db.issue.set('1', title='eggs') | 89 # change and make sure we retrieve the correct value |
| 90 self.assertEqual(self.db.issue.get('1', 'title'), 'eggs') | 90 self.db.issue.set(nid, title='eggs') |
| 91 | 91 if commit: self.db.commit() |
| 92 # do some commit stuff | 92 self.assertEqual(self.db.issue.get(nid, 'title'), 'eggs') |
| 93 self.db.commit() | 93 |
| 94 self.assertEqual(self.db.issue.get('1', 'title'), 'eggs') | 94 def testStringUnset(self): |
| 95 self.db.issue.create(title="spam", status='1') | 95 for commit in (0,1): |
| 96 self.db.commit() | 96 nid = self.db.issue.create(title="spam", status='1') |
| 97 self.assertEqual(self.db.issue.get('2', 'title'), 'spam') | 97 if commit: self.db.commit() |
| 98 self.db.issue.set('2', title='ham') | 98 self.assertEqual(self.db.issue.get(nid, 'title'), 'spam') |
| 99 self.assertEqual(self.db.issue.get('2', 'title'), 'ham') | 99 # make sure we can unset |
| 100 self.db.commit() | 100 self.db.issue.set(nid, title=None) |
| 101 self.assertEqual(self.db.issue.get('2', 'title'), 'ham') | 101 if commit: self.db.commit() |
| 102 | 102 self.assertEqual(self.db.issue.get(nid, "title"), None) |
| 103 # make sure we can unset | |
| 104 self.db.issue.set('1', title=None) | |
| 105 self.assertEqual(self.db.issue.get('1', "title"), None) | |
| 106 | 103 |
| 107 def testLinkChange(self): | 104 def testLinkChange(self): |
| 108 self.db.issue.create(title="spam", status='1') | 105 for commit in (0,1): |
| 109 self.assertEqual(self.db.issue.get('1', "status"), '1') | 106 nid = self.db.issue.create(title="spam", status='1') |
| 110 self.db.issue.set('1', status='2') | 107 if commit: self.db.commit() |
| 111 self.assertEqual(self.db.issue.get('1', "status"), '2') | 108 self.assertEqual(self.db.issue.get(nid, "status"), '1') |
| 112 self.db.issue.set('1', status=None) | 109 self.db.issue.set(nid, status='2') |
| 113 self.assertEqual(self.db.issue.get('1', "status"), None) | 110 if commit: self.db.commit() |
| 111 self.assertEqual(self.db.issue.get(nid, "status"), '2') | |
| 112 | |
| 113 def testLinkUnset(self): | |
| 114 for commit in (0,1): | |
| 115 nid = self.db.issue.create(title="spam", status='1') | |
| 116 if commit: self.db.commit() | |
| 117 self.db.issue.set(nid, status=None) | |
| 118 if commit: self.db.commit() | |
| 119 self.assertEqual(self.db.issue.get(nid, "status"), None) | |
| 114 | 120 |
| 115 def testMultilinkChange(self): | 121 def testMultilinkChange(self): |
| 116 u1 = self.db.user.create(username='foo') | 122 for commit in (0,1): |
| 117 u2 = self.db.user.create(username='bar') | 123 u1 = self.db.user.create(username='foo%s'%commit) |
| 118 self.db.issue.create(title="spam", nosy=[u1]) | 124 u2 = self.db.user.create(username='bar%s'%commit) |
| 119 self.assertEqual(self.db.issue.get('1', "nosy"), [u1]) | 125 nid = self.db.issue.create(title="spam", nosy=[u1]) |
| 120 self.db.issue.set('1', nosy=[]) | 126 if commit: self.db.commit() |
| 121 self.assertEqual(self.db.issue.get('1', "nosy"), []) | 127 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1]) |
| 122 self.db.issue.set('1', nosy=[u1,u2]) | 128 self.db.issue.set(nid, nosy=[]) |
| 123 self.assertEqual(self.db.issue.get('1', "nosy"), [u1,u2]) | 129 if commit: self.db.commit() |
| 130 self.assertEqual(self.db.issue.get(nid, "nosy"), []) | |
| 131 self.db.issue.set(nid, nosy=[u1,u2]) | |
| 132 if commit: self.db.commit() | |
| 133 self.assertEqual(self.db.issue.get(nid, "nosy"), [u1,u2]) | |
| 124 | 134 |
| 125 def testDateChange(self): | 135 def testDateChange(self): |
| 126 self.db.issue.create(title="spam", status='1') | 136 for commit in (0,1): |
| 127 a = self.db.issue.get('1', "deadline") | 137 nid = self.db.issue.create(title="spam", status='1') |
| 128 self.db.issue.set('1', deadline=date.Date()) | 138 a = self.db.issue.get(nid, "deadline") |
| 129 b = self.db.issue.get('1', "deadline") | 139 if commit: self.db.commit() |
| 130 self.db.commit() | 140 self.db.issue.set(nid, deadline=date.Date()) |
| 131 self.assertNotEqual(a, b) | 141 b = self.db.issue.get(nid, "deadline") |
| 132 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00')) | 142 if commit: self.db.commit() |
| 133 self.db.issue.set('1', deadline=date.Date()) | 143 self.assertNotEqual(a, b) |
| 134 self.db.issue.set('1', deadline=None) | 144 self.assertNotEqual(b, date.Date('1970-1-1 00:00:00')) |
| 135 self.assertEqual(self.db.issue.get('1', "deadline"), None) | 145 |
| 146 def testDateUnset(self): | |
| 147 for commit in (0,1): | |
| 148 nid = self.db.issue.create(title="spam", status='1') | |
| 149 self.db.issue.set(nid, deadline=date.Date()) | |
| 150 if commit: self.db.commit() | |
| 151 self.assertNotEqual(self.db.issue.get(nid, "deadline"), None) | |
| 152 self.db.issue.set(nid, deadline=None) | |
| 153 if commit: self.db.commit() | |
| 154 self.assertEqual(self.db.issue.get(nid, "deadline"), None) | |
| 136 | 155 |
| 137 def testIntervalChange(self): | 156 def testIntervalChange(self): |
| 138 nid = self.db.issue.create(title="spam", status='1') | 157 for commit in (0,1): |
| 139 self.db.commit() | 158 nid = self.db.issue.create(title="spam", status='1') |
| 140 a = self.db.issue.get(nid, "foo") | 159 if commit: self.db.commit() |
| 141 i = date.Interval('-1d') | 160 a = self.db.issue.get(nid, "foo") |
| 142 self.db.issue.set(nid, foo=i) | 161 i = date.Interval('-1d') |
| 143 self.db.commit() | 162 self.db.issue.set(nid, foo=i) |
| 144 self.assertNotEqual(self.db.issue.get(nid, "foo"), a) | 163 if commit: self.db.commit() |
| 145 self.assertEqual(i, self.db.issue.get(nid, "foo")) | 164 self.assertNotEqual(self.db.issue.get(nid, "foo"), a) |
| 146 j = date.Interval('1y') | 165 self.assertEqual(i, self.db.issue.get(nid, "foo")) |
| 147 self.db.issue.set(nid, foo=j) | 166 j = date.Interval('1y') |
| 148 self.db.commit() | 167 self.db.issue.set(nid, foo=j) |
| 149 self.assertNotEqual(self.db.issue.get(nid, "foo"), i) | 168 if commit: self.db.commit() |
| 150 self.assertEqual(j, self.db.issue.get(nid, "foo")) | 169 self.assertNotEqual(self.db.issue.get(nid, "foo"), i) |
| 151 self.db.issue.set(nid, foo=None) | 170 self.assertEqual(j, self.db.issue.get(nid, "foo")) |
| 152 self.db.commit() | 171 |
| 153 self.assertEqual(self.db.issue.get(nid, "foo"), None) | 172 def testIntervalUnset(self): |
| 173 for commit in (0,1): | |
| 174 nid = self.db.issue.create(title="spam", status='1') | |
| 175 self.db.issue.set(nid, foo=date.Interval('-1d')) | |
| 176 if commit: self.db.commit() | |
| 177 self.assertNotEqual(self.db.issue.get(nid, "foo"), None) | |
| 178 self.db.issue.set(nid, foo=None) | |
| 179 if commit: self.db.commit() | |
| 180 self.assertEqual(self.db.issue.get(nid, "foo"), None) | |
| 154 | 181 |
| 155 def testBooleanChange(self): | 182 def testBooleanChange(self): |
| 156 userid = self.db.user.create(username='foo', assignable=1) | 183 userid = self.db.user.create(username='foo', assignable=1) |
| 157 self.assertEqual(1, self.db.user.get(userid, 'assignable')) | 184 self.assertEqual(1, self.db.user.get(userid, 'assignable')) |
| 158 self.db.user.set(userid, assignable=0) | 185 self.db.user.set(userid, assignable=0) |
