responseanalyzer (version 0.8.8, 30 April 2002)
index
c:\work\puffin\responseanalyzer.py

Puffin uses a ResponseAnalyzer to analyze the HTTP response that the
web server returns upon execution of the test action (those that involve a call to the 
server, anyway). Depending on the results of that analysis, the ResponseAnalyzer then 
creates an AnalysisResult object and places into it the original ActionResponse object 
sent into it by the Test Action's execute method and a test results description string. 
This AnalysisResult object is then sent back to the Test Action which then sends it out 
to the TestPlanManager upon conclusion of the test action's execute() method. The 
TestPlanManager then sends this to the results processor. Puffin provides three core response
analyzers (described below) and you can create your own custom response analyzers. All
that is required is that all response analyzer classes extend ResponseAnalyzer (below). 
 
As mentioned above, Puffin comes with three core response analyzers:
EvalResponseAnalyzer -- This allows you to evaluate an expression and based on the 
    result will deem the test action a success or failure. You can include any 
    previously initialized test token in the expression as well. See below.
TimerResponseAnalyzer -- This allows you to base a test action's success or failure on
    whether or not the test action's execution took less than a specified period of time
    in seconds.
StatusResponseAnalyzer -- This allows you to base a test action's success or failure on
    whether or not the HTTP code returned by the server is one of those specified as params.
 
Here's all you need to do to create your own response analyzer:
1) Change the src attribute on the <defaultResponseAnalyzer> or <responseAnalyzer> for
either the default or test action specific, respectively, to 'custom'.
2) Then change the type attribute's value to be the name of your class.
3) Add your response analyzer class to the extensions.py file as described there.
4) Make sure you extend ResponseAnalyzer and that your method signatures are correct.
 
For example, let's say you want to use your own resonse analyzer which does XML Schema
validation against a ActionResponse. Furthermore, let's assume you want to use it as the
default. Here is the puffin config xml entry:
<responseAnalyzer src='custom' type='SchemaAnalyzer'>
    <param name='schemaFile'>mySchema.xsd</param>
</responseAnalyzer>
 
***TODO*** An XML schema validating WILL be part of a 1.0 release of Puffin.

 
Modules
            
extensions
puffinlogging
re
sys
tokenprocessing
 
Classes
            
AnalysisResult
ResponseAnalyzer
EvalResponseAnalyzer
StatusResponseAnalyzer
TimerResponseAnalyzer
 
class AnalysisResult
      A response analyzer communicates the results of its analysis using an AnalysisResult
object.
 
   Methods defined here:
__init__(self, actionResponse, analyzerName, analysisMsg, succeeded=0)
Constructor for the AnalysisResult class.
 
Keyword Arguments:
actionResponse -- The action response object resulting from the test action's execution.
analysisMsg -- The message generated by the response analyzer to describe the analysis.
succeeded -- Whether or not the test action 'succeeded,' whatever that means for the
    test action.
getActionResponse(self)
Return the action response.
getAnalysisMsg(self)
Return the analysis message.
getAnalyzerName(self)
Return the name of the analyzer that generated this analysis result.
getSucceeded(self)
Return whether or not the test for this analysis result succeeded or not.

Data and non-method functions defined here:
__doc__ = 'A response analyzer communicates the results of its analysis using an AnalysisResult\n object.'
__module__ = 'responseanalyzer'
 
class EvalResponseAnalyzer(ResponseAnalyzer)
      This simple response analyzer will evaluate an expression and based on the 
result will deem the test action a success or failure. You can include any 
previously initialized test token in the expression as well.
 
Keyword Arguments:
actionResponse -- The response information from the execution of the test action.
tokenDictionary -- The current token dictionary for this test plan's execution.
 
Parameters:
runOnFirstExecution -- Whether or not to execute this response analyzer's
    analysis on a test action's first execution.
