[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests/tests - test_Request.py:1.1.2.5.2.1

Karl Anderson cvs-admin at zope.org
Fri Nov 14 20:03:10 EST 2003


Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests/tests
In directory cvs.zope.org:/tmp/cvs-serv29797/FunctionalTests/tests

Modified Files:
      Tag: kra-intersest-branch
	test_Request.py 
Log Message:
merged changes from kra-misc-branch


=== Packages/FunctionalTests/FunctionalTests/tests/test_Request.py 1.1.2.5 => 1.1.2.5.2.1 ===
--- Packages/FunctionalTests/FunctionalTests/tests/test_Request.py:1.1.2.5	Wed Nov 12 14:51:47 2003
+++ Packages/FunctionalTests/FunctionalTests/tests/test_Request.py	Fri Nov 14 20:02:39 2003
@@ -241,42 +241,50 @@
             'last_visit:date=2001/11/12 17:21:03.25675 US/Eastern' )
         self.assertEquals( request.getMethod(), 'POST' )        
 
-#     def testMultipartContentTypeForm(self):
-#         """
-#         Test the content type of a multipart/form-data request
-#         after adding a form field.
-#         """
-#         request = self._makeOne( URL='http://example.com' )
-#         request.addField( 'last_visit:form=foobar' )
-#         self.assertEquals( request.getContentType()
-#                          , 'multipart/form-data' )
-
-    def testMultipartContentTypeFile(self):
+    def testMultipartContentTypeForm(self):
         """
         Test the content type of a multipart/form-data request
-        after adding a file field.
+        after adding a form field.
+        """
+        request = self._makeOne( URL='http://example.com' )
+        request.addField( 'last_visit=foobar' )
+        request.setMultipart()
+        self.assertEquals( request.getContentType()[:30]
+                         , 'multipart/form-data; boundary=' )
+
+   # def testMultipartContentTypeFile(self):
+   #     """
+   #     Test the content type of a multipart/form-data request
+   #     after adding a file field.
+   #     """
+   #     request = self._makeOne( URL='http://example.com' )
+   #     request.addField( 'last_visit:file=foobar' )
+   #     self.assertEquals( request.getContentType()[:30]
+   #                      , 'multipart/form-data; boundary=' )
+
+    def testMultipartDataForm(self):
+        """
+        Test that the data returned by a multipart/form-data request is proper,
+        and that the boundary matches that given by the content type.
         """
+        expected = '--[boundary]\nContent-Type: text/plain\ncontent-disposition: form-data; name="last_visit"\n\nfoobar\n--[boundary]\nContent-Type: text/plain\ncontent-disposition: form-data; name="next_visit"\n\nbazqux\n--[boundary]--\n'
         request = self._makeOne( URL='http://example.com' )
-        request.addField( 'last_visit:file=foobar' )
-        self.assertEquals( request.getContentType(),
-                           'multipart/form-data' )
+        request.addField( 'last_visit=foobar' )
+        request.addField( 'next_visit=bazqux' )
+        request.setMultipart()
+        got = request.getData()
+        type = request.getContentType()
+        import re
+        boundary = re.search('boundary="([^"]*)"', type).groups()[0]
+        # the boundaries are generated and may change
+        #bdReg = 'boundary="([^\n]*)"\n'
+        #expectedBd = re.search( bdReg, expected ).groups()[0]
+        #expected = expected.replace(expectedBd, '[boundary]')
+        #gotBd = re.search( bdReg, got ).groups()[0]
+        #got = got.replace(gotBd, '[boundary]')
+        got = got.replace(boundary, '[boundary]')
+        self.assertEquals(expected, got)
 
-#     def testMultipartDataForm(self):
-#         "Test the data returned by a multipart/form-data request."
-#         expected = 'multipart/form-data;\n boundary="64.242.113.150.1056.29208.1068160273.155.31644"\n--64.242.113.150.1056.29208.1068160273.155.31644\nContent-Type: text/plain\ncontent-disposition: form-data; name="last_visit"\n\nfoobar\n--64.242.113.150.1056.29208.1068160273.155.31644\nContent-Type: text/plain\ncontent-disposition: form-data; name="next_visit"\n\nbazqux\n--64.242.113.150.1056.29208.1068160273.155.31644--\n'
-#         request = self._makeOne( URL='http://example.com' )
-#         request.addField( 'last_visit:form=foobar' )
-#         request.addField( 'next_visit:form=bazqux' )
-#         got = request.getData()
-#         # the boundaries are generated and may change
-#         bdReg = 'boundary="([^\n]*)"\n'
-#         import re
-#         expectedBd = re.search( bdReg, expected ).groups()[0]
-#         expected = expected.replace(expectedBd, '[boundary]')
-#         gotBd = re.search( bdReg, got ).groups()[0]
-#         got = got.replace(gotBd, '[boundary]')
-#         self.assertEquals(expected, got)
-        
     # TODO:  test more of the API
 
 class ZEORequestTests( unittest.TestCase




More information about the Zope-CVS mailing list