comparison test/test_cgi.py @ 1384:a87f59436895 maint-0.5

ported CGI fixes from HEAD
author Richard Jones <richard@users.sourceforge.net>
date Wed, 15 Jan 2003 22:38:14 +0000
parents 56c5b4509378
children a61ca144d3a4
comparison
equal deleted inserted replaced
1371:56c5b4509378 1384:a87f59436895
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.4 2003-01-15 11:14:01 richard Exp $ 11 # $Id: test_cgi.py,v 1.4.2.1 2003-01-15 22:38:14 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 16 from roundup import init, instance, password
56 def testNothing(self): 56 def testNothing(self):
57 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, 57 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
58 makeForm({})), {}) 58 makeForm({})), {})
59 59
60 def testNothingWithRequired(self): 60 def testNothingWithRequired(self):
61 form = makeForm({':required': 'title'}) 61 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
62 self.assertRaises(ValueError, client.parsePropsFromForm, self.db, 62 self.db.issue, makeForm({':required': 'title'}))
63 self.db.issue, form) 63 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
64 self.db.issue, makeForm({':required': 'title,status',
65 'status':'1'}))
66 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
67 self.db.issue, makeForm({':required': ['title','status'],
68 'status':'1'}))
64 69
65 # 70 #
66 # String 71 # String
67 # 72 #
68 def testEmptyString(self): 73 def testEmptyString(self):
84 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, 89 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
85 makeForm({'title': ''}), nodeid), {'title': ''}) 90 makeForm({'title': ''}), nodeid), {'title': ''})
86 nodeid = self.db.issue.create(title='foo') 91 nodeid = self.db.issue.create(title='foo')
87 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, 92 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
88 makeForm({'title': ' '}), nodeid), {'title': ''}) 93 makeForm({'title': ' '}), nodeid), {'title': ''})
94
95 #
96 # Link
97 #
98 def testEmptyLink(self):
99 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
100 makeForm({'status': ''})), {})
101 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
102 makeForm({'status': ' '})), {})
103 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
104 self.db.issue, makeForm({'status': ['', '']}))
105 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
106 makeForm({'status': '-1'})), {})
107
108 def testSetLink(self):
109 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
110 makeForm({'status': 'unread'})), {'status': '1'})
111 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
112 makeForm({'status': '1'})), {'status': '1'})
113
114 def testUnsetLink(self):
115 nodeid = self.db.issue.create(status='unread')
116 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
117 makeForm({'status': '-1'}), nodeid), {'status': None})
118
119 def testInvalidLinkValue(self):
120 # XXX This is not the current behaviour - should we enforce this?
121 # self.assertRaises(IndexError, client.parsePropsFromForm, self.db,
122 # self.db.issue, makeForm({'status': '4'}))
123 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
124 self.db.issue, makeForm({'status': 'frozzle'}))
125 # XXX need a test for the TypeError where the link class doesn't define a key?
89 126
90 # 127 #
91 # Multilink 128 # Multilink
92 # 129 #
93 def testEmptyMultilink(self): 130 def testEmptyMultilink(self):
122 # self.db.issue, makeForm({'nosy': '4'})) 159 # self.db.issue, makeForm({'nosy': '4'}))
123 self.assertRaises(ValueError, client.parsePropsFromForm, self.db, 160 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
124 self.db.issue, makeForm({'nosy': 'frozzle'})) 161 self.db.issue, makeForm({'nosy': 'frozzle'}))
125 self.assertRaises(ValueError, client.parsePropsFromForm, self.db, 162 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
126 self.db.issue, makeForm({'nosy': '1,frozzle'})) 163 self.db.issue, makeForm({'nosy': '1,frozzle'}))
127 # XXX need a test for the TypeError (where the ML class doesn't define a key 164 # XXX need a test for the TypeError (where the ML class doesn't define a key?
128 165
129 def testMultilinkAdd(self): 166 def testMultilinkAdd(self):
130 nodeid = self.db.issue.create(nosy=['1']) 167 nodeid = self.db.issue.create(nosy=['1'])
131 # do nothing 168 # do nothing
132 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, 169 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
160 197
161 # remove one that doesn't exist? 198 # remove one that doesn't exist?
162 self.assertRaises(ValueError, client.parsePropsFromForm, self.db, 199 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
163 self.db.issue, makeForm({':remove:nosy': '4'}), nodeid) 200 self.db.issue, makeForm({':remove:nosy': '4'}), nodeid)
164 201
202 def testMultilinkRetired(self):
203 self.db.user.retire('2')
204 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
205 makeForm({'nosy': ['2','3']})), {'nosy': ['2','3']})
206 nodeid = self.db.issue.create(nosy=['1','2'])
207 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
208 makeForm({':remove:nosy': '2'}), nodeid), {'nosy': ['1']})
209 self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
210 makeForm({':add:nosy': '3'}), nodeid), {'nosy': ['1','2','3']})
211
212 def testAddRemoveNonexistant(self):
213 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
214 self.db.issue, makeForm({':remove:foo': '2'}))
215 self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
216 self.db.issue, makeForm({':add:foo': '2'}))
217
165 # 218 #
166 # Password 219 # Password
167 # 220 #
168 def testEmptyPassword(self): 221 def testEmptyPassword(self):
169 self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, 222 self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
193 self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, 246 self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
194 makeForm({'password': ''}), nodeid), {}) 247 makeForm({'password': ''}), nodeid), {})
195 nodeid = self.db.user.create(username='2', password=password.Password('foo')) 248 nodeid = self.db.user.create(username='2', password=password.Password('foo'))
196 self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, 249 self.assertEqual(client.parsePropsFromForm(self.db, self.db.user,
197 makeForm({'password': '', 'password:confirm': ''}), nodeid), {}) 250 makeForm({'password': '', 'password:confirm': ''}), nodeid), {})
251
252 #
253 # Boolean
254 #
255 # XXX this needs a property to work on.
256 # def testEmptyBoolean(self):
257 # self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
258 # makeForm({'title': ''})), {})
259 # self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
260 # makeForm({'title': ' '})), {})
261 # self.assertRaises(ValueError, client.parsePropsFromForm, self.db,
262 # self.db.issue, makeForm({'title': ['', '']}))
263
264 # def testSetBoolean(self):
265 # self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
266 # makeForm({'title': 'foo'})), {'title': 'foo'})
267 # self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
268 # makeForm({'title': 'a\r\nb\r\n'})), {'title': 'a\nb'})
269
270 # def testEmptyBooleanSet(self):
271 # nodeid = self.db.issue.create(title='foo')
272 # self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
273 # makeForm({'title': ''}), nodeid), {'title': ''})
274 # nodeid = self.db.issue.create(title='foo')
275 # self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue,
276 # makeForm({'title': ' '}), nodeid), {'title': ''})
198 277
199 278
200 def suite(): 279 def suite():
201 l = [unittest.makeSuite(FormTestCase), 280 l = [unittest.makeSuite(FormTestCase),
202 ] 281 ]

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