evalExpression -- The evaluation expression. This must evaluate (using Python's
    eval() method to TRUE or FALSE. You can use any elements in your expression
    that you choose (numbers, strings, whatever).
 
Examples:
1.  <param name='evalExpression'><![CDATA[$$$TOKEN1$$$ > $$$TOKEN2$$$]]></param>
2.  <param name='evalExpression'><![CDATA[$$$TOKEN1$$$ == 'KEYTON']]></param>
3.  <param name='evalExpression'><![CDATA[($$$TOKEN1$$$ + 1) / 2 > 0.34]]></param>
 
Common Use:
One common use for this response analyzer is to check to see if a token exists.
To accomplish this, you would do something like the following for the config of your
test action:
 
     <testAction name='login'>
        <path>/start.cgi</path>
         <output name="SESSION_ID" processor="extractRegex">
            <param name="expr" eval="0"><![CDATA[href="itemList\.cgi\?session_id=(\d*)&]]></param>
         </output>
         <responseAnalyzerList>
            <responseAnalyzer type='EvalResponseAnalyzer'>
                <param name='evalExpression'><![CDATA[$$$SESSION_ID$$$]]></param>
            </responseAnalyzer>
         </responseAnalyzerList>
         <output name="ITEM_NUMBER" processor='extractRandomNumber'>
            <param name='max'>4</param>
         </output>
     </testAction>
 
The above will attempt to extract the session id and then check to see if it is there.
 
You could have determined whether your session id was '12345' like this:
     <testAction name='login'>
        <path>/start.cgi</path>
         <output name="SESSION_ID" processor="extractRegex">
            <param name="expr" eval="0"><![CDATA[href="itemList\.cgi\?session_id=(\d*)&]]></param>
         </output>
         <responseAnalyzerList>
            <responseAnalyzer type='EvalResponseAnalyzer'>
                <param name='evalExpression'><![CDATA[$$$SESSION_ID$$$=='12345']]></param>
            </responseAnalyzer>
         </responseAnalyzerList>
         <output name="ITEM_NUMBER" processor='extractRandomNumber'>
            <param name='max'>4</param>
         </output>
     </testAction>
 
   Methods defined here:
__init__(self, paramDictionary, runOnFirstExecution)
Constructor for the ExpressionResponseAnalyzer base class.
 
Keyword Arguments:
paramDictionary -- A ParamDictionary containing entries for every param for this 
    response analyzer. See above for more information.
runOnFirstExecution -- Whether or not to execute this response analyzer's analysis
    on the first execution of a test action.
analyze(self, actionResponse, tokenDictionary)
Analyze the action response. Search for the existence of any of the values provided
in srchText parameters. If no srchText parameter is found, look for the word "exception."
 
Keyword Arguments:
actionResponse -- The response information from the execution of the test action.
    NOTE: The action response is actually not used.
tokenDictionary -- The current token dictionary for this test plan's execution.

Data and non-method functions defined here:
__doc__ = 'This simple response analyzer will evaluate an ... \n \n '
__module__ = 'responseanalyzer'
 
class ResponseAnalyzer
      The base class for the response analyzer that analyzes the response document
sent back from a server upon execution of a test action.
 
   Methods defined here:
__init__(self, paramDictionary, runOnFirstExecution)
Constructor for the ResponseAnalyzer base class.
 
Keyword Arguments:
paramDictionary -- A ParamDictionary containing entries for every param 
    for this response analyzer.
runOnFirstExecution -- Whether or not to execute this response analyzer's analysis
    on the first execution of a test action.
analyze(self, actionResponse, tokenDictionary)
Analyze the response sent back from a server upon execution of a test action.
 
Keyword Arguments:
actionResponse -- The response information from the execution of the test action.
tokenDictionary -- The current token dictionary for this test plan's execution.

Data and non-method functions defined here:
__doc__ = 'The base class for the response analyzer that a...k from a server upon execution of a test action.'
__module__ = 'responseanalyzer'
 
class StatusResponseAnalyzer(ResponseAnalyzer)
      This response analyzer checks to make sure that one (or more) specific HTTP status
code(s) is(are) returned (usually 200).
 
Example of use in Puffin config file:
   <responseAnalyzer src='puffin' type='StatusResponseAnalyzer'>
      <param name='httpStatus'>200</param>
      <param name='httpStatus'>302</param>
   </responseAnalyzer>
 
   Methods defined here:
__init__(self, paramDictionary, runOnFirstExecution)
Constructor for the TimerResponseAnalyzer base class.
 
Keyword Arguments:
paramDictionary -- A ParamDictionary containing entries for every param for this 
    response analyzer. The following parameters are used:
    httpStatus -- The HTTP status required for the test action succeeded (can 
        be multiple possibilities -- any of these will allow a test action to succeed).
runOnFirstExecution -- Whether or not to execute this response analyzer's analysis
    on the first execution of a test action.
analyze(self, actionResponse, tokenDictionary)
Analyze the action response for HTTP response status. Check against all
valid values (from the httpStatusRequired param value(s)).
 
Keyword Arguments:
actionResponse -- The response information from the execution of the test action.
tokenDictionary -- The current token dictionary for this test plan's execution.

Data and non-method functions defined here:
__doc__ = "This response analyzer checks to make sure that...s'>302\n \n "
__module__ = 'responseanalyzer'
 
class TimerResponseAnalyzer(ResponseAnalyzer)
      This response analyzer checks to see if the test action's execution takes longer
than a specified length of time (in seconds).
 
Example of use in Puffin config file:
   <responseAnalyzer src='puffin' type='TimerResponseAnalyzer'>
      <param name='timeLimitSecs'>20</param>
   </responseAnalyzer>
 
   Methods defined here:
__init__(self, paramDictionary, runOnFirstExecution)
Constructor for the TimerResponseAnalyzer base class.
 
Keyword Arguments:
paramDictionary -- A ParamDictionary containing entries for every param for this 
    response analyzer. The following parameters are used:
    timeLimitSecs -- The time limit for the test action in seconds. If the test 
        action's execution takes longer than this time limit, then the test action
        is a failure.
runOnFirstExecution -- Whether or not to execute this response analyzer's analysis
    on the first execution of a test action.
analyze(self, actionResponse, tokenDictionary)
Analyze the action response's elapsed time. If this test action's execution
takes longer than the timeLimitSec value, then the test action fails.
 
Keyword Arguments:
actionResponse -- The response information from the execution of the test action.
tokenDictionary -- The current token dictionary for this test plan's execution.

Data and non-method functions defined here:
__doc__ = "This response analyzer checks to see if the tes...cs'>20\n \n "
__module__ = 'responseanalyzer'
 
Functions
            
getResponseAnalyzerList(responseAnalyzerNodeList)
Generate a list of response analyzers from a list of nodes.
 
Keyword Arguments:
responseAnalyzerNodeList -- The list of XML nodes for a series of response
    analyzers.
 
Data
             __author__ = 'Keyton Weissinger '
__date__ = '30 April 2002'
__file__ = '.\\responseanalyzer.pyc'
__name__ = 'responseanalyzer'
__status__ = 'beta'
__version__ = '0.8.8'
 
Author
             Keyton Weissinger <keyton@weissinger.org>