[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests/tests -
test_Request.py:1.2
Tres Seaver
tseaver at zope.com
Sat Apr 2 18:22:23 EST 2005
Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests/tests
In directory cvs.zope.org:/tmp/cvs-serv26739/FunctionalTests/tests
Modified Files:
test_Request.py
Log Message:
- Lay in last set of updates (not yet finished).
=== Packages/FunctionalTests/FunctionalTests/tests/test_Request.py 1.1 => 1.2 ===
--- Packages/FunctionalTests/FunctionalTests/tests/test_Request.py:1.1 Sat May 31 15:10:07 2003
+++ Packages/FunctionalTests/FunctionalTests/tests/test_Request.py Sat Apr 2 18:21:53 2005
@@ -150,7 +150,9 @@
seconds = timing.milli() / 1000.0
delta = abs( seconds - SLEEP_TIME )
- self.failUnless( delta < 0.01 )
+ self.failUnless( delta < 0.01,
+ "expected to sleep for %f seconds, slept for %f" %
+ ( seconds, SLEEP_TIME ))
class HTTPRequestTests( unittest.TestCase
@@ -169,7 +171,121 @@
return self._getTargetClass()( name=name, URL=URL, *args, **kw )
- # TODO: test actual API
+ def test_result( self ):
+
+ request = self._makeOne()
+ request.setExpectedResult( 'foo' )
+ self.assertEquals( request.getExpectedResult(), 'foo' )
+
+ def testHostPort(self):
+ """
+ Test that setting the host with or without the port in the URI
+ gives the right host and port.
+ """
+ request = self._makeOne( URL='http://example.com' )
+ self.assertEquals( request.getHost(), 'example.com' )
+ self.assertEquals( request.getPort(), None )
+ request = self._makeOne( URL='http://example.com:80' )
+ self.assertEquals( request.getHost(), 'example.com' )
+ self.assertEquals( request.getPort(), 80 )
+
+ def testAddGetField(self):
+ "Test that adding, getting a field does the right thing."
+ expected = [ 'last_visit'
+ , 'date'
+ , '2001/11/12 17:21:03.25675 US/Eastern'
+ ]
+ request = self._makeOne( URL='http://example.com' )
+ request.addField(
+ 'last_visit:date=2001/11/12 17:21:03.25675 US/Eastern')
+ got = request.getFields()
+ self.assertEquals( len( got ), 1 )
+ got = got[0]
+ self.assertEquals( len( expected ), len( got ) )
+ got = list( got )
+ while len( expected ):
+ self.assertEquals( got.pop(), expected.pop() )
+
+ # XXX I'm writing this based on what the methods do now, may be wrong
+ def testContentType(self):
+ "Test the base content type."
+ request = self._makeOne( URL='http://example.com' )
+ self.assertEquals( request.getContentType(),
+ 'application/x-www-form-urlencoded' )
+
+ def testURIEncodedContentType(self):
+ "Test that adding a URI-encoded field sets the right content type."
+ request = self._makeOne( URL='http://example.com' )
+ request.addField(
+ 'last_visit:date=2001/11/12 17:21:03.25675 US/Eastern' )
+ self.assertEquals( request.getContentType(),
+ 'application/x-www-form-urlencoded' )
+
+ def testURIEncodedData(self):
+ "Test that adding a URI-encoded field sets the right data."
+ request = self._makeOne( URL='http://example.com' )
+ request.addField(
+ 'last_visit:date=2001/11/12 17:21:03.25675 US/Eastern' )
+ data = 'last_visit:date=2001%2F11%2F12+17%3A21%3A03.25675+US%2FEastern'
+ self.assertEquals( request.getData(), data )
+
+ def testMethod(self):
+ "Test the base method."
+ request = self._makeOne( URL='http://example.com' )
+ self.assertEquals( request.getMethod(), 'GET' )
+
+ def testURIEncodedMethod(self):
+ "Test that adding a URI-encoded sets the right method."
+ request = self._makeOne( URL='http://example.com' )
+ request.addField(
+ '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=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=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)
+
+ # TODO: test more of the API
class ZEORequestTests( unittest.TestCase
, _RequestBaseTests
@@ -192,6 +308,12 @@
, *args
, **kw
)
+
+ def test_result( self ):
+
+ request = self._makeOne()
+ request.setExpectedResult( 'foo' )
+ self.assertEquals( request.getExpectedResult(), 'foo' )
# TODO: test actual API
More information about the Zope-CVS
mailing list