Mercurial > p > roundup > code
comparison test/test_cgi.py @ 1425:58ce2c1614cd
new form handling complete
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Thu, 13 Feb 2003 07:38:34 +0000 |
| parents | 3ac43c62a250 |
| children | c70068162e64 |
comparison
equal
deleted
inserted
replaced
| 1424:6709b759b16a | 1425:58ce2c1614cd |
|---|---|
| 6 # | 6 # |
| 7 # This module is distributed in the hope that it will be useful, | 7 # This module is distributed in the hope that it will be useful, |
| 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 8 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 9 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 10 # | 10 # |
| 11 # $Id: test_cgi.py,v 1.7 2003-02-12 06:41:58 richard Exp $ | 11 # $Id: test_cgi.py,v 1.8 2003-02-13 07:38:34 richard Exp $ |
| 12 | 12 |
| 13 import unittest, os, shutil, errno, sys, difflib, cgi | 13 import unittest, os, shutil, errno, sys, difflib, cgi |
| 14 | 14 |
| 15 from roundup.cgi import client | 15 from roundup.cgi import client |
| 16 from roundup import init, instance, password, hyperdb, date | 16 from roundup import init, instance, password, hyperdb, date |
| 17 | |
| 18 class FileUpload: | |
| 19 def __init__(self, content, filename): | |
| 20 self.content = content | |
| 21 self.filename = filename | |
| 17 | 22 |
| 18 def makeForm(args): | 23 def makeForm(args): |
| 19 form = cgi.FieldStorage() | 24 form = cgi.FieldStorage() |
| 20 for k,v in args.items(): | 25 for k,v in args.items(): |
| 21 if type(v) is type([]): | 26 if type(v) is type([]): |
| 22 [form.list.append(cgi.MiniFieldStorage(k, x)) for x in v] | 27 [form.list.append(cgi.MiniFieldStorage(k, x)) for x in v] |
| 28 elif isinstance(v, FileUpload): | |
| 29 x = cgi.MiniFieldStorage(k, v.content) | |
| 30 x.filename = v.filename | |
| 31 form.list.append(x) | |
| 23 else: | 32 else: |
| 24 form.list.append(cgi.MiniFieldStorage(k, v)) | 33 form.list.append(cgi.MiniFieldStorage(k, v)) |
| 25 return form | 34 return form |
| 26 | 35 |
| 27 class config: | 36 class config: |
| 70 | 79 |
| 71 # | 80 # |
| 72 # Empty form | 81 # Empty form |
| 73 # | 82 # |
| 74 def testNothing(self): | 83 def testNothing(self): |
| 75 self.assertEqual(self.parseForm({}), {'test': {}}) | 84 self.assertEqual(self.parseForm({}), ({('test', None): {}}, [])) |
| 76 | 85 |
| 77 def testNothingWithRequired(self): | 86 def testNothingWithRequired(self): |
| 78 self.assertRaises(ValueError, self.parseForm, {':required': 'string'}) | 87 self.assertRaises(ValueError, self.parseForm, {':required': 'string'}) |
| 79 self.assertRaises(ValueError, self.parseForm, | 88 self.assertRaises(ValueError, self.parseForm, |
| 80 {':required': 'title,status', 'status':'1'}, 'issue') | 89 {':required': 'title,status', 'status':'1'}, 'issue') |
| 94 | 103 |
| 95 # | 104 # |
| 96 # String | 105 # String |
| 97 # | 106 # |
| 98 def testEmptyString(self): | 107 def testEmptyString(self): |
| 99 self.assertEqual(self.parseForm({'string': ''}), {'test': {}}) | 108 self.assertEqual(self.parseForm({'string': ''}), |
| 100 self.assertEqual(self.parseForm({'string': ' '}), {'test': {}}) | 109 ({('test', None): {}}, [])) |
| 110 self.assertEqual(self.parseForm({'string': ' '}), | |
| 111 ({('test', None): {}}, [])) | |
| 101 self.assertRaises(ValueError, self.parseForm, {'string': ['', '']}) | 112 self.assertRaises(ValueError, self.parseForm, {'string': ['', '']}) |
| 102 | 113 |
| 103 def testSetString(self): | 114 def testSetString(self): |
| 104 self.assertEqual(self.parseForm({'string': 'foo'}), | 115 self.assertEqual(self.parseForm({'string': 'foo'}), |
| 105 {'test': {'string': 'foo'}}) | 116 ({('test', None): {'string': 'foo'}}, [])) |
| 106 self.assertEqual(self.parseForm({'string': 'a\r\nb\r\n'}), | 117 self.assertEqual(self.parseForm({'string': 'a\r\nb\r\n'}), |
| 107 {'test': {'string': 'a\nb'}}) | 118 ({('test', None): {'string': 'a\nb'}}, [])) |
| 108 nodeid = self.db.issue.create(title='foo') | 119 nodeid = self.db.issue.create(title='foo') |
| 109 self.assertEqual(self.parseForm({'title': 'foo'}, 'issue', nodeid), | 120 self.assertEqual(self.parseForm({'title': 'foo'}, 'issue', nodeid), |
| 110 {'issue'+nodeid: {}}) | 121 ({('issue', nodeid): {}}, [])) |
| 111 | 122 |
| 112 def testEmptyStringSet(self): | 123 def testEmptyStringSet(self): |
| 113 nodeid = self.db.issue.create(title='foo') | 124 nodeid = self.db.issue.create(title='foo') |
| 114 self.assertEqual(self.parseForm({'title': ''}, 'issue', nodeid), | 125 self.assertEqual(self.parseForm({'title': ''}, 'issue', nodeid), |
| 115 {'issue'+nodeid: {'title': None}}) | 126 ({('issue', nodeid): {'title': None}}, [])) |
| 116 nodeid = self.db.issue.create(title='foo') | 127 nodeid = self.db.issue.create(title='foo') |
| 117 self.assertEqual(self.parseForm({'title': ' '}, 'issue', nodeid), | 128 self.assertEqual(self.parseForm({'title': ' '}, 'issue', nodeid), |
| 118 {'issue'+nodeid: {'title': None}}) | 129 ({('issue', nodeid): {'title': None}}, [])) |
| 130 | |
| 131 def testFileUpload(self): | |
| 132 file = FileUpload('foo', 'foo.txt') | |
| 133 self.assertEqual(self.parseForm({'content': file}, 'file'), | |
| 134 ({('file', None): {'content': 'foo', 'name': 'foo.txt', | |
| 135 'type': 'text/plain'}}, [])) | |
| 119 | 136 |
| 120 # | 137 # |
| 121 # Link | 138 # Link |
| 122 # | 139 # |
| 123 def testEmptyLink(self): | 140 def testEmptyLink(self): |
| 124 self.assertEqual(self.parseForm({'link': ''}), {'test': {}}) | 141 self.assertEqual(self.parseForm({'link': ''}), |
| 125 self.assertEqual(self.parseForm({'link': ' '}), {'test': {}}) | 142 ({('test', None): {}}, [])) |
| 143 self.assertEqual(self.parseForm({'link': ' '}), | |
| 144 ({('test', None): {}}, [])) | |
| 126 self.assertRaises(ValueError, self.parseForm, {'link': ['', '']}) | 145 self.assertRaises(ValueError, self.parseForm, {'link': ['', '']}) |
| 127 self.assertEqual(self.parseForm({'link': '-1'}), {'test': {}}) | 146 self.assertEqual(self.parseForm({'link': '-1'}), |
| 147 ({('test', None): {}}, [])) | |
| 128 | 148 |
| 129 def testSetLink(self): | 149 def testSetLink(self): |
| 130 self.assertEqual(self.parseForm({'status': 'unread'}, 'issue'), | 150 self.assertEqual(self.parseForm({'status': 'unread'}, 'issue'), |
| 131 {'issue': {'status': '1'}}) | 151 ({('issue', None): {'status': '1'}}, [])) |
| 132 self.assertEqual(self.parseForm({'status': '1'}, 'issue'), | 152 self.assertEqual(self.parseForm({'status': '1'}, 'issue'), |
| 133 {'issue': {'status': '1'}}) | 153 ({('issue', None): {'status': '1'}}, [])) |
| 134 nodeid = self.db.issue.create(status='unread') | 154 nodeid = self.db.issue.create(status='unread') |
| 135 self.assertEqual(self.parseForm({'status': 'unread'}, 'issue', nodeid), | 155 self.assertEqual(self.parseForm({'status': 'unread'}, 'issue', nodeid), |
| 136 {'issue'+nodeid: {}}) | 156 ({('issue', nodeid): {}}, [])) |
| 137 | 157 |
| 138 def testUnsetLink(self): | 158 def testUnsetLink(self): |
| 139 nodeid = self.db.issue.create(status='unread') | 159 nodeid = self.db.issue.create(status='unread') |
| 140 self.assertEqual(self.parseForm({'status': '-1'}, 'issue', nodeid), | 160 self.assertEqual(self.parseForm({'status': '-1'}, 'issue', nodeid), |
| 141 {'issue'+nodeid: {'status': None}}) | 161 ({('issue', nodeid): {'status': None}}, [])) |
| 142 | 162 |
| 143 def testInvalidLinkValue(self): | 163 def testInvalidLinkValue(self): |
| 144 # XXX This is not the current behaviour - should we enforce this? | 164 # XXX This is not the current behaviour - should we enforce this? |
| 145 # self.assertRaises(IndexError, self.parseForm, | 165 # self.assertRaises(IndexError, self.parseForm, |
| 146 # {'status': '4'})) | 166 # {'status': '4'})) |
| 147 self.assertRaises(ValueError, self.parseForm, {'link': 'frozzle'}) | 167 self.assertRaises(ValueError, self.parseForm, {'link': 'frozzle'}) |
| 148 | 168 self.assertRaises(ValueError, self.parseForm, {'status': 'frozzle'}, |
| 149 self.assertRaises(ValueError, self.parseForm, {'link': 'frozzle'}) | 169 'issue') |
| 150 | 170 |
| 151 # | 171 # |
| 152 # Multilink | 172 # Multilink |
| 153 # | 173 # |
| 154 def testEmptyMultilink(self): | 174 def testEmptyMultilink(self): |
| 155 self.assertEqual(self.parseForm({'nosy': ''}), {'test': {}}) | 175 self.assertEqual(self.parseForm({'nosy': ''}), |
| 156 self.assertEqual(self.parseForm({'nosy': ' '}), {'test': {}}) | 176 ({('test', None): {}}, [])) |
| 177 self.assertEqual(self.parseForm({'nosy': ' '}), | |
| 178 ({('test', None): {}}, [])) | |
| 157 | 179 |
| 158 def testSetMultilink(self): | 180 def testSetMultilink(self): |
| 159 self.assertEqual(self.parseForm({'nosy': '1'}, 'issue'), | 181 self.assertEqual(self.parseForm({'nosy': '1'}, 'issue'), |
| 160 {'issue': {'nosy': ['1']}}) | 182 ({('issue', None): {'nosy': ['1']}}, [])) |
| 161 self.assertEqual(self.parseForm({'nosy': 'admin'}, 'issue'), | 183 self.assertEqual(self.parseForm({'nosy': 'admin'}, 'issue'), |
| 162 {'issue': {'nosy': ['1']}}) | 184 ({('issue', None): {'nosy': ['1']}}, [])) |
| 163 self.assertEqual(self.parseForm({'nosy': ['1','2']}, 'issue'), | 185 self.assertEqual(self.parseForm({'nosy': ['1','2']}, 'issue'), |
| 164 {'issue': {'nosy': ['1','2']}}) | 186 ({('issue', None): {'nosy': ['1','2']}}, [])) |
| 165 self.assertEqual(self.parseForm({'nosy': '1,2'}, 'issue'), | 187 self.assertEqual(self.parseForm({'nosy': '1,2'}, 'issue'), |
| 166 {'issue': {'nosy': ['1','2']}}) | 188 ({('issue', None): {'nosy': ['1','2']}}, [])) |
| 167 self.assertEqual(self.parseForm({'nosy': 'admin,2'}, 'issue'), | 189 self.assertEqual(self.parseForm({'nosy': 'admin,2'}, 'issue'), |
| 168 {'issue': {'nosy': ['1','2']}}) | 190 ({('issue', None): {'nosy': ['1','2']}}, [])) |
| 169 | 191 |
| 170 def testEmptyMultilinkSet(self): | 192 def testEmptyMultilinkSet(self): |
| 171 nodeid = self.db.issue.create(nosy=['1','2']) | 193 nodeid = self.db.issue.create(nosy=['1','2']) |
| 172 self.assertEqual(self.parseForm({'nosy': ''}, 'issue', nodeid), | 194 self.assertEqual(self.parseForm({'nosy': ''}, 'issue', nodeid), |
| 173 {'issue'+nodeid: {'nosy': []}}) | 195 ({('issue', nodeid): {'nosy': []}}, [])) |
| 174 nodeid = self.db.issue.create(nosy=['1','2']) | 196 nodeid = self.db.issue.create(nosy=['1','2']) |
| 175 self.assertEqual(self.parseForm({'nosy': ' '}, 'issue', nodeid), | 197 self.assertEqual(self.parseForm({'nosy': ' '}, 'issue', nodeid), |
| 176 {'issue'+nodeid: {'nosy': []}}) | 198 ({('issue', nodeid): {'nosy': []}}, [])) |
| 177 self.assertEqual(self.parseForm({'nosy': '1,2'}, 'issue', nodeid), | 199 self.assertEqual(self.parseForm({'nosy': '1,2'}, 'issue', nodeid), |
| 178 {'issue'+nodeid: {}}) | 200 ({('issue', nodeid): {}}, [])) |
| 179 | 201 |
| 180 def testInvalidMultilinkValue(self): | 202 def testInvalidMultilinkValue(self): |
| 181 # XXX This is not the current behaviour - should we enforce this? | 203 # XXX This is not the current behaviour - should we enforce this? |
| 182 # self.assertRaises(IndexError, self.parseForm, | 204 # self.assertRaises(IndexError, self.parseForm, |
| 183 # {'nosy': '4'})) | 205 # {'nosy': '4'})) |
| 189 | 211 |
| 190 def testMultilinkAdd(self): | 212 def testMultilinkAdd(self): |
| 191 nodeid = self.db.issue.create(nosy=['1']) | 213 nodeid = self.db.issue.create(nosy=['1']) |
| 192 # do nothing | 214 # do nothing |
| 193 self.assertEqual(self.parseForm({':add:nosy': ''}, 'issue', nodeid), | 215 self.assertEqual(self.parseForm({':add:nosy': ''}, 'issue', nodeid), |
| 194 {'issue'+nodeid: {}}) | 216 ({('issue', nodeid): {}}, [])) |
| 195 | 217 |
| 196 # do something ;) | 218 # do something ;) |
| 197 self.assertEqual(self.parseForm({':add:nosy': '2'}, 'issue', nodeid), | 219 self.assertEqual(self.parseForm({':add:nosy': '2'}, 'issue', nodeid), |
| 198 {'issue'+nodeid: {'nosy': ['1','2']}}) | 220 ({('issue', nodeid): {'nosy': ['1','2']}}, [])) |
| 199 self.assertEqual(self.parseForm({':add:nosy': '2,mary'}, 'issue', | 221 self.assertEqual(self.parseForm({':add:nosy': '2,mary'}, 'issue', |
| 200 nodeid), {'issue'+nodeid: {'nosy': ['1','2','4']}}) | 222 nodeid), ({('issue', nodeid): {'nosy': ['1','2','4']}}, [])) |
| 201 self.assertEqual(self.parseForm({':add:nosy': ['2','3']}, 'issue', | 223 self.assertEqual(self.parseForm({':add:nosy': ['2','3']}, 'issue', |
| 202 nodeid), {'issue'+nodeid: {'nosy': ['1','2','3']}}) | 224 nodeid), ({('issue', nodeid): {'nosy': ['1','2','3']}}, [])) |
| 203 | 225 |
| 204 def testMultilinkAddNew(self): | 226 def testMultilinkAddNew(self): |
| 205 self.assertEqual(self.parseForm({':add:nosy': ['2','3']}, 'issue'), | 227 self.assertEqual(self.parseForm({':add:nosy': ['2','3']}, 'issue'), |
| 206 {'issue': {'nosy': ['2','3']}}) | 228 ({('issue', None): {'nosy': ['2','3']}}, [])) |
| 207 | 229 |
| 208 def testMultilinkRemove(self): | 230 def testMultilinkRemove(self): |
| 209 nodeid = self.db.issue.create(nosy=['1','2']) | 231 nodeid = self.db.issue.create(nosy=['1','2']) |
| 210 # do nothing | 232 # do nothing |
| 211 self.assertEqual(self.parseForm({':remove:nosy': ''}, 'issue', nodeid), | 233 self.assertEqual(self.parseForm({':remove:nosy': ''}, 'issue', nodeid), |
| 212 {'issue'+nodeid: {}}) | 234 ({('issue', nodeid): {}}, [])) |
| 213 | 235 |
| 214 # do something ;) | 236 # do something ;) |
| 215 self.assertEqual(self.parseForm({':remove:nosy': '1'}, 'issue', | 237 self.assertEqual(self.parseForm({':remove:nosy': '1'}, 'issue', |
| 216 nodeid), {'issue'+nodeid: {'nosy': ['2']}}) | 238 nodeid), ({('issue', nodeid): {'nosy': ['2']}}, [])) |
| 217 self.assertEqual(self.parseForm({':remove:nosy': 'admin,2'}, | 239 self.assertEqual(self.parseForm({':remove:nosy': 'admin,2'}, |
| 218 'issue', nodeid), {'issue'+nodeid: {'nosy': []}}) | 240 'issue', nodeid), ({('issue', nodeid): {'nosy': []}}, [])) |
| 219 self.assertEqual(self.parseForm({':remove:nosy': ['1','2']}, | 241 self.assertEqual(self.parseForm({':remove:nosy': ['1','2']}, |
| 220 'issue', nodeid), {'issue'+nodeid: {'nosy': []}}) | 242 'issue', nodeid), ({('issue', nodeid): {'nosy': []}}, [])) |
| 243 | |
| 244 # add and remove | |
| 245 self.assertEqual(self.parseForm({':add:nosy': ['3'], | |
| 246 ':remove:nosy': ['1','2']}, | |
| 247 'issue', nodeid), ({('issue', nodeid): {'nosy': ['3']}}, [])) | |
| 221 | 248 |
| 222 # remove one that doesn't exist? | 249 # remove one that doesn't exist? |
| 223 self.assertRaises(ValueError, self.parseForm, {':remove:nosy': '4'}, | 250 self.assertRaises(ValueError, self.parseForm, {':remove:nosy': '4'}, |
| 224 'issue', nodeid) | 251 'issue', nodeid) |
| 225 | 252 |
| 226 def testMultilinkRetired(self): | 253 def testMultilinkRetired(self): |
| 227 self.db.user.retire('2') | 254 self.db.user.retire('2') |
| 228 self.assertEqual(self.parseForm({'nosy': ['2','3']}, 'issue'), | 255 self.assertEqual(self.parseForm({'nosy': ['2','3']}, 'issue'), |
| 229 {'issue': {'nosy': ['2','3']}}) | 256 ({('issue', None): {'nosy': ['2','3']}}, [])) |
| 230 nodeid = self.db.issue.create(nosy=['1','2']) | 257 nodeid = self.db.issue.create(nosy=['1','2']) |
| 231 self.assertEqual(self.parseForm({':remove:nosy': '2'}, 'issue', | 258 self.assertEqual(self.parseForm({':remove:nosy': '2'}, 'issue', |
| 232 nodeid), {'issue'+nodeid: {'nosy': ['1']}}) | 259 nodeid), ({('issue', nodeid): {'nosy': ['1']}}, [])) |
| 233 self.assertEqual(self.parseForm({':add:nosy': '3'}, 'issue', nodeid), | 260 self.assertEqual(self.parseForm({':add:nosy': '3'}, 'issue', nodeid), |
| 234 {'issue'+nodeid: {'nosy': ['1','2','3']}}) | 261 ({('issue', nodeid): {'nosy': ['1','2','3']}}, [])) |
| 235 | 262 |
| 236 def testAddRemoveNonexistant(self): | 263 def testAddRemoveNonexistant(self): |
| 237 self.assertRaises(ValueError, self.parseForm, {':remove:foo': '2'}, | 264 self.assertRaises(ValueError, self.parseForm, {':remove:foo': '2'}, |
| 238 'issue') | 265 'issue') |
| 239 self.assertRaises(ValueError, self.parseForm, {':add:foo': '2'}, | 266 self.assertRaises(ValueError, self.parseForm, {':add:foo': '2'}, |
| 242 # | 269 # |
| 243 # Password | 270 # Password |
| 244 # | 271 # |
| 245 def testEmptyPassword(self): | 272 def testEmptyPassword(self): |
| 246 self.assertEqual(self.parseForm({'password': ''}, 'user'), | 273 self.assertEqual(self.parseForm({'password': ''}, 'user'), |
| 247 {'user': {}}) | 274 ({('user', None): {}}, [])) |
| 248 self.assertEqual(self.parseForm({'password': ''}, 'user'), | 275 self.assertEqual(self.parseForm({'password': ''}, 'user'), |
| 249 {'user': {}}) | 276 ({('user', None): {}}, [])) |
| 250 self.assertRaises(ValueError, self.parseForm, {'password': ['', '']}, | 277 self.assertRaises(ValueError, self.parseForm, {'password': ['', '']}, |
| 251 'user') | 278 'user') |
| 252 self.assertRaises(ValueError, self.parseForm, {'password': 'foo', | 279 self.assertRaises(ValueError, self.parseForm, {'password': 'foo', |
| 253 'password:confirm': ['', '']}, 'user') | 280 'password:confirm': ['', '']}, 'user') |
| 254 | 281 |
| 255 def testSetPassword(self): | 282 def testSetPassword(self): |
| 256 self.assertEqual(self.parseForm({'password': 'foo', | 283 self.assertEqual(self.parseForm({'password': 'foo', |
| 257 'password:confirm': 'foo'}, 'user'), {'user': {'password': 'foo'}}) | 284 'password:confirm': 'foo'}, 'user'), |
| 285 ({('user', None): {'password': 'foo'}}, [])) | |
| 258 | 286 |
| 259 def testSetPasswordConfirmBad(self): | 287 def testSetPasswordConfirmBad(self): |
| 260 self.assertRaises(ValueError, self.parseForm, {'password': 'foo'}, | 288 self.assertRaises(ValueError, self.parseForm, {'password': 'foo'}, |
| 261 'user') | 289 'user') |
| 262 self.assertRaises(ValueError, self.parseForm, {'password': 'foo', | 290 self.assertRaises(ValueError, self.parseForm, {'password': 'foo', |
| 264 | 292 |
| 265 def testEmptyPasswordNotSet(self): | 293 def testEmptyPasswordNotSet(self): |
| 266 nodeid = self.db.user.create(username='1', | 294 nodeid = self.db.user.create(username='1', |
| 267 password=password.Password('foo')) | 295 password=password.Password('foo')) |
| 268 self.assertEqual(self.parseForm({'password': ''}, 'user', nodeid), | 296 self.assertEqual(self.parseForm({'password': ''}, 'user', nodeid), |
| 269 {'user'+nodeid: {}}) | 297 ({('user', nodeid): {}}, [])) |
| 270 nodeid = self.db.user.create(username='2', | 298 nodeid = self.db.user.create(username='2', |
| 271 password=password.Password('foo')) | 299 password=password.Password('foo')) |
| 272 self.assertEqual(self.parseForm({'password': '', | 300 self.assertEqual(self.parseForm({'password': '', |
| 273 'password:confirm': ''}, 'user', nodeid), | 301 'password:confirm': ''}, 'user', nodeid), |
| 274 {'user'+nodeid: {}}) | 302 ({('user', nodeid): {}}, [])) |
| 275 | 303 |
| 276 # | 304 # |
| 277 # Boolean | 305 # Boolean |
| 278 # | 306 # |
| 279 def testEmptyBoolean(self): | 307 def testEmptyBoolean(self): |
| 280 self.assertEqual(self.parseForm({'boolean': ''}), {'test': {}}) | 308 self.assertEqual(self.parseForm({'boolean': ''}), |
| 281 self.assertEqual(self.parseForm({'boolean': ' '}), {'test': {}}) | 309 ({('test', None): {}}, [])) |
| 310 self.assertEqual(self.parseForm({'boolean': ' '}), | |
| 311 ({('test', None): {}}, [])) | |
| 282 self.assertRaises(ValueError, self.parseForm, {'boolean': ['', '']}) | 312 self.assertRaises(ValueError, self.parseForm, {'boolean': ['', '']}) |
| 283 | 313 |
| 284 def testSetBoolean(self): | 314 def testSetBoolean(self): |
| 285 self.assertEqual(self.parseForm({'boolean': 'yes'}), | 315 self.assertEqual(self.parseForm({'boolean': 'yes'}), |
| 286 {'test': {'boolean': 1}}) | 316 ({('test', None): {'boolean': 1}}, [])) |
| 287 self.assertEqual(self.parseForm({'boolean': 'a\r\nb\r\n'}), | 317 self.assertEqual(self.parseForm({'boolean': 'a\r\nb\r\n'}), |
| 288 {'test': {'boolean': 0}}) | 318 ({('test', None): {'boolean': 0}}, [])) |
| 289 nodeid = self.db.test.create(boolean=1) | 319 nodeid = self.db.test.create(boolean=1) |
| 290 self.assertEqual(self.parseForm({'boolean': 'yes'}, 'test', nodeid), | 320 self.assertEqual(self.parseForm({'boolean': 'yes'}, 'test', nodeid), |
| 291 {'test'+nodeid: {}}) | 321 ({('test', nodeid): {}}, [])) |
| 292 nodeid = self.db.test.create(boolean=0) | 322 nodeid = self.db.test.create(boolean=0) |
| 293 self.assertEqual(self.parseForm({'boolean': 'no'}, 'test', nodeid), | 323 self.assertEqual(self.parseForm({'boolean': 'no'}, 'test', nodeid), |
| 294 {'test'+nodeid: {}}) | 324 ({('test', nodeid): {}}, [])) |
| 295 | 325 |
| 296 def testEmptyBooleanSet(self): | 326 def testEmptyBooleanSet(self): |
| 297 nodeid = self.db.test.create(boolean=0) | 327 nodeid = self.db.test.create(boolean=0) |
| 298 self.assertEqual(self.parseForm({'boolean': ''}, 'test', nodeid), | 328 self.assertEqual(self.parseForm({'boolean': ''}, 'test', nodeid), |
| 299 {'test'+nodeid: {'boolean': None}}) | 329 ({('test', nodeid): {'boolean': None}}, [])) |
| 300 nodeid = self.db.test.create(boolean=1) | 330 nodeid = self.db.test.create(boolean=1) |
| 301 self.assertEqual(self.parseForm({'boolean': ' '}, 'test', nodeid), | 331 self.assertEqual(self.parseForm({'boolean': ' '}, 'test', nodeid), |
| 302 {'test'+nodeid: {'boolean': None}}) | 332 ({('test', nodeid): {'boolean': None}}, [])) |
| 303 | 333 |
| 304 # | 334 # |
| 305 # Date | 335 # Date |
| 306 # | 336 # |
| 307 def testEmptyDate(self): | 337 def testEmptyDate(self): |
| 308 self.assertEqual(self.parseForm({'date': ''}), {'test': {}}) | 338 self.assertEqual(self.parseForm({'date': ''}), |
| 309 self.assertEqual(self.parseForm({'date': ' '}), {'test': {}}) | 339 ({('test', None): {}}, [])) |
| 340 self.assertEqual(self.parseForm({'date': ' '}), | |
| 341 ({('test', None): {}}, [])) | |
| 310 self.assertRaises(ValueError, self.parseForm, {'date': ['', '']}) | 342 self.assertRaises(ValueError, self.parseForm, {'date': ['', '']}) |
| 311 | 343 |
| 312 def testSetDate(self): | 344 def testSetDate(self): |
| 313 self.assertEqual(self.parseForm({'date': '2003-01-01'}), | 345 self.assertEqual(self.parseForm({'date': '2003-01-01'}), |
| 314 {'test': {'date': date.Date('2003-01-01')}}) | 346 ({('test', None): {'date': date.Date('2003-01-01')}}, [])) |
| 315 nodeid = self.db.test.create(date=date.Date('2003-01-01')) | 347 nodeid = self.db.test.create(date=date.Date('2003-01-01')) |
| 316 self.assertEqual(self.parseForm({'date': '2003-01-01'}, 'test', | 348 self.assertEqual(self.parseForm({'date': '2003-01-01'}, 'test', |
| 317 nodeid), {'test'+nodeid: {}}) | 349 nodeid), ({('test', nodeid): {}}, [])) |
| 318 | 350 |
| 319 def testEmptyDateSet(self): | 351 def testEmptyDateSet(self): |
| 320 nodeid = self.db.test.create(date=date.Date('.')) | 352 nodeid = self.db.test.create(date=date.Date('.')) |
| 321 self.assertEqual(self.parseForm({'date': ''}, 'test', nodeid), | 353 self.assertEqual(self.parseForm({'date': ''}, 'test', nodeid), |
| 322 {'test'+nodeid: {'date': None}}) | 354 ({('test', nodeid): {'date': None}}, [])) |
| 323 nodeid = self.db.test.create(date=date.Date('1970-01-01.00:00:00')) | 355 nodeid = self.db.test.create(date=date.Date('1970-01-01.00:00:00')) |
| 324 self.assertEqual(self.parseForm({'date': ' '}, 'test', nodeid), | 356 self.assertEqual(self.parseForm({'date': ' '}, 'test', nodeid), |
| 325 {'test'+nodeid: {'date': None}}) | 357 ({('test', nodeid): {'date': None}}, [])) |
| 326 | 358 |
| 327 # | 359 # |
| 328 # Test multiple items in form | 360 # Test multiple items in form |
| 329 # | 361 # |
| 330 def testMultiple(self): | 362 def testMultiple(self): |
| 331 self.assertEqual(self.parseForm({'string': 'a', 'issue@title': 'b'}), | 363 self.assertEqual(self.parseForm({'string': 'a', 'issue-1@title': 'b'}), |
| 332 {'test': {'string': 'a'}, 'issue': {'title': 'b'}}) | 364 ({('test', None): {'string': 'a'}, ('issue', '-1'): |
| 365 {'title': 'b'}}, [])) | |
| 333 nodeid = self.db.test.create() | 366 nodeid = self.db.test.create() |
| 334 self.assertEqual(self.parseForm({'string': 'a', 'issue@title': 'b'}, | 367 self.assertEqual(self.parseForm({'string': 'a', 'issue-1@title': 'b'}, |
| 335 'test', nodeid), | 368 'test', nodeid), ({('test', nodeid): {'string': 'a'}, |
| 336 {'test1': {'string': 'a'}, 'issue': {'title': 'b'}}) | 369 ('issue', '-1'): {'title': 'b'}}, [])) |
| 370 self.assertEqual(self.parseForm({ | |
| 371 'string': 'a', | |
| 372 'issue-1@:add:nosy': '1', | |
| 373 'issue-2@:link:superseder': 'issue-1', | |
| 374 }), | |
| 375 ({('test', None): {'string': 'a'}, | |
| 376 ('issue', '-1'): {'nosy': ['1']}, | |
| 377 ('issue', '-2'): {}}, | |
| 378 [('issue', '-2', 'superseder', | |
| 379 [(('issue', '-1'), ('issue', '-1'))]) | |
| 380 ] | |
| 381 ) | |
| 382 ) | |
| 383 | |
| 384 def testLinkBadDesignator(self): | |
| 385 self.assertRaises(ValueError, self.parseForm, | |
| 386 {'test-1@:link:link': 'blah'}) | |
| 387 self.assertRaises(ValueError, self.parseForm, | |
| 388 {'test-1@:link:link': 'issue'}) | |
| 389 | |
| 390 def testBackwardsCompat(self): | |
| 391 self.assertEqual(self.parseForm({':note': 'spam'}, 'issue'), | |
| 392 ({('issue', None): {}, ('msg', '-1'): {'content': 'spam'}}, | |
| 393 [('issue', None, 'messages', [('msg', '-1')])])) | |
| 394 file = FileUpload('foo', 'foo.txt') | |
| 395 self.assertEqual(self.parseForm({':file': file}, 'issue'), | |
| 396 ({('issue', None): {}, ('file', '-1'): {'content': 'foo', | |
| 397 'name': 'foo.txt', 'type': 'text/plain'}}, | |
| 398 [('issue', None, 'files', [('file', '-1')])])) | |
| 337 | 399 |
| 338 def suite(): | 400 def suite(): |
| 339 l = [unittest.makeSuite(FormTestCase), | 401 l = [unittest.makeSuite(FormTestCase), |
| 340 ] | 402 ] |
| 341 return unittest.TestSuite(l) | 403 return unittest.TestSuite(l) |
| 342 | 404 |
| 405 def run(): | |
| 406 runner = unittest.TextTestRunner() | |
| 407 unittest.main(testRunner=runner) | |
| 408 | |
| 409 if __name__ == '__main__': | |
| 410 run() | |
| 343 | 411 |
| 344 # vim: set filetype=python ts=4 sw=4 et si | 412 # vim: set filetype=python ts=4 sw=4 et si |
