[Zope-CVS] CVS: Packages/FunctionalTests - Framework.py:1.17

Tres Seaver tseaver@zope.com
Fri, 12 Apr 2002 19:01:51 -0400


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

Modified Files:
	Framework.py 
Log Message:


  - Update Result to share cookies with parents (i.e., an entire suite
    shares a single session).

  - Add 'repeat' for both requests and sub-tests.
    
  The combination of 'repeat', SleepRequests, and shared cookies
  allows us to generate long-running, repetetive sequences of reqeusts,
  simulating reasonable "real-world" request patterns.


=== Packages/FunctionalTests/Framework.py 1.16 => 1.17 ===
         self._children = []
         self._cookies = []
+        self._parent = None
 
     #
     #   Queries
@@ -67,17 +68,37 @@
         result.update( self._defaults )
         return result
 
+    def getParent( self ):
+        """
+            Return our parent request, or None.
+        """
+        return self._parent
+
+    def setParent( self, parent ):
+        """
+            Setup our parent request.
+        """
+        self._parent = parent
+
     def getCookies( self ):
         """
             Return cookies we have accumulated during the request.
         """
-        return self._cookies
+        if self._cookies:
+            return self._cookies
+        #import pdb; pdb.set_trace()
+        if self._parent:
+            return self._parent.getCookies()
+        return []
 
     def setCookies( self, cookies ):
         """
             Store our cookies.
         """
         self._cookies = cookies
+        if self._parent:
+            #import pdb; pdb.set_trace()
+            self._parent.setCookies( cookies )
 
     def setStateValue( self, key, value ):
         """
@@ -174,6 +195,7 @@
                      , self.checkResponses()
                      , self.checkElapsedTimes()
                      )
+        child.setParent( self )
         self._children.append( child )
         return child
 
@@ -423,7 +445,7 @@
     options = cp.options( section )
 
     if 'sleep' in options:
-        r.setSleepTime( float( cp.get( section, 'sleep' ) ) )
+        r.setSleepTime( cp.getfloat( section, 'sleep' ) )
 
     return r
 
@@ -1092,9 +1114,10 @@
         """
         self._load_sequence = load_sequence
     
-    def addRequest( self, request ):
+    def addRequest( self, request, repeat_count=1 ):
 
-        return self._requests.append( request )
+        for i in range( repeat_count ):
+            self._requests.append( request )
 
     #
     #   TestBase interface
@@ -1144,10 +1167,11 @@
         """
         return tuple( self._children )
 
-    def addChild( self, child ):
+    def addChild( self, child, repeat_count=1 ):
         """
         """
-        self._children.append( child )
+        for i in range( repeat_count ):
+            self._children.append( child )
 
     def _execute( self, result ):
 
@@ -1212,10 +1236,16 @@
         test.setSetup( _buildRequest( cp, _SETUP_SECTION ) )
 
     for section in cp.listOtherSections():
+        options = cp.options( section )
+        if 'repeat' in options:
+            repeat_count = cp.getint( section, 'repeat' )
+        else:
+            repeat_count = 1
         if isScenario:
-            test.addRequest( _buildRequest( cp, section ) )
+            test.addRequest( _buildRequest( cp, section ), repeat_count )
         else:
-            test.addChild( buildTest( cp.get( section, 'file' ), defaults ) )
+            child = buildTest( cp.get( section, 'file' ), defaults )
+            test.addChild( child, repeat_count )
 
     if isScenario and _POSTCONDITION_SECTION in cp.listSpecialSections( 0 ):
         test.setPostcondition( _buildRequest( cp, _POSTCONDITION_SECTION ) )