|
8 | 8 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
9 | 9 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
10 | 10 | # |
11 | | -# $Id: test_cgi.py,v 1.1 2003-01-14 06:15:58 richard Exp $ |
| 11 | +# $Id: test_cgi.py,v 1.2 2003-01-14 22:21:35 richard Exp $ |
12 | 12 |
|
13 | 13 | import unittest, os, shutil, errno, sys, difflib, cgi |
14 | 14 |
|
15 | 15 | from roundup.cgi import client |
16 | | -from roundup import init, instance |
| 16 | +from roundup import init, instance, password |
17 | 17 |
|
18 | 18 | def makeForm(args): |
19 | 19 | form = cgi.FieldStorage() |
20 | 20 | for k,v in args.items(): |
21 | 21 | if type(v) is type([]): |
22 | | - form.list.append([cgi.MiniFieldStorage(k, x) for x in v]) |
| 22 | + [form.list.append(cgi.MiniFieldStorage(k, x)) for x in v] |
23 | 23 | else: |
24 | 24 | form.list.append(cgi.MiniFieldStorage(k, v)) |
25 | 25 | return form |
@@ -50,14 +50,95 @@ def tearDown(self): |
50 | 50 | except OSError, error: |
51 | 51 | if error.errno not in (errno.ENOENT, errno.ESRCH): raise |
52 | 52 |
|
53 | | - def testParseNothing(self): |
54 | | - client.parsePropsFromForm(self.db, self.db.issue, makeForm({})) |
| 53 | + # |
| 54 | + # Empty form |
| 55 | + # |
| 56 | + def testNothing(self): |
| 57 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 58 | + makeForm({})), {}) |
55 | 59 |
|
56 | | - def testParseNothingWithRequired(self): |
| 60 | + def testNothingWithRequired(self): |
57 | 61 | form = makeForm({':required': 'title'}) |
58 | 62 | self.assertRaises(ValueError, client.parsePropsFromForm, self.db, |
59 | 63 | self.db.issue, form) |
60 | 64 |
|
| 65 | + # |
| 66 | + # String |
| 67 | + # |
| 68 | + def testEmptyString(self): |
| 69 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 70 | + makeForm({'title': ''})), {}) |
| 71 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 72 | + makeForm({'title': ' '})), {}) |
| 73 | + |
| 74 | + def testSetString(self): |
| 75 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 76 | + makeForm({'title': 'foo'})), {'title': 'foo'}) |
| 77 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 78 | + makeForm({'title': 'a\r\nb\r\n'})), {'title': 'a\nb'}) |
| 79 | + |
| 80 | + def testEmptyStringSet(self): |
| 81 | + nodeid = self.db.issue.create(title='foo') |
| 82 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 83 | + makeForm({'title': ''}), nodeid), {'title': ''}) |
| 84 | + nodeid = self.db.issue.create(title='foo') |
| 85 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 86 | + makeForm({'title': ' '}), nodeid), {'title': ''}) |
| 87 | + |
| 88 | + # |
| 89 | + # Multilink |
| 90 | + # |
| 91 | + def testEmptyMultilink(self): |
| 92 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 93 | + makeForm({'nosy': ''})), {}) |
| 94 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 95 | + makeForm({'nosy': ' '})), {}) |
| 96 | + |
| 97 | + def testSetMultilink(self): |
| 98 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 99 | + makeForm({'nosy': '1'})), {'nosy': ['1']}) |
| 100 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 101 | + makeForm({'nosy': ['1','2']})), {'nosy': ['1','2']}) |
| 102 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 103 | + makeForm({'nosy': '1,2'})), {'nosy': ['1','2']}) |
| 104 | + |
| 105 | + def testEmptyMultilinkSet(self): |
| 106 | + nodeid = self.db.issue.create(nosy=['1','2']) |
| 107 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 108 | + makeForm({'nosy': ''}), nodeid), {'nosy': []}) |
| 109 | + nodeid = self.db.issue.create(nosy=['1','2']) |
| 110 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.issue, |
| 111 | + makeForm({'nosy': ' '}), nodeid), {'nosy': []}) |
| 112 | + |
| 113 | + # |
| 114 | + # Password |
| 115 | + # |
| 116 | + def testEmptyPassword(self): |
| 117 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, |
| 118 | + makeForm({'password': ''})), {}) |
| 119 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, |
| 120 | + makeForm({'password': ''})), {}) |
| 121 | + |
| 122 | + def testSetPassword(self): |
| 123 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, |
| 124 | + makeForm({'password': 'foo', 'password:confirm': 'foo'})), |
| 125 | + {'password': 'foo'}) |
| 126 | + |
| 127 | + def testSetPasswordConfirmBad(self): |
| 128 | + self.assertRaises(ValueError, client.parsePropsFromForm, self.db, |
| 129 | + self.db.user, makeForm({'password': 'foo'})) |
| 130 | + self.assertRaises(ValueError, client.parsePropsFromForm, self.db, |
| 131 | + self.db.user, makeForm({'password': 'foo', |
| 132 | + 'password:confirm': 'bar'})) |
| 133 | + |
| 134 | + def testEmptyPasswordNOTSet(self): |
| 135 | + nodeid = self.db.user.create(username='1', password=password.Password('foo')) |
| 136 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, |
| 137 | + makeForm({'password': ''}), nodeid), {}) |
| 138 | + nodeid = self.db.user.create(username='2', password=password.Password('foo')) |
| 139 | + self.assertEqual(client.parsePropsFromForm(self.db, self.db.user, |
| 140 | + makeForm({'password': '', 'password:confirm': ''}), nodeid), {}) |
| 141 | + |
61 | 142 |
|
62 | 143 | def suite(): |
63 | 144 | l = [unittest.makeSuite(FormTestCase), |
|
0 commit comments