[Zope-CVS] CVS: Packages/FunctionalTests/FunctionalTests - ScenarioGenerator.py:1.3 LoggingProxy.py:NONE TkLoggingProxy.py:NONE
Tres Seaver
tseaver@zope.com
Fri, 23 May 2003 17:21:45 -0400
Update of /cvs-repository/Packages/FunctionalTests/FunctionalTests
In directory cvs.zope.org:/tmp/cvs-serv11425/FunctionalTests
Modified Files:
ScenarioGenerator.py
Removed Files:
LoggingProxy.py TkLoggingProxy.py
Log Message:
- Clean up imports, get rid of 'string' module.
- Clean up exports.
- Guess at the 'portal_url', using the scheme and netloc of the first
URL (TODO: allow the user to pre-specify portal_url and site_path
on the command line).
- Strip the portal_url out of the request URLs (so we behave better
when dealing with output from a "real" logging proxy.
=== Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py 1.2 => 1.3 ===
--- Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py:1.2 Fri May 23 16:47:03 2003
+++ Packages/FunctionalTests/FunctionalTests/ScenarioGenerator.py Fri May 23 17:21:44 2003
@@ -1,47 +1,53 @@
-"""
- LoggingProxy request post-processor.
+""" Script: ScenarioGenerator
+
+Converts logged request data into a scenario script.
+
+$Id$
"""
-import sys, string, re
-import getopt, glob, rfc822, urllib
+import sys
+import re
+import getopt
+import glob
+import rfc822
+import urllib
+import urlparse
-SCENARIO_SKELETON = """\
+_SCENARIO_SKELETON = """\
[Scenario]
Title : Enter scenario title here
Use_case: Enter use case name here
"""
-REQUEST_SKELETON = """
+_REQUEST_SKELETON = """
[Request_%(REQUEST_NUM)03d]
HTTP_Verb: %(HTTP_VERB)s
HTTP_Version: %(HTTP_VERSION)s
URL: %%(portal_url)s/%%(site_path)s%(REQUEST_URI)s
"""
-AUTHENTICATION_SKELETON = """\
+_AUTHENTICATION_SKELETON = """\
Authentication: %%(userid)s:%%(password)s
"""
-HEADER_SKELETON = """\
-Header_%(HEADER_NUM)d: %(HEADER_NAME)=%(HEADER_VALUE)s
-"""
-
-COOKIE_SKELETON = """\
+_COOKIE_SKELETON = """\
Cookie_%(COOKIE_NUM)d: %(COOKIE_VALUE)s
"""
-FIELD_SKELETON = """\
+_FIELD_SKELETON = """\
Field_%(FIELD_NUM)d: %(FIELD_NAME)s=%(FIELD_VALUE)s
"""
-RESULT_SKELETON = """\
+_RESULT_SKELETON = """\
Expected_Result: %(RESULT_CODE)d
"""
-DEFAULT_SKELETON = """
+_DEFAULT_SKELETON = """
[DEFAULT]
userid: userid
password: password
+portal_url: %(portal_url)s
+site_path: %(site_path)s
"""
class ScenarioGenerator:
@@ -220,7 +226,7 @@
if self._capture_cookies:
count = parms.get( 'cookie_count', 0 ) + 1
parms[ 'cookie_count' ] = count
- self._print( COOKIE_SKELETON
+ self._print( _COOKIE_SKELETON
, COOKIE_NUM=count
, COOKIE_VALUE=value
)
@@ -232,7 +238,7 @@
'[DEFAULT]' section).
"""
parms[ 'saw_authentication' ] = 1
- self._print( AUTHENTICATION_SKELETON )
+ self._print( _AUTHENTICATION_SKELETON )
def _handleContentType( self, value, parms ):
"""
@@ -252,10 +258,10 @@
'application/x-www-form-urlencoded'.
"""
count = 0
- for key_val in string.split( data, '&' ):
- k, v = map( urllib.unquote_plus, string.split( key_val, '=' ) )
+ for key_val in data.split( '&' ):
+ k, v = map( urllib.unquote_plus, key_val.split( '=' ) )
count = count + 1
- self._print( FIELD_SKELETON
+ self._print( _FIELD_SKELETON
, FIELD_NUM=count
, FIELD_NAME=k
, FIELD_VALUE=v
@@ -281,8 +287,6 @@
self._exclude_regex = None
def _getExcludeRegex( self
- , join=string.join
- , compile=re.compile
):
"""
Return a regex which, if matched, indicates that we should
@@ -297,8 +301,8 @@
self._addExcludePattern( line )
if self._exclude_patterns:
- self._exclude_regex = compile( join( self._exclude_patterns
- , '|' ) )
+ self._exclude_regex = re.compile(
+ '|'.join( self._exclude_patterns ) )
return self._exclude_regex
def processFile( self
@@ -328,7 +332,7 @@
self._log( '** matches exclude regex, skipping', 1 )
return request_num
- request = string.rstrip( f.readline() )
+ request = f.readline().rstrip()
match = REQUEST_LINE.match( request )
if not match:
@@ -337,13 +341,28 @@
http_verb, uri, http_version = match.groups()
+ ( scheme
+ , netloc
+ , path
+ , params
+ , query
+ , fragment
+ ) = urlparse.urlparse( uri )
+
+ if scheme and parms.get( 'portal_url' ) is None:
+ parms[ 'portal_url' ] = urlparse.urlunparse(
+ ( scheme, netloc, '', '', '', '' ) )
+
+ site_relative_uri = urlparse.urlunparse(
+ ( '', '', path, params, query, fragment ) )
+
request_num = request_num + 1
- self._print( REQUEST_SKELETON
+ self._print( _REQUEST_SKELETON
, REQUEST_NUM=request_num
, HTTP_VERB=http_verb
, HTTP_VERSION=http_version
- , REQUEST_URI=uri
+ , REQUEST_URI=site_relative_uri
)
headers = rfc822.Message( f )
@@ -367,7 +386,7 @@
else:
handler( self, payload )
- self._print( RESULT_SKELETON
+ self._print( _RESULT_SKELETON
, RESULT_CODE=200 # TODO: Read from response?
)
@@ -380,7 +399,7 @@
create a scenario file with one section per request file,
dumping to specified output file.
"""
- self._print( SCENARIO_SKELETON )
+ self._print( _SCENARIO_SKELETON )
glob_pattern = '%s/%s_*.%s' % ( self._logfile_directory
, self._logfile_prefix
@@ -388,13 +407,17 @@
)
request_num = 0
- parms = { 'saw_authentication' : 0 }
-
- for filename in glob.glob( glob_pattern ):
+ parms = { 'saw_authentication' : 0
+ , 'portal_url' : None
+ , 'site_path' : None
+ }
+
+ filenames = glob.glob( glob_pattern )
+ filenames.sort()
+ for filename in filenames:
request_num = self.processFile( filename, request_num, parms )
- if parms[ 'saw_authentication' ]:
- self._print( DEFAULT_SKELETON )
+ self._print( _DEFAULT_SKELETON % parms )
if __name__ == '__main__':
=== Removed File Packages/FunctionalTests/FunctionalTests/LoggingProxy.py ===
=== Removed File Packages/FunctionalTests/FunctionalTests/TkLoggingProxy.py ===