[Zope3-checkins] SVN: Zope3/trunk/src/zope/app/tests/ Created a
script for converting http sesssions recorded by tcpwatch
Jim Fulton
jim at zope.com
Sun Aug 22 15:12:15 EDT 2004
Log message for revision 27220:
Created a script for converting http sesssions recorded by tcpwatch
into functional doctests.
Changed:
A Zope3/trunk/src/zope/app/tests/dochttp.py
A Zope3/trunk/src/zope/app/tests/recorded/
A Zope3/trunk/src/zope/app/tests/recorded/test0001.request
A Zope3/trunk/src/zope/app/tests/recorded/test0001.response
A Zope3/trunk/src/zope/app/tests/recorded/test0002.request
A Zope3/trunk/src/zope/app/tests/recorded/test0002.response
A Zope3/trunk/src/zope/app/tests/test_dochttp.py
-=-
Added: Zope3/trunk/src/zope/app/tests/dochttp.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/dochttp.py 2004-08-22 19:05:53 UTC (rev 27219)
+++ Zope3/trunk/src/zope/app/tests/dochttp.py 2004-08-22 19:12:14 UTC (rev 27220)
@@ -0,0 +1,198 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Convert an http tcpwatch session to a doctest
+
+$Id$
+"""
+
+import optparse
+import os
+import re
+import rfc822
+import sys
+
+usage = """usage: \%prog <options> directory
+
+Convert an http tcpwatch recorded sesssion to a doctest file, which is
+written to standard output.
+
+"""
+
+parser = optparse.OptionParser(usage)
+parser.add_option("-p", "--prefix", default="watch",
+ help="Prefix for recorded tcpwatch session files")
+parser.add_option("-U", "--skip-url", action="append",
+ help="Regular expression for URLs to skip")
+parser.add_option("-E", "--skip-extension", action="append",
+ help="URL file-extension to skip")
+parser.add_option("-e", "--extension", action="append",
+ help="URL file-extension to include")
+parser.add_option("-I", "--skip-request-header", action="append",
+ help="Request header to skip")
+parser.add_option("-O", "--skip-response-header", action="append",
+ help="Response header to skip")
+
+default_options = [
+ '-e', 'html',
+
+ '-I', 'Accept-Charset', '-I', 'Accept-Encoding', '-I', 'Accept-Language',
+ '-I', 'Accept', '-I', 'Connection', '-I', 'Host', '-I', 'Keep-Alive',
+ '-I', 'User-Agent',
+
+ '-O', 'Date', '-O', 'Server', '-O', 'X-Content-Type-Warning',
+ '-O', 'X-Powered-By',
+
+ ]
+
+def dochttp(args=sys.argv[1:], default=None):
+ """Convert a tcpwatch recorded sesssion to a doctest file"""
+ if default is None:
+ default = default_options
+
+ options, args = parser.parse_args(default+args)
+ try:
+ directory, = args
+ except:
+ parser.print_help()
+ sys.exit(1)
+
+ skip_extensions = options.skip_extension or ()
+ extensions = [ext for ext in (options.extension or ())
+ if ext not in skip_extensions]
+ skip_urls = [re.compile(pattern) for pattern in (options.skip_url or ())]
+
+ names = [name[:-len(".request")]
+ for name in os.listdir(directory)
+ if name.startswith(options.prefix) and name.endswith('.request')
+ ]
+ names.sort()
+
+ extre = re.compile("[.](\w+)$")
+
+ for name in names:
+ requests = Requests(
+ open(os.path.join(directory, name + ".request")),
+ options.skip_request_header,
+ )
+ responses = Responses(
+ open(os.path.join(directory, name + ".response")),
+ options.skip_response_header,
+ )
+
+ # We use map so as *not* to truncate at shortest input.
+ # We want an error of the numberof requests and responses
+ # is different.
+ for request, response in map(None, requests, responses):
+ assert (request and response) or not (request or response)
+
+ path = request.path
+ ext = extre.search(path)
+ if ext:
+ ext = ext.group(1)
+ if extensions:
+ if ext not in extensions:
+ continue
+ else:
+ if ext in skip_extensions:
+ continue
+
+ for skip_url in skip_urls:
+ if skip_url.search(request.path):
+ break
+ else:
+ output_test(request, response)
+
+
+def output_test(request, response):
+ print
+ print
+ print ' >>> print http(r"""'
+ print ' ...', '\n ... '.join(request.lines())+'""")'
+ print ' ', '\n '.join([line.rstrip() or '<BLANKLINE>'
+ for line in response.lines()])
+
+class Message:
+
+ start = ''
+
+ def __init__(self, file, skip_headers):
+ start = file.readline().rstrip()
+ if start:
+ self.start = start
+ headers = [split_header(header)
+ for header in rfc822.Message(file).headers
+ ]
+ headers = [
+ ('-'.join([s.capitalize() for s in name.split('-')]),
+ v.rstrip()
+ )
+ for (name, v) in headers
+ if name.lower() not in skip_headers
+ ]
+ self.headers = headers
+ content_length = int(dict(headers).get('Content-Length', '0'))
+ if content_length:
+ self.body = file.read(content_length).split('\n')
+ else:
+ self.body = []
+
+ def __nonzero__(self):
+ return bool(self.start)
+
+ def lines(self):
+ if self.start:
+ output = [self.start]
+ headers = ["%s: %s" % (name, v) for (name, v) in self.headers]
+ headers.sort()
+ output.extend(headers)
+ output.append('')
+ output.extend(self.body)
+ output.extend(self.body)
+ else:
+ output = []
+
+ return output
+
+headerre = re.compile('(\S+): (.+)$')
+def split_header(header):
+ return headerre.match(header).group(1, 2)
+
+def messages(cls, file, skip_headers):
+ skip_headers = [name.lower() for name in (skip_headers or ())]
+ while 1:
+ message = cls(file, skip_headers)
+ if message:
+ yield message
+ else:
+ break
+
+class Request(Message):
+
+ path = ''
+
+ def __init__(self, file, skip_headers):
+ Message.__init__(self, file, skip_headers)
+ if self.start:
+ self.command, self.path, self.protocol = self.start.split()
+
+def Requests(file, skip_headers):
+ return messages(Request, file, skip_headers)
+
+def Responses(file, skip_headers):
+ return messages(Message, file, skip_headers)
+
+main = dochttp
+
+if __name__ == '__main__':
+ main()
Added: Zope3/trunk/src/zope/app/tests/recorded/test0001.request
===================================================================
--- Zope3/trunk/src/zope/app/tests/recorded/test0001.request 2004-08-22 19:05:53 UTC (rev 27219)
+++ Zope3/trunk/src/zope/app/tests/recorded/test0001.request 2004-08-22 19:12:14 UTC (rev 27220)
@@ -0,0 +1,81 @@
+GET /@@contents.html HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+
+GET /@@contents.html HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/pl.gif HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/@@contents.html
+If-Modified-Since: Thu, 19 Aug 2004 10:10:04 GMT
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@singleBranchTree.xml HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/mi.gif HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/
+Authorization: Basic bWdyOm1ncnB3
+
+GET /++etc++site/@@manage HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/site_management.css HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/css,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/++etc++site/@@tasks.html
+Authorization: Basic bWdyOm1ncnB3
+
Added: Zope3/trunk/src/zope/app/tests/recorded/test0001.response
===================================================================
--- Zope3/trunk/src/zope/app/tests/recorded/test0001.response 2004-08-22 19:05:53 UTC (rev 27219)
+++ Zope3/trunk/src/zope/app/tests/recorded/test0001.response 2004-08-22 19:12:14 UTC (rev 27220)
@@ -0,0 +1,130 @@
+HTTP/1.1 401 Unauthorized
+X-Content-Type-Warning: guessed from content
+Content-Length: 89
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:05 GMT
+Content-Type: text/html;charset=utf-8
+WWW-Authenticate: basic realm=zope
+Server: zope.server.http (HTTP)
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+
+...
+
+</html>
+
+HTTP/1.1 200 Ok
+X-Content-Type-Warning: guessed from content
+Content-Length: 89
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:13 GMT
+Content-Type: text/html;charset=utf-8
+Server: zope.server.http (HTTP)
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+
+...
+
+</html>
+
+HTTP/1.1 304 Not Modified
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:15 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 200 Ok
+Content-Length: 183
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Expires: Fri, 13 Aug 2004 10:35:28 GMT
+Server: zope.server.http (HTTP)
+Pragma: no-cache
+Cache-Control: no-cache
+Date: Fri, 20 Aug 2004 10:35:28 GMT
+Content-Type: text/xml;charset=utf-8
+
+<?xml version="1.0" ?><children> <collection name="" length="0" icon_url="http://localhost:8081/@@/zope-app-folder-interfaces-IFolder-zmi_icon.gif" isroot=""></collection> </children>HTTP/1.1 200 Ok
+Last-Modified: Thu, 19 Aug 2004 10:10:06 GMT
+Content-Length: 868
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:47 GMT
+Cache-Control: public,max-age=86400
+Content-Type: image/gif
+Server: zope.server.http (HTTP)
+
+GIF89a ÷ ÿ ÿ PPPÀÀÀÿ @ @ @ @ÿÿ ÿÿ @ÿÿÿ !ù , @A H° Á*|0À 6tH±¢Å%:qâÅ IräÆOX¹2¥A=,Y2¤M ;HTTP/1.1 303 See Other
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+Location: @@tasks.html
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:51 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 200 Ok
+Last-Modified: Thu, 19 Aug 2004 10:10:04 GMT
+Content-Length: 738
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:52 GMT
+Cache-Control: public,max-age=86400
+Content-Type: text/css;charset=utf-8
+Server: zope.server.http (HTTP)
+
+/*
+** Customisations for the Site Management view
+** Used when the URL contains ++etc++site
+*/
+a {
+ color: #963;
+}
+
+#actions {
+ background: #963;
+ border-left: 1px solid #963;
+ border-right: 1px solid #963;
+}
+
+#actions a {
+ color: White;
+ border-left: 1px dashed white;
+}
+
+#actions a:hover {
+ color: black;
+ background-color: White;
+}
+
+#breadcrumbs {
+ border-bottom: 1px solid #963;
+}
+
+.itemViews {
+ border-bottom: 1px solid #963;
+}
+
+.itemViews a {
+ border: 1px solid #963;
+}
+
+.itemViews a.selected {
+ background: #963;
+ border-bottom: #963 1px solid;
+}
+
+.itemViews a:hover {
+ background-color: #963;
+ color: White;
+}
+
+hr {
+ color: #963;
+}
+
+
+h1, h2, h3, h4, h5, h6 {
+ border-bottom: 1px solid #963;
+}
Added: Zope3/trunk/src/zope/app/tests/recorded/test0002.request
===================================================================
--- Zope3/trunk/src/zope/app/tests/recorded/test0002.request 2004-08-22 19:05:53 UTC (rev 27219)
+++ Zope3/trunk/src/zope/app/tests/recorded/test0002.request 2004-08-22 19:12:14 UTC (rev 27220)
@@ -0,0 +1,145 @@
+GET /@@/zope3.css HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/css,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/@@contents.html
+If-Modified-Since: Thu, 19 Aug 2004 10:10:06 GMT
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/onlinehelp.js HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: */*
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/@@contents.html
+If-Modified-Since: Thu, 19 Aug 2004 10:10:06 GMT
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/xmltree.js HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: */*
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/@@contents.html
+If-Modified-Since: Thu, 19 Aug 2004 10:10:06 GMT
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/favicon.png HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+If-Modified-Since: Thu, 19 Aug 2004 10:10:06 GMT
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/zope3logo.gif HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/@@contents.html
+If-Modified-Since: Thu, 19 Aug 2004 10:10:04 GMT
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@singleBranchTree.xml HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/zope-app-folder-interfaces-IFolder-zmi_icon.gif HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/@@contents.html
+If-Modified-Since: Thu, 19 Aug 2004 10:10:08 GMT
+Authorization: Basic bWdyOm1ncnB3
+
+GET / HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@children.xml HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Authorization: Basic bWdyOm1ncnB3
+
+GET /@@/zope-app-site-interfaces-ISiteManager-zmi_icon.gif HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/
+Authorization: Basic bWdyOm1ncnB3
+
+GET /++etc++site/@@tasks.html HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Referer: http://localhost:8081/
+Authorization: Basic bWdyOm1ncnB3
+
+GET /++etc++site/@@singleBranchTree.xml HTTP/1.1
+Host: localhost:8081
+User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.4.1) Gecko/20031114
+Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,video/x-mng,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1
+Accept-Language: en-us,en;q=0.5
+Accept-Encoding: gzip,deflate
+Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
+Keep-Alive: 300
+Connection: keep-alive
+Authorization: Basic bWdyOm1ncnB3
+
Added: Zope3/trunk/src/zope/app/tests/recorded/test0002.response
===================================================================
--- Zope3/trunk/src/zope/app/tests/recorded/test0002.response 2004-08-22 19:05:53 UTC (rev 27219)
+++ Zope3/trunk/src/zope/app/tests/recorded/test0002.response 2004-08-22 19:12:14 UTC (rev 27220)
@@ -0,0 +1,118 @@
+HTTP/1.1 304 Not Modified
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:14 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 304 Not Modified
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:14 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 304 Not Modified
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:14 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 304 Not Modified
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:14 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 304 Not Modified
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:14 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 200 Ok
+Content-Length: 183
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Expires: Fri, 13 Aug 2004 10:35:15 GMT
+Server: zope.server.http (HTTP)
+Pragma: no-cache
+Cache-Control: no-cache
+Date: Fri, 20 Aug 2004 10:35:15 GMT
+Content-Type: text/xml;charset=utf-8
+
+<?xml version="1.0" ?><children> <collection name="" length="0" icon_url="http://localhost:8081/@@/zope-app-folder-interfaces-IFolder-zmi_icon.gif" isroot=""></collection> </children>HTTP/1.1 304 Not Modified
+X-Content-Type-Warning: guessed from content
+Content-Length: 0
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:15 GMT
+Content-Type: text/plain;charset=utf-8
+Server: zope.server.http (HTTP)
+
+HTTP/1.1 200 Ok
+X-Content-Type-Warning: guessed from content
+Content-Length: 89
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:27 GMT
+Content-Type: text/html;charset=utf-8
+Server: zope.server.http (HTTP)
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+
+...
+
+</html>
+
+HTTP/1.1 200 Ok
+Content-Length: 175
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Expires: Fri, 13 Aug 2004 10:35:47 GMT
+Server: zope.server.http (HTTP)
+Pragma: no-cache
+Cache-Control: no-cache
+Date: Fri, 20 Aug 2004 10:35:47 GMT
+Content-Type: text/xml;charset=utf-8
+
+<?xml version="1.0" ?><children> <collection name="++etc++site" length="1" icon_url="http://localhost:8081/@@/zope-app-site-interfaces-ISiteManager-zmi_icon.gif"/> </children>HTTP/1.1 200 Ok
+Last-Modified: Thu, 19 Aug 2004 10:09:00 GMT
+Content-Length: 932
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:47 GMT
+Cache-Control: public,max-age=86400
+Content-Type: image/gif
+Server: zope.server.http (HTTP)
+
+GIF89a ÷ NNN¨oÿ ñï¶Wâã*çèEííqíí{îîîîïïððùâ¼ðð£òòôôÀõõËööÐøøÚùùâúúçúúëúúíýýôþþúÿÿÿ !ù , H° Á(Dp
ÐP 2 ÀãB6Ð02$D -jÈa <` `£@rºÓÁ6¸¹3d"Àt§Ó-b°@ahQ¢7/T0¡éK¦¢"Шq§Æ¨:ª 6eÅ· ;HTTP/1.1 200 Ok
+X-Content-Type-Warning: guessed from content
+Content-Length: 89
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Date: Fri, 20 Aug 2004 10:35:51 GMT
+Content-Type: text/html;charset=utf-8
+Server: zope.server.http (HTTP)
+
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+
+...
+
+</html>
+
+HTTP/1.1 200 Ok
+Content-Length: 325
+X-Powered-By: Zope (www.zope.org), Python (www.python.org)
+Expires: Fri, 13 Aug 2004 10:35:52 GMT
+Server: zope.server.http (HTTP)
+Pragma: no-cache
+Cache-Control: no-cache
+Date: Fri, 20 Aug 2004 10:35:52 GMT
+Content-Type: text/xml;charset=utf-8
+
+<?xml version="1.0" ?><children> <collection name="" length="0" icon_url="http://localhost:8081/@@/zope-app-folder-interfaces-IFolder-zmi_icon.gif" isroot=""><collection name="++etc++site" length="1" icon_url="http://localhost:8081/@@/zope-app-site-interfaces-ISiteManager-zmi_icon.gif"></collection></collection> </children>
\ No newline at end of file
Added: Zope3/trunk/src/zope/app/tests/test_dochttp.py
===================================================================
--- Zope3/trunk/src/zope/app/tests/test_dochttp.py 2004-08-22 19:05:53 UTC (rev 27219)
+++ Zope3/trunk/src/zope/app/tests/test_dochttp.py 2004-08-22 19:12:14 UTC (rev 27220)
@@ -0,0 +1,164 @@
+##############################################################################
+#
+# Copyright (c) 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.0 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Test tcpdoc
+
+$Id$
+"""
+import os
+import unittest
+from zope.testing.doctestunit import DocTestSuite
+import zope.app.tests
+from zope.app.tests.dochttp import dochttp
+
+directory = os.path.join(os.path.split(zope.app.tests.__file__)[0], 'recorded')
+
+
+expected = r'''
+
+ >>> print http(r"""
+ ... GET /@@contents.html HTTP/1.1
+ ... """)
+ HTTP/1.1 401 Unauthorized
+ Content-Length: 89
+ Content-Type: text/html;charset=utf-8
+ Www-Authenticate: basic realm=zope
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+
+
+ >>> print http(r"""
+ ... GET /@@contents.html HTTP/1.1
+ ... Authorization: Basic bWdyOm1ncnB3
+ ... """)
+ HTTP/1.1 200 Ok
+ Content-Length: 89
+ Content-Type: text/html;charset=utf-8
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+
+
+ >>> print http(r"""
+ ... GET /++etc++site/@@manage HTTP/1.1
+ ... Authorization: Basic bWdyOm1ncnB3
+ ... Referer: http://localhost:8081/
+ ... """)
+ HTTP/1.1 303 See Other
+ Content-Length: 0
+ Content-Type: text/plain;charset=utf-8
+ Location: @@tasks.html
+ <BLANKLINE>
+
+
+ >>> print http(r"""
+ ... GET / HTTP/1.1
+ ... Authorization: Basic bWdyOm1ncnB3
+ ... """)
+ HTTP/1.1 200 Ok
+ Content-Length: 89
+ Content-Type: text/html;charset=utf-8
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+
+
+ >>> print http(r"""
+ ... GET /++etc++site/@@tasks.html HTTP/1.1
+ ... Authorization: Basic bWdyOm1ncnB3
+ ... Referer: http://localhost:8081/
+ ... """)
+ HTTP/1.1 200 Ok
+ Content-Length: 89
+ Content-Type: text/html;charset=utf-8
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+ <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
+ lang="en">
+ <BLANKLINE>
+ ...
+ <BLANKLINE>
+ </html>
+ <BLANKLINE>
+ <BLANKLINE>
+'''
+
+class Test(unittest.TestCase):
+
+ def test_dochttp(self):
+ import sys, StringIO
+ old = sys.stdout
+ sys.stdout = StringIO.StringIO()
+ dochttp(['-p', 'test', directory])
+ got = sys.stdout.getvalue()
+ sys.stdout = old
+ self.assert_(got, expected)
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(Test))
+ return suite
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
+
More information about the Zope3-Checkins
mailing list