|
4 | 4 | import sys |
5 | 5 | import tempfile |
6 | 6 | import unittest |
| 7 | +from collections import namedtuple |
7 | 8 | from io import StringIO, BytesIO |
8 | 9 |
|
9 | 10 | class HackedSysModule: |
@@ -118,6 +119,23 @@ def gen_result(data, environ): |
118 | 119 |
|
119 | 120 | class CgiTests(unittest.TestCase): |
120 | 121 |
|
| 122 | + def test_parse_multipart(self): |
| 123 | + fp = BytesIO(POSTDATA.encode('latin1')) |
| 124 | + env = {'boundary': BOUNDARY.encode('latin1'), |
| 125 | + 'CONTENT-LENGTH': '558'} |
| 126 | + result = cgi.parse_multipart(fp, env) |
| 127 | + expected = {'submit': [b' Add '], 'id': [b'1234'], |
| 128 | + 'file': [b'Testing 123.\n'], 'title': [b'']} |
| 129 | + self.assertEqual(result, expected) |
| 130 | + |
| 131 | + def test_fieldstorage_properties(self): |
| 132 | + fs = cgi.FieldStorage() |
| 133 | + self.assertFalse(fs) |
| 134 | + self.assertIn("FieldStorage", repr(fs)) |
| 135 | + self.assertEqual(list(fs), list(fs.keys())) |
| 136 | + fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue')) |
| 137 | + self.assertTrue(fs) |
| 138 | + |
121 | 139 | def test_escape(self): |
122 | 140 | self.assertEqual("test & string", cgi.escape("test & string")) |
123 | 141 | self.assertEqual("<test string>", cgi.escape("<test string>")) |
@@ -151,7 +169,8 @@ def test_strict(self): |
151 | 169 |
|
152 | 170 | def test_log(self): |
153 | 171 | cgi.log("Testing") |
154 | | - |
| 172 | + cgi.logfile = "fail/" |
| 173 | + cgi.initlog("%s", "Testing initlog") |
155 | 174 | cgi.logfp = StringIO() |
156 | 175 | cgi.initlog("%s", "Testing initlog 1") |
157 | 176 | cgi.log("%s", "Testing log 2") |
|
0 commit comments