]> granicus.if.org Git - python/commitdiff
Adding test coverage for cgi.FieldStorage based on the scenario mentioned in issue...
authorSenthil Kumaran <senthil@uthcode.com>
Sun, 12 Jan 2014 06:16:55 +0000 (22:16 -0800)
committerSenthil Kumaran <senthil@uthcode.com>
Sun, 12 Jan 2014 06:16:55 +0000 (22:16 -0800)
Lib/test/test_cgi.py

index 7fdd482b9424e48e2628c80f238d8cdec849ce72..349d5e9b40cef6eb3414eb677d1b4723e3cbb196 100644 (file)
@@ -5,6 +5,8 @@ import sys
 import tempfile
 import unittest
 
+from collections import namedtuple
+
 class HackedSysModule:
     # The regression test will have real values in sys.argv, which
     # will completely confuse the test of the cgi module
@@ -232,6 +234,14 @@ class CgiTests(unittest.TestCase):
         # as long as the chunksize is 1 << 16.
         self.assertTrue(f.numcalls > 2)
 
+    def test_fieldstorage_invalid(self):
+        fs = cgi.FieldStorage()
+        self.assertFalse(fs)
+        self.assertRaises(TypeError, bool(fs))
+        self.assertEqual(list(fs), list(fs.keys()))
+        fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue'))
+        self.assertTrue(fs)
+
     def test_fieldstorage_multipart(self):
         #Test basic FieldStorage multipart parsing
         env = {'REQUEST_METHOD':'POST', 'CONTENT_TYPE':'multipart/form-data; boundary=---------------------------721837373350705526688164684', 'CONTENT_LENGTH':'558'}