[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests - Request.py:1.5 interfaces.py:1.2

Tres Seaver tseaver@zope.com
Sat, 31 May 2003 15:10:38 -0400


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

Modified Files:
	Request.py interfaces.py 
Log Message:


  - FunctionalTests/Request.py:

    o Add interface assertions, moving docstrings to interfaces.

    o _buildSleepRequest:  pass sleep_time to ctor.

  - FunctionalTests/interfaces.py:

    o Flesh out request interfaces.

  - FunctionalTests/tests/test_all:

    o Add request tests.

  - FunctionalTests/tests/conformance.py:

    o Add base classes for testing interface conformance.

  - FunctionalTests/tests/plugin_module.py:

    o Dummy module for testing plugin functions.

  - FunctionalTests/tests/test_Request.py:

    o Test request implementations.

    o XXX:  HTTPRequest and ZEORequest tests still need fleshing out.


=== Packages/FunctionalTests/FunctionalTests/Request.py 1.4 => 1.5 ===
--- Packages/FunctionalTests/FunctionalTests/Request.py:1.4	Fri May 30 21:17:44 2003
+++ Packages/FunctionalTests/FunctionalTests/Request.py	Sat May 31 15:10:07 2003
@@ -9,6 +9,12 @@
 import urlparse
 import base64
 
+from interfaces import IPluginFunction
+from interfaces import IRequest
+from interfaces import ISleepRequest
+from interfaces import IHTTPRequest
+from interfaces import IZEORequest
+
 from Invocation import HTTPRequestInvocation
 from Invocation import ZEORequestInvocation
 
@@ -23,38 +29,40 @@
     
     o This file must be available at runtime in the test environment.
     """
+    __implements__ = ( IPluginFunction, )
+
     def __init__( self, filename, function ):
 
         self._filename = filename
         self._function = function
 
     #
-    #   Accessors
+    #   IPluginFunction implementation
     #
     def getFileName( self ):
 
-        """ Return the name of the file containing our function.
+        """ See IPluginFunction.
         """
         return self._filename
 
     def getFunctionName( self ):
 
-        """ Return the name of our function.
+        """ See IPluginFunction.
         """
         return self._function
 
     def getFunction( self ):
 
-        """ Return a function object.
+        """ See IPluginFunction.
         """
         g = {} # faux globals
         execfile( self.getFileName(), g )
         return g[ self.getFunctionName() ]
       
 
-class _RequestBase: # XXX scarecrow me?
+class _RequestBase:
 
-    """ Common base class for requests.
+    """ Common base class for IRequest implementations.
     """
     def __init__( self, name ):
 
@@ -68,48 +76,43 @@
     #
     def getName( self ):
 
-        """ Return the name of this request within the scenario.
+        """ See IRequest.
         """
         return self._name
 
     def getExpectedResult( self ):
 
-        """ Return the expected result (return value, HTTP request code,
-            etc.)
+        """ See IRequest.
         """
         return self._expected_result
 
     def getExpectedTime( self ):
 
-        """ Return the maximum expected time to complete the request.
+        """ See IRequest.
         """
         return self._expected_time
 
     def getOption( self, key, default=None ):
 
-        """ Return the value for the given option.
-
-        o Return 'default' if no such option exists.
+        """ See IRequest.
         """
         return self._options.get( key, default )
 
     def listOptions( self ):
 
-        """ Return a list of the options we know about.
+        """ See IRequest.
         """
         return self._options.keys()
 
     def __call__( self, result ):
 
-        """ Invoke the request, storing results in 'result'.
+        """ See IRequest.
         """
         raise NotImplementedError
 
     def _setOptions( self, cp, section, clear=1 ):
 
-        """ Store all options associated with the request.
-
-        o If 'clear', then wipe out previously stored options.
+        """ See IRequest.
         """
         if clear:
             self._options.clear()
@@ -119,27 +122,17 @@
 
 class SleepRequest( _RequestBase ):
 
-    """ Define a "spacer" request, used to inject time between other requests.
-
-    o Would primarily be used in load testing, when simulating "actual"
-      user interactions.
+    """ Implement ISleepRequest.
     """
+    __implements__ = ( ISleepRequest, )
+
+    def __init__( self, name, sleep_time=1 ):
+        _RequestBase.__init__( self, name )
+        self._sleep_time = sleep_time
+
     #
     #   Accessors
     #
-    def getName( self ):
-
-        """ Return the name of this request within the scenario.
-        """
-        return self._name
-
-    def getExpectedResult( self ):
-
-        """ Return the expected result (return value, HTTP request code,
-            etc.)
-        """
-        return self._expected_result
-
     def getExpectedTime( self ):
 
         """ Return the maximum expected time to complete the request.
@@ -148,13 +141,13 @@
 
     def getSleepTime( self ):
 
-        """ Return the time to sleep, in seconds.
+        """ See ISleepRequest.
         """
         return self._sleep_time
 
     def setSleepTime( self, sleep_time ):
 
-        """ Set the sleep time, in seconds.
+        """ See ISleepRequest.
         """
         self._sleep_time = sleep_time
 
@@ -173,6 +166,7 @@
     o Includes both the parameters for invoking the system and the
       expected results.
     """
+    __implements__ = ( IHTTPRequest, )
 
     def __init__( self, name, URL ):
 
@@ -211,13 +205,13 @@
     #
     def getMethod( self ):
 
-        """ Return the name of the HTTP method to use for this request.
+        """ See IHTTPRequest.
         """
         return self._fields and 'POST' or 'GET'
 
     def getURI( self ):
 
-        """ Return the site-relative portion of the URL.
+        """ See IHTTPRequest.
         """
         url = self._path
         if self._params:
@@ -228,96 +222,87 @@
             url = url + '#' + self._fragment
         return url
 
-
     def getURLScheme( self ):
 
-        """ Return the scheme (e.g., 'http', 'ftp') for the request.
+        """ See IHTTPRequest.
         """
         return self._scheme
 
     def getHost( self ):
 
-        """ Return the hostname for the request.
+        """ See IHTTPRequest.
         """
         return self._host
 
     def getPort( self ):
 
-        """ Return the port number for the request.
+        """ See IHTTPRequest.
         """
         return self._port
 
     def getPath( self ):
 
-        """ Return the path for the request.
+        """ See IHTTPRequest.
         """
         return self._path
 
     def getParameters( self ):
 
-        """ Return the parameters (e.g., ';foo') for the request.
+        """ See IHTTPRequest.
         """
         return self._params
 
     def getQueryString( self ):
 
-        """ Return the query string for the request.
+        """ See IHTTPRequest.
         """
         return self._query
 
     def getFragment( self ):
 
-        """ Return the fragment (e.g., '#section') for the request.
+        """ See IHTTPRequest.
         """
         return self._fragment
 
     def getAuthenticationToken( self ):
 
-        """ Return the authentication token to be used, if any, as
-            a 'userid:password' string.
+        """ See IHTTPRequest.
         """
         return self._authentication_token
 
     def getHeaders( self ):
 
-        """ Return a sequence of '( key, value )' tuples for additional
-            HTTP headers to be passed with the request.
+        """ See IHTTPRequest.
         """
         return tuple( self._headers )
 
     def getCookies( self ):
 
-        """ Return a sequence of '( key, value )' tuples for the cookies
-            to be passed with the request.
+        """ See IHTTPRequest.
         """
         return tuple( self._cookies )
 
     def getFields( self ):
 
-        """ Return a sequence of '( name, type, value )' tuples
-            representing the form variables to be included in the
-            request.
-
-            Fields of type 'file' will *not* be loaded;  the value
-            will be the filename.
+        """ See IHTTPRequest.
         """
         return tuple( self._fields )
 
     def getExpectedRedirect( self ):
 
-        """ Return the URL expected for a redirect.
+        """ See IHTTPRequest.
         """
         return self._expected_redirect
 
     def getExpectedCookies( self ):
 
-        """ Return the cookie IDs expected for this request
+        """ See IHTTPRequest.
         """
         return self._expected_cookies
 
     def matchExpectedCookies( self, cookies ):
 
-        """ Do 'cookies' match what we expect?
+        """ See IHTTPRequest.
         """
         for cookie in cookies:
             for key in cookie.keys():
@@ -327,20 +312,19 @@
 
     def retainCookies( self ):
 
-        """ Should invocations of this request retain cookies?
+        """ See IHTTPRequest.
         """
         return self._expected_cookies is not None
     
     def getContentType( self ):
 
-        """ Return the HTTP 'Content-type' to use for this request.
+        """ See IHTTPRequest.
         """
         return self._has_file_field and _MULTIPART or _URLENCODED
 
     def getData( self ):
 
-        """ Return the payload for this request, formatted as specified
-            in getContentType().
+        """ See IHTTPRequest.
         """
         if self._has_file_field:
 
@@ -362,19 +346,19 @@
     #
     def addHeader( self, header_desc ):
 
-        """ Construct a header tuple and add it to our list.
+        """ See IHTTPRequest.
         """
         self._headers.append( _buildHeader( header_desc ) )
 
     def addCookie( self, cookie_desc ):
 
-        """ Construct a cookie tuple and add it to our list.
+        """ See IHTTPRequest.
         """
         self._cookies.append( _buildCookie( cookie_desc ) )
 
     def addField( self, field_desc ):
 
-        """ Construct a field tuple and add it to our list.
+        """ See IHTTPRequest.
         """
         field = _buildField( field_desc )
         if field[2] == 'file':
@@ -383,19 +367,19 @@
 
     def setAuthenticationToken( self, authentication_token ):
 
-        """ Assign the authentication token.
+        """ See IHTTPRequest.
         """
         self._authentication_token = authentication_token
 
     def setExpectedResult( self, result_code ):
 
-        """ Override the default expected HTTP response code.
+        """ See IHTTPRequest.
         """
         self._expected_result = result_code
 
     def setExpectedRedirect( self, redirect_url ):
 
-        """ Override the default expected HTTP redirect path.
+        """ See IHTTPRequest.
         """
         self._expected_redirect = redirect_url
         if self._expected_result == 200:
@@ -403,13 +387,13 @@
 
     def setExpectedTime( self, response_time ):
 
-        """ Override the default expected response time, in seconds.
+        """ See IHTTPRequest.
         """
         self._expected_time = response_time
 
     def setExpectedCookies( self, cookies ):
 
-        """ Override the default expected response time, in seconds.
+        """ See IHTTPRequest.
         """
         if type( cookies ) == type( '' ):
             cookies = cookies.split( ';' )
@@ -474,6 +458,8 @@
     
     o Executed via ZEO, rather than via HTTP.
     """
+    __implements__ = ( IZEORequest, )
+
     def __init__( self, name, filename, function ):
 
         _RequestBase.__init__( self, name )
@@ -569,12 +555,14 @@
 
     """ Construct a SleepRequest, using the values in 'cp' and 'section'.
     """
-    r = SleepRequest( section )
-
     options = cp.options( section )
 
     if 'sleep' in options:
-        r.setSleepTime( cp.getfloat( section, 'sleep' ) )
+        sleep_time = cp.getfloat( section, 'sleep' )
+    else:
+        sleep_time = 1.0
+
+    r = SleepRequest( section, sleep_time )
 
     r._setOptions( cp, section )
 


=== Packages/FunctionalTests/FunctionalTests/interfaces.py 1.1 => 1.2 ===
--- Packages/FunctionalTests/FunctionalTests/interfaces.py:1.1	Tue May 20 21:05:05 2003
+++ Packages/FunctionalTests/FunctionalTests/interfaces.py	Sat May 31 15:10:07 2003
@@ -8,11 +8,254 @@
 except ImportError:
     class Interface: pass
 
+
+class IPluginFunction( Interface ):
+
+    """ Represent a function loadable from a separate file.
+    
+    o This file must be available at runtime in the test environment.
+    """
+
+    def getFileName():
+
+        """ Return the name of the file containing our function.
+        """
+
+    def getFunctionName():
+
+        """ Return the name of our function.
+        """
+
+    def getFunction():
+
+        """ Return a function object.
+        """
+
+
 class IRequest( Interface ):
 
     """ Define an abstract request, apart from any invocation.
     """
 
+    def getName():
+
+        """ Return the name of this request within the scenario.
+        """
+
+    def getExpectedResult():
+
+        """ Return the expected result (return value, HTTP request code, etc.)
+        """
+
+    def getExpectedTime():
+
+        """ Return the maximum expected time to complete the request.
+        """
+
+    def getOption( key, default=None ):
+
+        """ Return the value for the given option.
+
+        o Return 'default' if no such option exists.
+        """
+
+    def listOptions():
+
+        """ Return a list of the options we know about.
+        """
+
+    def __call__( result ):
+
+        """ Invoke the request, storing results in 'result'.
+        """
+
+    def _setOptions( cp, section, clear=1 ):
+
+        """ Store all options associated with the request.
+
+        o If 'clear', then wipe out previously stored options.
+
+        o Intended only for use by builder functions.
+        """
+
+    def __call__( result ):
+
+        """ Invoke the request;  store the results in 'result'.
+        """
+
+class ISleepRequest( IRequest ):
+
+    """ Define a "spacer" request, used to inject time between other requests.
+
+    o Primarily for use in load testing, when simulating "actual"
+      user interactions.
+    """
+
+    def getSleepTime():
+
+        """ Return the time to sleep, in seconds.
+        """
+
+    def setSleepTime( sleep_time ):
+
+        """ Set the sleep time, in seconds.
+        """
+
+
+class IHTTPRequest( IRequest ):
+
+    """ Define a single request/reply interaction with the system via HTTP.
+
+    o Includes both the parameters for invoking the system and the
+      expected results.
+    """
+
+    def getMethod():
+
+        """ Return the name of the HTTP method to use for this request.
+        """
+
+    def getURI():
+
+        """ Return the site-relative portion of the URL.
+        """
+
+    def getURLScheme():
+
+        """ Return the scheme (e.g., 'http', 'ftp') for the request.
+        """
+
+    def getHost():
+
+        """ Return the hostname for the request.
+        """
+
+    def getPort():
+
+        """ Return the port number for the request.
+        """
+
+    def getPath():
+
+        """ Return the path for the request.
+        """
+
+    def getParameters():
+
+        """ Return the parameters (e.g., ';foo') for the request.
+        """
+
+    def getQueryString():
+
+        """ Return the query string for the request.
+        """
+
+    def getFragment():
+
+        """ Return the fragment (e.g., '#section') for the request.
+        """
+
+    def getAuthenticationToken():
+
+        """ Return the authentication token to be used, if any, as
+            a 'userid:password' string.
+        """
+
+    def getHeaders():
+
+        """ Return a sequence of '( key, value )' tuples for additional
+            HTTP headers to be passed with the request.
+        """
+
+    def getCookies():
+
+        """ Return a sequence of '( key, value )' tuples for the cookies
+            to be passed with the request.
+        """
+
+    def getFields():
+
+        """ Return a sequence of '( name, type, value )' tuples
+            representing the form variables to be included in the
+            representing the form variables to be included in the
+            request.
+
+            Fields of type 'file' will *not* be loaded;  the value
+            will be the filename.
+        """
+
+    def getExpectedRedirect():
+
+        """ Return the URL expected for a redirect.
+        """
+
+    def getExpectedCookies():
+
+        """ Return the cookie IDs expected for this request
+        """
+
+    def matchExpectedCookies( cookies ):
+
+        """ Do 'cookies' match what we expect?
+        """
+
+    def retainCookies():
+
+        """ Should invocations of this request retain cookies?
+        """
+
+    def getContentType():
+
+        """ Return the HTTP 'Content-type' to use for this request.
+        """
+
+    def getData():
+
+        """ Return the payload for this request, formatted as specified
+            in getContentType().
+        """
+
+    def addHeader( header_desc ):
+
+        """ Construct a header tuple and add it to our list.
+        """
+
+    def addCookie( cookie_desc ):
+
+        """ Construct a cookie tuple and add it to our list.
+        """
+
+    def addField( field_desc ):
+
+        """ Construct a field tuple and add it to our list.
+        """
+
+    def setAuthenticationToken( authentication_token ):
+
+        """ Assign the authentication token.
+        """
+
+    def setExpectedResult( result_code ):
+
+        """ Override the default expected HTTP response code.
+        """
+
+    def setExpectedRedirect( redirect_url ):
+
+        """ Override the default expected HTTP redirect path.
+        """
+
+    def setExpectedTime( response_time ):
+
+        """ Override the default expected response time, in seconds.
+        """
+
+    def setExpectedCookies( cookies ):
+
+        """ Override the default expected response time, in seconds.
+        """
+
+
 class IResult( Interface ):
 
     """ Represent the result of invoking one or more related requests.
@@ -22,60 +265,57 @@
     o Implements GoF Composite pattern.
     """
 
-    #
-    #   Accessors
-    #
-    def getTest( self ):
+    def getTest():
 
         """ Return our test object.
         """
 
-    def getApplication( self ):
+    def getApplication():
 
         """ Return the root object of Zope.
         """
 
-    def getDefaults( self ):
+    def getDefaults():
 
         """ Return our test object.
         """
 
-    def getParent( self ):
+    def getParent():
 
         """ Return our parent request, or None.
         """
 
-    def getCookies( self ):
+    def getCookies():
 
         """ Return cookies we have accumulated during the request.
         """
 
-    def timeRequests( self ):
+    def timeRequests():
 
         """ Should we capture elapsed times?
         """
 
-    def checkResponses( self ):
+    def checkResponses():
 
         """ Should we validate response values?
         """
 
-    def checkRedirects( self ):
+    def checkRedirects():
 
         """ Should we validate redirect locations?
         """
 
-    def checkContent( self ):
+    def checkContent():
 
         """ Should we validate content?
         """
 
-    def checkElapsedTimes( self ):
+    def checkElapsedTimes():
 
         """ Should we validate elapsed times?
         """
 
-    def listInvocations( self, roll_up=1 ):
+    def listInvocations( roll_up=1 ):
 
         """ Return the list of invocations we manage.
 
@@ -83,22 +323,22 @@
           those we manage directly.
         """
 
-    def listErrors( self, fatal_only=0, roll_up=1 ):
+    def listErrors( fatal_only=0, roll_up=1 ):
 
         """ Return a list of fatal errors.
         """
 
-    def listChildren( self ):
+    def listChildren():
 
         """ Return our sub-results.
         """
 
-    def listDumpedResults( self ):
+    def listDumpedResults():
 
         """ Return a list of verbose invocation dumps.
         """
 
-    def __call__( self ):
+    def __call__():
 
         """ Test the validity of the request.
         
@@ -109,42 +349,42 @@
     #
     #   Mutators
     #
-    def setParent( self, parent ):
+    def setParent( parent ):
 
         """ Setup our parent request.
         """
 
-    def setCookies( self, cookies ):
+    def setCookies( cookies ):
 
         """ Store our cookies.
         """
 
-    def setStateValue( self, key, value ):
+    def setStateValue( key, value ):
 
         """ Remember a value (e.g., across invocations)
         """
 
-    def getStateValue( self, key ):
+    def getStateValue( key ):
 
         """ Recall a value stored using 'setStateValue'.
         """
 
-    def addInvocation( self, invocation, request ):
+    def addInvocation( invocation, request ):
 
         """ Remember a request invocation other than setup / postcondition.
         """
 
-    def newChild( self, test ):
+    def newChild( test ):
 
         """ Create, remember, and return a sub-result.
         """
 
-    def logError( self, msg ):
+    def logError( msg ):
 
         """ Record a fatal error.
         """
 
-    def logFatalError( self, msg ):
+    def logFatalError( msg ):
 
         """ Record a fatal error.
         """
@@ -155,32 +395,39 @@
     """ Record particular request invocations.
     """
 
-    def getRequest( self ):
+    def getRequest():
 
         """ Return the request for which we were invoked.
         """
 
-    def beginRequest( self ):
+    def beginRequest():
 
         """ Record the start of the request invocation.
         """
 
-    def endRequest( self ):
+    def endRequest():
 
         """ Record the end of the request invocation.
         """
 
-    def dump( self ):
+    def dump():
 
         """ Return a string describing the invocation.
         """
 
-    def getResult( self ):
+    def getResult():
 
         """ Return a value representing the result of the invocation.
         """
 
-    def getElapsedTime( self ):
+    def getElapsedTime():
 
         """ Return the time taken by this invocation.
         """
+
+class IZEORequest( IRequest ):
+
+    """ Represent a scaffolding remote function call
+    
+    o Executed via ZEO, rather than via HTTP.
+    """