[wwwsearch-commits] r43927 - in wwwsearch/mechanize/trunk: . test-tools
jjlee at codespeak.net
jjlee at codespeak.net
Thu May 31 00:37:14 CEST 2007
Author: jjlee
Date: Thu May 31 00:37:13 2007
New Revision: 43927
Modified:
wwwsearch/mechanize/trunk/functional_tests.py
wwwsearch/mechanize/trunk/test-tools/twisted-localserver.py
Log:
A bit more work on local twisted server for functional tests: Add 302 redirection page to get rid of one of the hardcoded wwwsearch URLs. Fix some issues in local twisted server.
Modified: wwwsearch/mechanize/trunk/functional_tests.py
==============================================================================
--- wwwsearch/mechanize/trunk/functional_tests.py (original)
+++ wwwsearch/mechanize/trunk/functional_tests.py Thu May 31 00:37:13 2007
@@ -57,13 +57,13 @@
self.assertEqual(self.browser.title(), 'mechanize')
def test_302_and_404(self):
- # the combination of 302 (caused by use of "sf.net") and 404 has caused
- # problems in the past due to accidental double-wrapping of the error
- # response
+ # the combination of 302 and 404 (/redirected is configured to redirect
+ # to a non-existent URL /nonexistent) has caused problems in the past
+ # due to accidental double-wrapping of the error response
import urllib2
self.assertRaises(
urllib2.HTTPError,
- self.browser.open, "http://wwwsearch.sf.net/doesnotexist",
+ self.browser.open, urljoin(self.uri, "/redirected"),
)
def test_reread(self):
Modified: wwwsearch/mechanize/trunk/test-tools/twisted-localserver.py
==============================================================================
--- wwwsearch/mechanize/trunk/test-tools/twisted-localserver.py (original)
+++ wwwsearch/mechanize/trunk/test-tools/twisted-localserver.py Thu May 31 00:37:13 2007
@@ -60,29 +60,45 @@
{"content-type": self.content_type},
self.text)
-def make_page(root, name, text,
- content_type="text/html"):
+def _make_page(root, name, text,
+ content_type="text/html",
+ leaf=False):
page = Page()
page.text = text
base_type, specific_type = content_type.split("/")
page.content_type = http_headers.MimeType(base_type, specific_type)
+ page.addSlash = not leaf
setattr(root, "child_"+name, page)
return page
+def make_page(root, name, text,
+ content_type="text/html"):
+ return _make_page(root, name, text, content_type, leaf=False)
+
+def make_leaf_page(root, name, text,
+ content_type="text/html"):
+ return _make_page(root, name, text, content_type, leaf=True)
+
+def make_redirect(root, name, location_relative_ref):
+ redirect = resource.RedirectResource(path=location_relative_ref)
+ setattr(root, "child_"+name, redirect)
+ return redirect
+
def main():
root = Page()
root.text = ROOT_HTML
make_page(root, "mechanize", MECHANIZE_HTML)
- bits = make_page(root, "robots.txt",
- "User-Agent: *\nDisallow: /norobots",
- "text/plain")
- bits = make_page(root, "robots", "Hello, robots.", "text/plain")
- bits = make_page(root, "norobots", "Hello, non-robots.", "text/plain")
+ make_leaf_page(root, "robots.txt",
+ "User-Agent: *\nDisallow: /norobots",
+ "text/plain")
+ make_leaf_page(root, "robots", "Hello, robots.", "text/plain")
+ make_leaf_page(root, "norobots", "Hello, non-robots.", "text/plain")
bits = make_page(root, "bits", "GeneralFAQ.html")
- make_page(bits, "cctest2.txt",
- "Hello ClientCookie functional test suite.",
- "text/plain")
- make_page(bits, "mechanize_reload_test.html", RELOAD_TEST_HTML)
+ make_leaf_page(bits, "cctest2.txt",
+ "Hello ClientCookie functional test suite.",
+ "text/plain")
+ make_leaf_page(bits, "mechanize_reload_test.html", RELOAD_TEST_HTML)
+ make_redirect(root, "redirected", "/doesnotexist")
site = server.Site(root)
reactor.listenTCP(int(sys.argv[1]), channel.HTTPFactory(site))
More information about the wwwsearch-commits
mailing list