Fix sporadic test failures with a dummy directory listing.

This commit is contained in:
Bastian Kleineidam 2012-10-15 14:36:27 +02:00
parent 3a51ac7662
commit a77a5dddfd
2 changed files with 35 additions and 3 deletions

View file

@ -91,14 +91,14 @@ url /?d=directory&p=page1
cache key http://localhost:%(port)d/?d=directory&p=page1
real url http://localhost:%(port)d/?d=directory&p=page1
name should not be cached
warning Content with 1KB is the same as in URLs (http://localhost:%(port)d/?d=directory&p=page).
warning Content with 309B is the same as in URLs (http://localhost:%(port)d/?d=directory&p=page).
valid
url /?quoted=ü
cache key http://localhost:%(port)d/?quoted=%%C3%%BC
real url http://localhost:%(port)d/?quoted=%%C3%%BC
name html entities
warning Content with 1KB is the same as in URLs (http://localhost:%(port)d/?d=directory&p=page,http://localhost:%(port)d/?d=directory&p=page1).
warning Content with 309B is the same as in URLs (http://localhost:%(port)d/?d=directory&p=page,http://localhost:%(port)d/?d=directory&p=page1).
valid
url (cached)

View file

@ -23,6 +23,9 @@ import BaseHTTPServer
import httplib
import time
import threading
import cgi
import urllib
from cStringIO import StringIO
from . import LinkCheckTest
@ -67,7 +70,8 @@ class StoppableHttpServer (BaseHTTPServer.HTTPServer, object):
class NoQueryHttpRequestHandler (StoppableHttpRequestHandler):
"""
Handler ignoring the query part of requests.
Handler ignoring the query part of requests and sending dummy directory
listings.
"""
def remove_path_query (self):
@ -92,6 +96,34 @@ class NoQueryHttpRequestHandler (StoppableHttpRequestHandler):
self.remove_path_query()
super(NoQueryHttpRequestHandler, self).do_HEAD()
def list_directory(self, path):
"""Helper to produce a directory listing (absent index.html).
Return value is either a file object, or None (indicating an
error). In either case, the headers are sent, making the
interface the same as for send_head().
"""
f = StringIO()
f.write('<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">')
f.write("<html>\n<title>Dummy directory listing</title>\n")
f.write("<body>\n<h2>Dummy test directory listing</h2>\n")
f.write("<hr>\n<ul>\n")
list = ["example1.txt", "example2.html", "example3"]
for name in list:
displayname = linkname = name
f.write('<li><a href="%s">%s</a>\n'
% (urllib.quote(linkname), cgi.escape(displayname)))
f.write("</ul>\n<hr>\n</body>\n</html>\n")
length = f.tell()
f.seek(0)
self.send_response(200)
encoding = "utf-8"
self.send_header("Content-type", "text/html; charset=%s" % encoding)
self.send_header("Content-Length", str(length))
self.end_headers()
return f
class HttpServerTest (LinkCheckTest):
"""