[Zope-CVS] CVS: Packages/FunctionalTests/tests - test_Scenario.py:1.1 test_all.py:1.2
Tres Seaver
tseaver@zope.com
Tue, 19 Mar 2002 22:08:28 -0500
Update of /cvs-repository/Packages/FunctionalTests/tests
In directory cvs.zope.org:/tmp/cvs-serv29871/tests
Modified Files:
test_all.py
Added Files:
test_Scenario.py
Log Message:
- Add tests for Scenario.
- Add accessor / mutator for "load sequence", a field used to describe
how the scenario is to be executed when used in load testing.
XXX: Currently, kept only as the string read from the config file.
=== Added File Packages/FunctionalTests/tests/test_Scenario.py ===
import unittest
class DummyRequest:
_called_with = None
_fail = 0
def __init__( self, id ):
self._id = id
def getId( self ):
return self._id
def setFail( self ):
self._fail = 1
def __call__( self, result ):
self._called_with = result
if self._fail:
result.setAbend()
return self._id
class DummyResult:
_ok = 1
_setup_called = 0
_teardown_called = 0
def __init__( self ):
self._invocations = []
def __call__( self ):
return self._ok
def isAbend( self ):
return not self._ok
def getSetupCalled( self ):
return self._setup_called
def getTeardownCalled( self ):
return self._teardown_called
def setAbend( self ):
self._ok = 0
def setSetupCalled( self ):
self._setup_called = 1
def setTeardownCalled( self ):
self._teardown_called = 1
def addInvocation( self, inv, req ):
self._invocations.append( ( inv, req ) )
def listInvocations( self ):
return self._invocations
class ScenarioTests( unittest.TestCase ):
def _makeOne( self, *args, **kw ):
from FunctionalTests.Framework import Scenario
return Scenario( *args, **kw )
def test_empty( self ):
empty = self._makeOne()
self.failIf( empty.getUseCase() )
self.failIf( empty.getPostcondition() )
self.failIf( empty.listRequests() )
self.failIf( empty.getLoadSequence() )
def _makeRequests( self, *ids ):
result = []
for id in ids:
result.append( DummyRequest( id ) )
return tuple( result )
def test_addRequest( self ):
adder = self._makeOne()
REQUESTS = self._makeRequests( 'one', 'two', 'three' )
for request in REQUESTS:
adder.addRequest( request )
requests = adder.listRequests()
self.assertEquals( len( requests ), len( REQUESTS ) )
for r in REQUESTS:
self.failUnless( r in requests )
def test_call_normal( self ):
phb = self._makeOne()
REQUESTS = self._makeRequests( 'foo', 'bar', 'baz' )
for request in REQUESTS:
phb.addRequest( request )
result = DummyResult()
r = phb( result )
self.assertEquals( r, result )
self.failIf( result.isAbend() )
self.assertEquals( len( result.listInvocations() ), len( REQUESTS ) )
def test_call_abend( self ):
phb = self._makeOne()
REQUESTS = self._makeRequests( 'foo', 'bar', 'baz' )
REQUESTS[1].setFail()
for request in REQUESTS:
phb.addRequest( request )
result = DummyResult()
r = phb( result )
self.assertEquals( r, result )
self.failUnless( result.isAbend() )
self.assertEquals( len( result.listInvocations() ), 2 )
def test_suite():
return unittest.makeSuite( ScenarioTests )
if __name__ == '__main__':
unittest.main()
=== Packages/FunctionalTests/tests/test_all.py 1.1 => 1.2 ===
from FunctionalTests.tests import test_ConfigParserExt
from FunctionalTests.tests import test_Result
+from FunctionalTests.tests import test_Scenario
def test_suite():
suite = unittest.TestSuite()
suite.addTest( test_ConfigParserExt.test_suite() )
suite.addTest( test_Result.test_suite() )
+ suite.addTest( test_Scenario.test_suite() )
return suite
def run():