You are viewing a plain text version of this content. The canonical link for it is here.
Posted to mod_python-commits@quetz.apache.org by jg...@apache.org on 2006/10/14 17:45:38 UTC

svn commit: r463963 [3/4] - in /httpd/mod_python/branches/jgallacher/tools/test-ng: ./ conf/ htdocs/ htdocs/core/ htdocs/core/subdir/ htdocs/leaktests/ mptest/ mptest/core/ mptest/leaktest/

Added: httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/request.py
URL: http://svn.apache.org/viewvc/httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/request.py?view=auto&rev=463963
==============================================================================
--- httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/request.py (added)
+++ httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/request.py Sat Oct 14 08:45:35 2006
@@ -0,0 +1,1173 @@
+import base64
+import os
+
+
+from mptest.httpdconf import *
+from mptest.testconf import * 
+from mptest.testsetup import register
+from mptest.util import findUnusedPort
+
+
+class DocumentRootTest(PerRequestTestBase):
+    handler = "request::req_document_root"
+    server_name = "test_req_document_root"
+
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+    def runTest(self):
+        """DocumentRootTest: req.document_root()"""
+
+        print "\n  * Testing req.document_root()"
+        rsp = self.vhost_get("test_req_document_root")
+
+        if rsp.upper() != self.document_root.replace("\\", "/").upper():
+            self.fail(`rsp`)
+register(DocumentRootTest)
+
+
+class AddHandlerTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_add_handler"
+    handler = "request::req_add_handler"
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+    def runTest(self):
+        """AddHandler: req.add_handler()"""
+
+        print "\n  * Testing req.add_handler()"
+        rsp = self.vhost_get(self.server_name)
+
+        if (rsp != 2*"test ok"):
+            self.fail(`rsp`)
+register(AddHandlerTest)
+
+
+class AddBadHandlerTest(PerRequestTestBase):
+    """Adding a non-existent handler with req.add_handler should
+    raise an exception.
+    """
+
+    server_name = "test_req_add_bad_handler"
+    handler = "request::req_add_bad_handler"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+    def runTest(self):
+        """AddBadHandlerTest: req_add_bad_handler"""
+
+        print """\n  * Testing req.add_handler("PythonHandler", "bad_handler")"""
+        rsp = self.vhost_get(self.server_name)
+
+        # look for evidence of the exception in the error log 
+        time.sleep(1)
+        f = open(os.path.join(self.httpd.server_root, "logs/error_log"))
+        log = f.read()
+        f.close()
+        if log.find("contains no 'bad_handler'") == -1:
+            self.fail("""Could not find "contains no 'bad_handler'" in error_log""")
+register(AddBadHandlerTest)
+
+
+class AddEmptyHandlerStringTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_add_empty_handler_string"
+    handler = "request::req_add_empty_handler_string"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """AddEmptyHandlerStringTest: req_add_empty_handler_string"""
+        # Adding an empty string as the handler in req.add_handler
+        # should raise an exception
+
+        print """\n  * Testing req.add_handler("PythonHandler","")"""
+        rsp = self.vhost_get("test_req_add_empty_handler_string")
+
+        if (rsp == "no exception"):
+            self.fail("Expected an exception")
+
+register(AddEmptyHandlerStringTest)
+
+
+
+class AddHandlerEmptyPhaseTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_add_handler_empty_phase"
+    handler = "request::req_add_handler_empty_phase"
+
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonInterpPerDirective("On"),
+                                  PythonFixupHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """AddHandlerEmptyPhaseTest: req_add_handler_empty_phase"""
+        # Adding handler to content phase when no handler already
+        # exists for that phase.
+
+        print """\n  * Testing req.add_handler() for empty phase"""
+        rsp = self.vhost_get("test_req_add_handler_empty_phase")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(AddHandlerEmptyPhaseTest)
+
+
+
+class AddHandlerEmptyPhaseTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_add_handler_empty_phase"
+    handler = "request::req_add_handler_empty_phase"
+
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonInterpPerDirective("On"),
+                                  PythonFixupHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """AddHandlerEmptyPhaseTest: req_add_handler_empty_phase"""
+        # Adding handler to content phase when no handler already
+        # exists for that phase.
+
+        print """\n  * Testing req.add_handler() for empty phase"""
+        rsp = self.vhost_get("test_req_add_handler_empty_phase")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(AddHandlerEmptyPhaseTest)
+
+
+class AddHandlerDirectoryTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_add_handler_directory"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonInterpPerDirective("On"),
+                                  PythonFixupHandler("request::test_req_add_handler_directory"),
+                                  PythonDebug("On")))
+
+    def runTest(self):
+        """AddHandlerDirectoryTest: req_add_handler_directory"""
+        # Checking that directory is canonicalized and trailing
+        # slash is added.
+
+        print """\n  * Testing req.add_handler() directory"""
+        rsp = self.vhost_get("test_req_add_handler_directory")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(AddHandlerDirectoryTest)
+
+
+
+class AccesshandlerAddHandlerToEmptyHlTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_accesshandler_add_handler_to_empty_hl"
+    
+    def config(self):
+        # Note that there is no PythonHandler specified in the the VirtualHost
+        # config. We want to see if req.add_handler will work when the 
+        # handler list is empty.
+
+        #PythonHandler("request::req_add_empty_handler_string"),
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonAccessHandler("request::accesshandler_add_handler_to_empty_hl"),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """AccesshandlerAddHandlerToEmptyHlTest: accesshandler_add_handler_to_empty_hl"""
+
+        print """\n  * Testing req.add_handler() when handler list is empty"""
+        rsp = self.vhost_get("test_accesshandler_add_handler_to_empty_hl")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(AccesshandlerAddHandlerToEmptyHlTest)
+
+
+class AllowMethodsTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_allow_methods"
+    handler = "request::req_allow_methods"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """AllowMethodsTest: req_allow_methods"""
+
+        print "\n  * Testing req.allow_methods()"
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/request.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_allow_methods", self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        server_hdr = response.getheader("Allow", "")
+        conn.close()
+
+        self.failUnless(server_hdr.find("PYTHONIZE") > -1, "req.allow_methods() didn't work")
+
+register(AllowMethodsTest)
+
+
+class GetBasicAuthPwTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_get_basic_auth_pw"
+    handler = "request::req_get_basic_auth_pw"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  AuthName("blah"),
+                                  AuthType("basic"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """GetBasicAuthPwTest: req_get_basic_auth_pw"""
+
+        print "\n  * Testing req.get_basic_auth_pw()"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/request.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_get_basic_auth_pw", self.httpd.port))
+        auth = base64.encodestring("spam:eggs").strip()
+        conn.putheader("Authorization", "Basic %s" % auth)
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(GetBasicAuthPwTest)
+
+
+class AuthTypeTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_auth_type"
+    handler = "request::req_auth_type"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  AuthName("blah"),
+                                  AuthType("dummy"),
+                                  Require("valid-user"),
+                                  PythonAuthenHandler("request::req_auth_type"),
+                                  PythonAuthzHandler("request::req_auth_type"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """AuthTypeTest: req_auth_type"""
+
+        print "\n  * Testing req.auth_type()"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/request.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_auth_type", self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(AuthTypeTest)
+
+
+class RequiresTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_requires"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                    ServerName(self.server_name),
+                    DocumentRoot(self.document_root),
+                    Directory(self.document_root,
+                              SetHandler("mod_python"),
+                              AuthName("blah"),
+                              AuthType("dummy"),
+                              Require("valid-user"),
+                              PythonAuthenHandler("request::req_requires"),
+                              PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """RequiresTest: req_requires"""
+
+        print "\n  * Testing req.requires()"
+
+        rsp = self.vhost_get("test_req_requires")
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/request.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_requires", self.httpd.port))
+        auth = base64.encodestring("spam:eggs").strip()
+        conn.putheader("Authorization", "Basic %s" % auth)
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(RequiresTest)
+
+
+class InternalRedirectTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_internal_redirect"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler("request::req_internal_redirect | .py"),
+                                  PythonHandler("request::req_internal_redirect_int | .int"),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """InternalRedirectTest: req.internal_redirect()"""
+
+        print "\n  * Testing %s" % self.runTest.__doc__
+
+        rsp = self.vhost_get("test_req_internal_redirect")
+
+        if rsp != "test ok":
+            self.fail("internal_redirect")
+
+register(InternalRedirectTest)
+
+
+class ConstructUrlTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_construct_url"
+    handler = "request::req_construct_url"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """ConstructUrlTest: req.construct_url()"""
+
+        print "\n  * Testing", self.shortDescription()
+        rsp = self.vhost_get("test_req_construct_url")
+
+        if rsp != "test ok":
+            self.fail("construct_url")
+
+register(ConstructUrlTest)
+
+
+class ReadTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_read"
+    handler = "request::req_read"
+    
+    def config(self):
+
+        return str(Timeout("5")) + \
+            str(VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On"))))
+
+    def runTest(self):
+        """ReadTest: req_read"""
+
+        print "\n  * Testing req.read()"
+
+        params = '1234567890'*10000
+        print "    writing %d bytes..." % len(params)
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("POST", "/request.py", skip_host=1)
+        conn.putheader("Host", "test_req_read:%s" % self.httpd.port)
+        conn.putheader("Content-Length", len(params))
+        conn.endheaders()
+        conn.send(params)
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        print "    response size: %d\n" % len(rsp)
+        if (rsp != params):
+            self.fail(`rsp`)
+
+        print "    read/write ok, now lets try causing a timeout (should be 5 secs)"
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("POST", "/request.py", skip_host=1)
+        conn.putheader("Host", "test_req_read:%s" % self.httpd.port)
+        conn.putheader("Content-Length", 10)
+        conn.endheaders()
+        conn.send("123456789")
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if rsp.find("IOError") < 0:
+            self.fail("timeout test failed")
+
+
+register(ReadTest)
+
+class ReadlineTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_readline"
+    handler = "request::req_readline"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """ReadlineTest: req_readline"""
+
+        print "\n  * Testing req.readline()"
+
+        params = ('1234567890'*3000+'\n')*4
+        print "    writing %d bytes..." % len(params)
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("POST", "/request.py", skip_host=1)
+        conn.putheader("Host", "test_req_readline:%s" % self.httpd.port)
+        conn.putheader("Content-Length", len(params))
+        conn.endheaders()
+        conn.send(params)
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        print "    response size: %d\n" % len(rsp)
+        if (rsp != params):
+            self.fail(`rsp`)
+
+register(ReadlineTest)
+
+
+class ReadlinesTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_readlines"
+    handler = "request::req_readlines"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """ReadlinesTest: req_readlines"""
+
+        print "\n  * Testing req.readlines()"
+
+        params = ('1234567890'*3000+'\n')*4
+        print "    writing %d bytes..." % len(params)
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("POST", "/request.py", skip_host=1)
+        conn.putheader("Host", "test_req_readlines:%s" % self.httpd.port)
+        conn.putheader("Content-Length", len(params))
+        conn.endheaders()
+        conn.send(params)
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        print "    response size: %d\n" % len(rsp)
+        if (rsp != params):
+            self.fail(`rsp`)
+
+        print "\n  * Testing req.readlines(size_hint=30000)"
+
+        params = ('1234567890'*3000+'\n')*4
+        print "    writing %d bytes..." % len(params)
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("POST", "/request.py", skip_host=1)
+        conn.putheader("Host", "test_req_readlines:%s" % self.httpd.port)
+        conn.putheader("Content-Length", len(params))
+        conn.putheader("SizeHint", 30000)
+        conn.endheaders()
+        conn.send(params)
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        print "    response size: %d\n" % len(rsp)
+        if (rsp != ('1234567890'*3000+'\n')):
+            self.fail(`rsp`)
+
+        print "\n  * Testing req.readlines(size_hint=32000)"
+
+        params = ('1234567890'*3000+'\n')*4
+        print "    writing %d bytes..." % len(params)
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("POST", "/request.py", skip_host=1)
+        conn.putheader("Host", "test_req_readlines:%s" % self.httpd.port)
+        conn.putheader("Content-Length", len(params))
+        conn.putheader("SizeHint", 32000)
+        conn.endheaders()
+        conn.send(params)
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        print "    response size: %d\n" % len(rsp)
+        if (rsp != (('1234567890'*3000+'\n')*2)):
+            self.fail(`rsp`)
+
+register(ReadlinesTest)
+
+
+class DiscardRequestBodyTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_discard_request_body"
+    handler = "request::req_discard_request_body"
+    
+    def config(self):
+
+        return str(Timeout("5")) + \
+            str(VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On"))))
+
+    def runTest(self):
+        """DiscardRequestBodyTest: req_discard_request_body"""
+
+        print "\n  * Testing req.discard_request_body()"
+
+        params = '1234567890'*2
+        print "    writing %d bytes..." % len(params)
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/request.py", skip_host=1)
+        conn.putheader("Host", "test_req_discard_request_body:%s" % self.httpd.port)
+        conn.putheader("Content-Length", len(params))
+        conn.endheaders()
+        conn.send(params)
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(DiscardRequestBodyTest)
+
+
+class RegisterCleanupTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_register_cleanup"
+    handler = "request::req_register_cleanup"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """RegisterCleanupTest: req_register_cleanup"""
+
+        print "\n  * Testing req.register_cleanup()"
+
+        rsp = self.vhost_get("test_req_register_cleanup")
+        
+        # see what's in the log now
+        time.sleep(1)
+        f = open(os.path.join(self.httpd.server_root, "logs/error_log"))
+        log = f.read()
+        f.close()
+        if log.find("req_register_cleanup test ok") == -1:
+            self.fail("Could not find test message in error_log")
+
+register(RegisterCleanupTest)
+
+
+class HeadersOutTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_headers_out"
+    handler = "request::req_headers_out"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """HeadersOutTest: req_headers_out"""
+
+        print "\n  * Testing req.headers_out"
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/test.py", skip_host=1)
+        conn.putheader("Host", "test_req_headers_out:%s" % self.httpd.port)
+        conn.endheaders()
+        response = conn.getresponse()
+        h = response.getheader("x-test-header", None)
+        response.read()
+        conn.close()
+
+        if h is None:
+            self.fail("Could not find x-test-header")
+
+        if h != "test ok":
+            self.fail("x-test-header is there, but does not contain 'test ok'")
+
+register(HeadersOutTest)
+
+
+class SendfileTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_sendfile"
+    handler = "request::req_sendfile"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """SendfileTest: req_sendfile"""
+
+        print "\n  * Testing req.sendfile() with offset and length"
+
+        rsp = self.vhost_get("test_req_sendfile")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(SendfileTest)
+
+
+class Sendfile2Test(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_sendfile2"
+    handler = "request::req_sendfile2"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """Sendfile2Test: req_sendfile2"""
+
+        print "\n  * Testing req.sendfile() without offset and length"
+
+        rsp = self.vhost_get("test_req_sendfile2")
+
+        if (rsp != "0123456789"*100):
+            self.fail(`rsp`)
+
+register(Sendfile2Test)
+
+
+class Sendfile3Test(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_sendfile3"
+    handler = "request::req_sendfile3"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """Sendfile3Test: req_sendfile3"""
+
+        if os.name == 'posix':
+
+            print "\n  * Testing req.sendfile() for a file which is a symbolic link"
+
+            rsp = self.vhost_get("test_req_sendfile3")
+
+            if (rsp != "0123456789"*100):
+                self.fail(`rsp`)
+        else:
+            print "\n  * Skipping req.sendfile() for a file which is a symbolic link"
+
+register(Sendfile3Test)
+
+
+class HandlerTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_handler"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  PythonFixupHandler("request::req_handler"),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """HandlerTest: req_handler"""
+
+        print "\n  * Testing req.handler"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_handler", self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(HandlerTest)
+
+
+class NoCacheTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_no_cache"
+    handler = "request::req_no_cache"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """NoCacheTest: req_no_cache"""
+
+        print "\n  * Testing req.no_cache"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/request.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_no_cache", self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if response.getheader("expires", None) is None:
+            self.fail(`response.getheader("expires", None)`)
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(NoCacheTest)
+
+
+class UpdateMtimeTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_update_mtime"
+    handler = "request::req_update_mtime"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """UpdateMtimeTest: req_update_mtime"""
+
+        print "\n  * Testing req.update_mtime"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/request.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_req_update_mtime", self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if response.getheader("etag", None) is None:
+            self.fail(`response.getheader("etag", None)`)
+
+        if response.getheader("last-modified", None) is None:
+            self.fail(`response.getheader("last-modified", None)`)
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(UpdateMtimeTest)
+
+
+class UtilRedirectTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_util_redirect"
+    handler = "request::util_redirect"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  PythonFixupHandler("request::util_redirect"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """UtilRedirectTest: util_redirect"""
+
+        print "\n  * Testing util.redirect()"
+        
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/", skip_host=1)
+        conn.putheader("Host", "%s:%s" % ("test_util_redirect", self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if response.status != 302:
+            self.fail('did not receive 302 status response')
+
+        if response.getheader("location", None) != "/dummy":
+            self.fail('did not receive correct location for redirection')
+        
+        if rsp != "test ok":
+            self.fail(`rsp`)
+
+register(UtilRedirectTest)
+
+
+class ServerGetConfigTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_server_get_config"
+    handler = "request::req_server_get_config"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        PythonDebug("On"),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("Off")))
+
+
+    def runTest(self):
+        """ServerGetConfigTest: req_server_get_config"""
+
+        print "\n  * Testing req.server.get_config()"
+
+        rsp = self.vhost_get("test_req_server_get_config")
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(ServerGetConfigTest)
+
+
+class ServerGetOptionsTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_server_get_options"
+    handler = "request::req_server_get_options"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        PythonDebug("Off"),
+                        PythonOption("global 1"),
+                        PythonOption("override 1"),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption("local 1"),
+                                  PythonOption("override 2"),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """ServerGetOptionsTest: req_server_get_options"""
+
+        print "\n  * Testing req.server.get_options()"
+
+        rsp = self.vhost_get("test_req_server_get_options")
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(ServerGetOptionsTest)
+
+
+
+
+class ReqRegisterOutputFilterTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_register_output_filter"
+    handler = "request::req_register_output_filter"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        SetHandler("mod_python"),
+                        PythonPath("[r'%s']+sys.path" % self.document_root),
+                        PythonHandler(self.handler),
+                        PythonDebug("On"))
+
+
+    def runTest(self):
+        """ReqRegisterOutputFilterTest: req_register_output_filter"""
+
+        print "\n  * Testing req.register_output_filter"
+        rsp = self.vhost_get("test_req_register_output_filter")
+
+        if (rsp != "TTEESSTT  OOKK"):
+            self.fail(`rsp`)
+
+register(ReqRegisterOutputFilterTest)
+
+
+class ReqAddOutputFilterTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_req_add_output_filter"
+    handler = "request::req_add_output_filter"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        SetHandler("mod_python"),
+                        PythonPath("[r'%s']+sys.path" % self.document_root),
+                        PythonHandler(self.handler),
+                        PythonOutputFilter("request::outputfilter1 MP_TEST_FILTER"),
+                        PythonDebug("On"))
+
+
+    def runTest(self):
+        """ReqAddOutputFilterTest: req_add_output_filter"""
+
+        print "\n  * Testing req.add_output_filter"
+        rsp = self.vhost_get("test_req_add_output_filter")
+
+        if (rsp != "TEST OK"):
+            self.fail(`rsp`)
+
+register(ReqAddOutputFilterTest)
+
+
+
+class OutputfilterTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_outputfilter"
+    handler = "request::simplehandler"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        SetHandler("mod_python"),
+                        PythonPath("[r'%s']+sys.path" % self.document_root),
+                        PythonHandler(self.handler),
+                        PythonOutputFilter("request::outputfilter1 MP_TEST_FILTER"),
+                        PythonDebug("On"),
+                        AddOutputFilter("MP_TEST_FILTER .py"))
+
+
+    def runTest(self):
+        """OutputfilterTest: outputfilter"""
+
+        print "\n  * Testing PythonOutputFilter"
+        rsp = self.vhost_get("test_outputfilter")
+
+        if (rsp != "TEST OK"):
+            self.fail(`rsp`)
+
+register(OutputfilterTest)
+
+
+

Added: httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/session.py
URL: http://svn.apache.org/viewvc/httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/session.py?view=auto&rev=463963
==============================================================================
--- httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/session.py (added)
+++ httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/session.py Sat Oct 14 08:45:35 2006
@@ -0,0 +1,192 @@
+"""Session unit tests go here"""
+
+import httplib
+import shutil
+
+from mptest.testsetup import register
+from mptest.testconf import * 
+from mptest.httpdconf import *
+
+class SessionSessionTest(PerRequestTestBase):
+    handler = "session::Session_Session"
+
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption('session_directory "%s"' % self.httpd.tmp_dir),
+                                  PythonOption('ApplicationPath "/path"'),
+                                  PythonOption('mod_python.session.application_domain "test_Session_Session"'),
+                                  PythonDebug("On")))
+
+    def runTest(self):
+        """SessionTest: Session.Session(self)"""
+
+        print "\n  * Testing", self.shortDescription()
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/session.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % (self.server_name, self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        setcookie = response.getheader("set-cookie", None)
+        rsp = response.read()
+        conn.close()
+
+        if rsp != "test ok" or setcookie == None:
+            self.fail("session did not set a cookie")
+
+        parts = setcookie.split('; ')
+        fields = {}
+        for part in parts:
+          key, value = part.split('=')
+          fields[key] = value
+
+        if not fields.has_key('path') or fields['path'] != '/path':
+            self.fail("session did not contain expected 'path'")
+
+        if not fields.has_key('domain') or fields['domain'] != 'test_Session_Session':
+            self.fail("session did not contain expected 'domain'")
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/session.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % (self.server_name, self.httpd.port))
+        conn.putheader("Cookie", setcookie)
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+        if rsp != "test ok":
+            self.fail("session did not accept our cookie")
+
+    def tearDown(self):
+        super(PerRequestTestBase, self).tearDown()
+        try:
+            os.remove(os.path.join(self.httpd.tmp_dir, 'mp_sess.dbm'))
+        except:
+            pass
+
+register(SessionSessionTest)
+
+
+class FileSessionTest(PerRequestTestBase):
+    """Tests FileSession created by Session.Session with the
+    session class name passed as a PythonOption
+    """
+    handler = "session::Session_Session"
+
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption('session FileSession'),
+                                  PythonOption('session_directory "%s"' % self.httpd.tmp_dir),
+                                  PythonOption('mod_python.session.application_domain "test_Session_FileSession"'),
+                                  PythonOption('ApplicationPath "/path"'),
+                                  PythonDebug("On")))
+
+    def runTest(self):
+        """FileSessionTest: Session(req) using PythonOption session FileSession"""
+
+        print "\n  * Testing", self.shortDescription()
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/session.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % (self.server_name, self.httpd.port))
+        conn.endheaders()
+        response = conn.getresponse()
+        setcookie = response.getheader("set-cookie", None)
+        rsp = response.read()
+        conn.close()
+
+        if rsp != "test ok" or setcookie == None:
+            self.fail("session did not set a cookie")
+
+        parts = setcookie.split('; ')
+        fields = {}
+        for part in parts:
+          key, value = part.split('=')
+          fields[key] = value
+
+        if not fields.has_key('path') or fields['path'] != '/path':
+            self.fail("session did not contain expected 'path'")
+
+        if not fields.has_key('domain') or fields['domain'] != 'test_Session_FileSession':
+            self.fail("session did not contain expected 'domain'")
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/session.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % (self.server_name, self.httpd.port))
+        conn.putheader("Cookie", setcookie)
+        conn.endheaders()
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+        if rsp != "test ok":
+            self.fail("session did not accept our cookie")
+
+        if not os.path.exists(os.path.join(self.httpd.tmp_dir, 'mp_sess')):
+            self.fail("FileSession directory not properly set")
+
+    def tearDown(self):
+        super(PerRequestTestBase, self).tearDown()
+        shutil.rmtree(os.path.join(self.httpd.tmp_dir, 'mp_sess'), ignore_errors=True)
+
+register(FileSessionTest)
+
+
+class SessionIllegalSidTest(PerRequestTestBase):
+    handler = "tests::Session_Session"
+
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                        SetHandler("mod_python"),
+                        PythonHandler(self.handler),
+                        PythonOption('session_directory "%s"' % self.httpd.tmp_dir),
+                        PythonDebug("On")))
+
+    def runTest(self):
+        """SessionIllegalSidTest: session with illegal session id value"""
+
+        print "\n  * Testing", self.shortDescription()
+        bad_cookie = 'pysid=/path/traversal/attack/bad; path=/'
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/session.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % (self.server_name, self.httpd.port))
+        conn.putheader("Cookie", bad_cookie)
+        conn.endheaders()
+        response = conn.getresponse()
+        status = response.status
+        conn.close()
+        if status != 500:
+            self.fail("session accepted a sid with illegal characters")
+
+        bad_cookie = 'pysid=%s; path=/' % ('abcdef'*64)
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/session.py", skip_host=1)
+        conn.putheader("Host", "%s:%s" % (self.server_name, self.httpd.port))
+        conn.putheader("Cookie", bad_cookie)
+        conn.endheaders()
+        response = conn.getresponse()
+        status = response.status
+        conn.close()
+        if status != 500:
+            self.fail("session accepted a sid which is too long")
+
+    def tearDown(self):
+        super(PerRequestTestBase, self).tearDown()
+        try:
+            os.remove(os.path.join(self.httpd.tmp_dir, 'mp_sess.dbm'))
+        except:
+            pass
+
+register(SessionIllegalSidTest)

Added: httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/tests.py
URL: http://svn.apache.org/viewvc/httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/tests.py?view=auto&rev=463963
==============================================================================
--- httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/tests.py (added)
+++ httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/tests.py Sat Oct 14 08:45:35 2006
@@ -0,0 +1,1100 @@
+import httplib
+import md5
+import random
+import socket
+import urllib
+
+from mptest.httpdconf import *
+from mptest.testconf import * 
+from mptest.testsetup import register
+from mptest.util import findUnusedPort
+
+
+class FileuploadTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_fileupload"
+    handler = "tests::fileupload"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """FileuploadTest: fileupload"""
+    
+        print "\n  * Testing 1 MB file upload support"
+
+        content = ''.join( [ chr(random.randrange(256)) for x in xrange(1024*1024) ] )
+        digest = md5.new(content).hexdigest()
+
+        rsp = self.vhost_post_multipart_form_data(
+            "test_fileupload",
+            variables={'test':'abcd'},
+            files={'testfile':('test.txt',content)},
+        )
+
+        if (rsp != digest):
+            self.fail('1 MB file upload failed, its contents were corrupted (%s)'%rsp)
+   
+register(FileuploadTest)
+
+
+class FileuploadEmbeddedCrTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_fileupload"
+    handler = "tests::fileupload"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """FileuploadEmbeddedCrTest: fileupload_embedded_cr"""
+        # Strange things can happen if there is a '\r' character at position
+        # readBlockSize of a line being read by FieldStorage.read_to_boundary 
+        # where the line length is > readBlockSize.
+        # This test will expose this problem.
+        
+        print "\n  * Testing file upload with \\r char in a line at position == readBlockSize"
+        
+        content = (
+            'a'*100 + '\r\n'
+            + 'b'*(readBlockSize-1) + '\r' # trick !
+            + 'ccc' + 'd'*100 + '\r\n'
+        )
+        digest = md5.new(content).hexdigest()
+        
+        rsp = self.vhost_post_multipart_form_data(
+            "test_fileupload",
+            variables={'test':'abcd'},
+            files={'testfile':('test.txt',content)},
+        )
+
+        if (rsp != digest):
+            self.fail('file upload embedded \\r test failed, its contents were corrupted (%s)'%rsp)
+
+        # The UNIX-HATERS handbook illustrates this problem. Once we've done some additional
+        # investigation to make sure that our synthetic file used above is correct,
+        # we can likely remove this conditional test. Also, there is no way to be sure
+        # that ugh.pdf will always be the same in the future so the test may not be valid
+        # over the long term.
+        try:
+            ugh = file('ugh.pdf','rb')
+            content = ugh.read()
+            ugh.close()
+        except:
+            print "  * Skipping the test for The UNIX-HATERS handbook file upload."
+            print "    To make this test, you need to download ugh.pdf from"
+            print "    http://research.microsoft.com/~daniel/uhh-download.html"
+            print "    into this script's directory."
+        else:
+            print "  * Testing The UNIX-HATERS handbook file upload support"
+    
+            digest = md5.new(content).hexdigest()
+    
+            rsp = self.vhost_post_multipart_form_data(
+                "test_fileupload",
+                variables={'test':'abcd'},
+                files={'testfile':('ugh.pdf',content)},
+            )
+    
+            
+            if (rsp != digest):
+                self.fail('The UNIX-HATERS handbook file upload failed, its contents was corrupted (%s)'%rsp)
+
+register(FileuploadEmbeddedCrTest)
+
+
+class FileuploadSplitBoundaryTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_fileupload"
+    handler = "tests::fileupload"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """FileuploadSplitBoundaryTest: fileupload_split_boundary"""
+        # This test is similar to test_fileupload_embedded_cr, but it is possible to
+        # write an implementation of FieldStorage.read_to_boundary that will pass
+        # that test but fail this one.
+        # 
+        # Strange things can happen if the last line in the file being uploaded 
+        # has length == readBlockSize -1. The boundary string marking the end of the
+        # file (eg. '\r\n--myboundary') will be split between the leading '\r' and the
+        # '\n'. Some implementations of read_to_boundary we've tried assume that this
+        # '\r' character is part of the file, instead of the boundary string. The '\r'
+        # will be appended to the uploaded file, leading to a corrupted file.
+
+        print "\n  * Testing file upload where length of last line == readBlockSize - 1"
+
+        content = (
+            'a'*100 + '\r\n'
+            + 'b'*(readBlockSize-1)  # trick !
+        )
+        digest = md5.new(content).hexdigest()
+        
+        rsp = self.vhost_post_multipart_form_data(
+            "test_fileupload",
+            variables={'test':'abcd'},
+            files={'testfile':('test.txt',content)},
+        )
+
+        if (rsp != digest):
+            self.fail('file upload long line test failed, its contents were corrupted (%s)'%rsp)
+
+        print "  * Testing file upload where length of last line == readBlockSize - 1 with an extra \\r"
+
+        content = (
+            'a'*100 + '\r\n'
+            + 'b'*(readBlockSize-1)
+            + '\r'  # second trick !
+        )
+        digest = md5.new(content).hexdigest()
+        
+        rsp = self.vhost_post_multipart_form_data(
+            "test_fileupload",
+            variables={'test':'abcd'},
+            files={'testfile':('test.txt',content)},
+        )
+
+        if (rsp != digest):
+            self.fail('file upload long line test failed, its contents were corrupted (%s)'%rsp)
+
+register(FileuploadSplitBoundaryTest)
+
+
+class SysArgvTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_sys_argv"
+    handler = "tests::test_sys_argv"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """SysArgvTest: sys_argv"""
+
+        print "\n  * Testing sys.argv definition"
+
+        rsp = self.vhost_get("test_sys_argv")
+
+        if (rsp != "['mod_python']"):
+            self.fail(`rsp`)
+
+register(SysArgvTest)
+
+
+class PythonoptionTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_PythonOption"
+    handler = "tests::PythonOption_items"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """PythonoptionTest: PythonOption"""
+
+        print "\n  * Testing PythonOption"
+
+        rsp = self.vhost_get("test_PythonOption")
+
+        if (rsp != "[('PythonOptionTest', 'sample_value')]"):
+            self.fail(`rsp`)
+
+register(PythonoptionTest)
+
+
+class PythonoptionOverrideTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_PythonOption_override"
+    handler = "tests::PythonOption_items"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption('PythonOptionTest "new_value"'),
+                                  PythonOption('PythonOptionTest2 "new_value2"'),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """PythonoptionOverrideTest: PythonOption_override"""
+
+        print "\n  * Testing PythonOption override"
+
+        rsp = self.vhost_get("test_PythonOption_override")
+
+        if (rsp != "[('PythonOptionTest', 'new_value'), ('PythonOptionTest2', 'new_value2')]"):
+            self.fail(`rsp`)
+
+register(PythonoptionOverrideTest)
+
+
+class PythonoptionRemoveTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_PythonOption_remove"
+    handler = "tests::PythonOption_items"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption('PythonOptionTest ""'),
+                                  PythonOption('PythonOptionTest2 "new_value2"'),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """PythonoptionRemoveTest: PythonOption_remove"""
+
+        print "\n  * Testing PythonOption remove"
+
+        rsp = self.vhost_get("test_PythonOption_remove")
+
+        if (rsp != "[('PythonOptionTest2', 'new_value2')]"):
+            self.fail(`rsp`)
+
+register(PythonoptionRemoveTest)
+
+
+class PythonoptionRemove2Test(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_PythonOption_remove2"
+    handler = "tests::PythonOption_items"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption('PythonOptionTest'),
+                                  PythonOption('PythonOptionTest2 "new_value2"'),
+                                  PythonOption('PythonOptionTest3 new_value3'),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """PythonoptionRemove2Test: PythonOption_remove2"""
+
+        print "\n  * Testing PythonOption remove2"
+
+        rsp = self.vhost_get("test_PythonOption_remove2")
+
+        if (rsp != "[('PythonOptionTest2', 'new_value2'), ('PythonOptionTest3', 'new_value3')]"):
+            self.fail(`rsp`)
+
+register(PythonoptionRemove2Test)
+
+
+class InterpreterPerDirectiveTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_interpreter_per_directive"
+    handler = "tests::interpreter"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  PythonInterpPerDirective('On'),
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+
+    def runTest(self):
+        """InterpreterPerDirectiveTest: interpreter_per_directive"""
+
+        print "\n  * Testing interpreter per directive"
+
+        interpreter_name = (self.document_root.replace('\\', '/')+'/').upper()
+
+        rsp = self.vhost_get("test_interpreter_per_directive").upper()
+        if (rsp != interpreter_name):
+            self.fail(`rsp`)
+
+        rsp = self.vhost_get("test_interpreter_per_directive", '/subdir/foo.py').upper()
+        if (rsp != interpreter_name):
+            self.fail(`rsp`)
+
+        rsp = self.vhost_get("test_interpreter_per_directive", '/subdir/').upper()
+        if (rsp != interpreter_name):
+            self.fail(`rsp`)
+
+register(InterpreterPerDirectiveTest)
+
+
+class InterpreterPerDirectoryTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_interpreter_per_directory"
+    handler = "tests::interpreter"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  PythonInterpPerDirectory('On'),
+                                  SetHandler("mod_python"),
+                                  PythonFixupHandler("tests::interpreter"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")),
+                        )
+
+
+
+    def runTest(self):
+        """InterpreterPerDirectoryTest: interpreter_per_directory"""
+
+        print "\n  * Testing interpreter per directory"
+
+        interpreter_name = (self.document_root.replace('\\', '/')+'/').upper()
+
+        rsp = self.vhost_get("test_interpreter_per_directory").upper()
+        if (rsp != interpreter_name):
+            self.fail(`rsp`)
+
+        rsp = self.vhost_get("test_interpreter_per_directory", '/subdir/foo.py').upper()
+        if (rsp != interpreter_name+'SUBDIR/'):
+            self.fail(`rsp`)
+
+        rsp = self.vhost_get("test_interpreter_per_directory", '/subdir/').upper()
+        if (rsp != interpreter_name+'SUBDIR/'):
+            self.fail(`rsp`)
+
+        rsp = self.vhost_get("test_interpreter_per_directory", '/subdir').upper()
+        if (rsp != interpreter_name+'SUBDIR/'):
+            self.fail(`rsp`)
+
+register(InterpreterPerDirectoryTest)
+
+
+class UtilFieldstorageTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_util_fieldstorage"
+    handler = "tests::util_fieldstorage"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """UtilFieldstorageTest: util_fieldstorage"""
+
+        print "\n  * Testing util_fieldstorage()"
+
+        params = urllib.urlencode([('spam', 1), ('spam', 2), ('eggs', 3), ('bacon', 4)])
+        headers = {"Host": "test_util_fieldstorage",
+                   "Content-type": "application/x-www-form-urlencoded",
+                   "Accept": "text/plain"}
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.request("POST", "/tests.py", params, headers)
+        response = conn.getresponse()
+        rsp = response.read()
+        conn.close()
+
+        if (rsp != "[Field('spam', '1'), Field('spam', '2'), Field('eggs', '3'), Field('bacon', '4')]"):
+            self.fail(`rsp`)
+
+register(UtilFieldstorageTest)
+
+
+class PostreadrequestTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_postreadrequest"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        SetHandler("mod_python"),
+                        PythonPath("[r'%s']+sys.path" % self.document_root),
+                        PythonPostReadRequestHandler("tests::postreadrequest"),
+                        PythonDebug("On"))
+
+
+    def runTest(self):
+        """PostreadrequestTest: postreadrequest"""
+
+        print "\n  * Testing PostReadRequestHandler"
+        rsp = self.vhost_get("test_postreadrequest")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+            
+register(PostreadrequestTest)
+
+
+class TransTest(PerRequestTestBase):
+    """See MODPYTHON-171 
+    Assignment to req.filename and POSIX style pathnames
+
+    The code change and this test were reverted in r451850.
+    This test should be removed.
+    """ 
+
+    server_name = "test_trans"
+    disable = True
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        SetHandler("mod_python"),
+                        PythonPath("[r'%s']+sys.path" % self.document_root),
+                        PythonTransHandler("tests::trans"),
+                        PythonDebug("On"))
+
+
+    def runTest(self):
+        """TransTest: trans"""
+
+        print "\n  * Testing TransHandler"
+        rsp = self.vhost_get("test_trans")
+
+        if (rsp[0:2] != " #"): # first line in tests.py
+            self.fail(`rsp`)
+            
+register(TransTest)
+
+
+class ImportTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_import"
+    handler = "tests::import_test"
+    
+    def config(self):
+
+        # configure apache to import it at startup
+        return Container(PythonPath("[r'%s']+sys.path" % self.document_root),
+                      PythonImport("dummymodule test_import"),
+                      PythonImport("dummymodule::function test_import"),
+                      VirtualHost("*",
+                                  ServerName(self.server_name),
+                                  DocumentRoot(self.document_root),
+                                  Directory(self.document_root,
+                                            SetHandler("mod_python"),
+                                            PythonHandler(self.handler),
+                                            PythonDebug("On"))))
+
+
+    def runTest(self):
+        """ImportTest: import"""
+
+        print "\n  * Testing PythonImport"
+        rsp = self.vhost_get("test_import")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(ImportTest)
+
+
+class ConnectionhandlerTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    
+    def config(self):
+
+        try: 
+            localip = socket.gethostbyname("localhost") 
+        except: 
+            localip = "127.0.0.1"
+
+        self.conport = findUnusedPort()
+        return str(Listen("%d" % self.conport)) + \
+            str(VirtualHost("%s:%d" % (localip, self.conport),
+                            SetHandler("mod_python"),
+                            PythonPath("[r'%s']+sys.path" % self.document_root),
+                            PythonConnectionHandler("tests::connectionhandler")))
+
+    def runTest(self):
+        """ConnectionhandlerTest: connectionhandler"""
+
+        print "\n  * Testing PythonConnectionHandler"
+
+        url = "http://127.0.0.1:%s/tests.py" % self.conport
+        f = urllib.urlopen(url)
+        rsp = f.read()
+        f.close()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(ConnectionhandlerTest)
+
+
+class InternalTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_internal"
+    handler = "internal"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        ServerAdmin("serveradmin@somewhere.com"),
+                        ErrorLog("logs/error_log"),
+                        ServerPath("some/path"),
+                        DocumentRoot(self.document_root + '/core'),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption("testing 123"),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """InternalTest: internal"""
+
+        print "\n  * Testing internally (status messages go to error_log)"
+
+        rsp = self.vhost_get("test_internal")
+        if (rsp[-7:] != "test ok"):
+            self.fail("Some tests failed, see error_log")
+
+#register(InternalTest)
+
+
+class PipeExtTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_pipe_ext"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler("mod_python.publisher | .py"),
+                                  PythonHandler("tests::simplehandler"),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """PipeExtTest: | .ext syntax"""
+
+        print "\n  * Testing %s" % self.runTest.__doc__
+
+        rsp = self.vhost_get("test_pipe_ext", path="/tests.py/pipe_ext")
+        if (rsp[-8:] != "pipe ext"):
+            self.fail("Expected: 'pipe ext'; got:" + `rsp`)
+
+        rsp = self.vhost_get("test_pipe_ext", path="/tests/anything")
+        if (rsp[-7:] != "test ok"):
+            self.fail("Expected: 'test ok'; got:" + `rsp`)
+        
+register(PipeExtTest)
+
+
+class CgihandlerTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_cgihandler"
+    handler = "mod_python.cgihandler"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """CgihandlerTest: cgihandler"""
+
+        print "\n  * Testing mod_python.cgihandler"
+
+        rsp = self.vhost_get("test_cgihandler", path="/cgitest.py")
+
+        if (rsp[-8:] != "test ok\n"):
+            self.fail(`rsp`)
+
+register(CgihandlerTest)
+
+
+class PsphandlerTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_psphandler"
+    handler = "mod_python.psp"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """PsphandlerTest: psphandler"""
+
+        print "\n  * Testing mod_python.psp"
+
+        rsp = self.vhost_get("test_psphandler", path="/psptest.psp")
+        if (rsp[-8:] != "test ok\n"):
+            self.fail(`rsp`)
+
+register(PsphandlerTest)
+
+
+class PspParserTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_psp_parser"
+    handler = "mod_python.psp"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """PspParserTest: psp_parser"""
+
+        print "\n  * Testing mod_python.psp parser"
+                # lines in psp_parser.psp should look like:
+        #   test:<char>:<test_string>$
+        #
+        # For example:
+        #   test:n:\n$
+        #   test:t:\t$
+        
+        rsp = self.vhost_get("test_psp_parser", path="/psp_parser.psp")
+        lines = [ line.strip() for line in rsp.split('$') if line ]
+        failures = []
+        for line in lines:
+            parts =  line.split(':', 2)
+            if len(parts) < 3:
+                continue
+
+            t, test_case, test_string = parts[0:3]
+            if not t.strip().startswith('test'):
+                continue
+            expected_result = test_case
+            # do the substitutions in expected_result
+            for ss, rs in [('-', '\\'),('CR', '\r'), ('LF', '\n'), ('TB', '\t')]:
+                expected_result = expected_result.replace(ss, rs)
+            
+            if expected_result != test_string:
+                print '       FAIL',  
+                failures.append(test_case)
+            else:
+                print '       PASS', 
+            print 'expect{%s} got{%s}' % (expected_result, test_string)
+
+        if failures:
+            msg = 'psp_parser parse errors for: %s' % (', '.join(failures))
+            self.fail(msg)
+
+register(PspParserTest)
+
+
+class PspErrorTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_psp_error"
+    handler = "mod_python.psp"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonOption('session_directory "%s"' % self.httpd.tmp_dir),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """PspErrorTest: psp_error"""
+
+        print "\n  * Testing mod_python.psp error page"
+
+        rsp = self.vhost_get("test_psp_error", path="/psptest_main.psp")
+        if (rsp.strip().split() != ["okay","fail"]):
+            self.fail(`rsp`)
+
+    def tearDown(self):
+        super(PerRequestTestBase, self).tearDown()
+        try:
+            os.remove(os.path.join(self.httpd.tmp_dir, 'mp_sess.dbm'))
+        except:
+            pass
+
+register(PspErrorTest)
+
+
+class CookieCookieTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_Cookie_Cookie"
+    handler = "tests::Cookie_Cookie"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """CookieCookieTest: Cookie_Cookie"""
+
+        print "\n  * Testing Cookie.Cookie"
+
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/testz.py", skip_host=1)
+        # this is three cookies, nastily formatted
+        conn.putheader("Host", "test_Cookie_Cookie:%s" % self.httpd.port)
+        conn.putheader("Cookie", "spam=foo; path=blah;;eggs=bar;")
+        conn.putheader("Cookie", "bar=foo")
+        conn.endheaders()
+        response = conn.getresponse()
+        setcookie = response.getheader("set-cookie", None)
+        rsp = response.read()
+        conn.close()
+
+        if rsp != "test ok" or setcookie != 'path=blah, eggs=bar, bar=foo, spam=foo':
+            print `rsp`
+            print `setcookie`
+            self.fail("cookie parsing failed")
+
+register(CookieCookieTest)
+
+
+class CookieMarshalcookieTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_Cookie_MarshalCookie"
+    handler = "tests::Cookie_Cookie"
+    
+    def config(self):
+
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """CookieMarshalcookieTest: Cookie_MarshalCookie"""
+
+        print "\n  * Testing Cookie.MarshalCookie"
+
+        mc = "eggs=d049b2b61adb6a1d895646719a3dc30bcwQAAABzcGFt"
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/testz.py", skip_host=1)
+        conn.putheader("Host", "test_Cookie_MarshalCookie:%s" % self.httpd.port)
+        conn.putheader("Cookie", mc)
+        conn.endheaders()
+        response = conn.getresponse()
+        setcookie = response.getheader("set-cookie", None)
+        rsp = response.read()
+        conn.close()
+
+        if rsp != "test ok" or setcookie != mc:
+            print `rsp`
+            self.fail("marshalled cookie parsing failed")
+
+        # and now a long MarshalledCookie test !
+
+        mc = ('test=859690207856ec75fc641a7566894e40c1QAAAB0'
+             'aGlzIGlzIGEgdmVyeSBsb25nIHZhbHVlLCBsb25nIGxvb'
+             'mcgbG9uZyBsb25nIGxvbmcgc28gbG9uZyBidXQgd2UnbG'
+             'wgZmluaXNoIGl0IHNvb24=')
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/testz.py", skip_host=1)
+        conn.putheader("Host", "test_Cookie_MarshalCookie:%s" % self.httpd.port)
+        conn.putheader("Cookie", mc)
+        conn.endheaders()
+        response = conn.getresponse()
+        setcookie = response.getheader("set-cookie", None)
+        rsp = response.read()
+        conn.close()
+
+        if rsp != "test ok" or setcookie != mc:
+            print `rsp`
+            self.fail("long marshalled cookie parsing failed")
+
+register(CookieMarshalcookieTest)
+
+
+class FilesDirectiveTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_files_directive"
+    handler = "tests::files_directive"
+    
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  Files("*.py",
+                                        SetHandler("mod_python"),
+                                        PythonHandler(self.handler),
+                                        PythonDebug("On"))))
+
+
+    def runTest(self):
+        """FilesDirectiveTest: files_directive"""
+
+        directory = (self.document_root.replace('\\', '/')+'/').upper()
+
+        print "\n  * Testing Files directive"
+        rsp = self.vhost_get("test_files_directive", path="/tests.py").upper()
+
+        if rsp != directory:
+            self.fail(`rsp`)
+
+register(FilesDirectiveTest)
+
+
+class NoneHandlerTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_none_handler"
+    handler = "tests::none_handler"
+    
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """NoneHandlerTest: none_handler"""
+
+        print "\n  * Testing None handler"
+
+        conn = httplib.HTTPConnection("127.0.0.1:%s" % self.httpd.port)
+        conn.putrequest("GET", "/tests.py", skip_host=1)
+        conn.putheader("Host", "test_none_handler:%s" % self.httpd.port)
+        conn.endheaders()
+        response = conn.getresponse()
+        status = response.status
+        rsp = response.read()
+        conn.close()
+        if status != 500:
+            print status, rsp
+            self.fail("none handler should generate error")
+
+register(NoneHandlerTest)
+
+
+class ServerReturnTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_server_return"
+    handler = "tests::server_return_2"
+    
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """ServerReturnTest: server_return"""
+
+        print "\n  * Testing SERVER_RETURN"
+        rsp = self.vhost_get("test_server_return")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(ServerReturnTest)
+
+
+class PhaseStatusTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_phase_status"
+    handler = "tests::phase_status_8"
+    
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  SetHandler("mod_python"),
+                                  AuthType("bogus"),
+                                  AuthName("bogus"),
+                                  Require("valid-user"),
+                                  PythonAuthenHandler("tests::phase_status_1"),
+                                  PythonAuthenHandler("tests::phase_status_2"),
+                                  PythonAuthenHandler("tests::phase_status_3"),
+                                  PythonAuthzHandler("tests::phase_status_4"),
+                                  PythonFixupHandler("tests::phase_status_5"),
+                                  PythonFixupHandler("tests::phase_status_6"),
+                                  PythonFixupHandler("tests::phase_status_7"),
+                                  PythonHandler(self.handler),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """PhaseStatusTest: phase_status"""
+
+        print "\n  * Testing phase status"
+        rsp = self.vhost_get("test_phase_status")
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+register(PhaseStatusTest)
+
+
+class ServerSideIncludeTest(PerRequestTestBase):
+    """DOCSTRING"""
+
+    server_name = "test_server_side_include"
+    
+    def config(self):
+        return VirtualHost("*",
+                        ServerName(self.server_name),
+                        DocumentRoot(self.document_root),
+                        Directory(self.document_root,
+                                  Options("+Includes"),
+                                  AddType("text/html .shtml"),
+                                  AddOutputFilter("INCLUDES .shtml"),
+                                  PythonFixupHandler("tests::server_side_include"),
+                                  PythonDebug("On")))
+
+
+    def runTest(self):
+        """ServerSideIncludeTest: server_side_include"""
+
+        print "\n  * Testing server side include"
+        rsp = self.vhost_get("test_server_side_include", path="/ssi.shtml")
+
+        rsp = rsp.strip()
+
+        if (rsp != "test ok"):
+            self.fail(`rsp`)
+
+
+register(ServerSideIncludeTest)
+

Added: httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/zzz.py
URL: http://svn.apache.org/viewvc/httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/zzz.py?view=auto&rev=463963
==============================================================================
--- httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/zzz.py (added)
+++ httpd/mod_python/branches/jgallacher/tools/test-ng/mptest/core/zzz.py Sat Oct 14 08:45:35 2006
@@ -0,0 +1,43 @@
+"""This module contains tests which should be run after all other tests.
+Typically this might be done to examine the error log for evidence
+of error conditions such as segmentation faults.
+
+We want these tests to run after all other tests, hence the name zzz.py
+
+"""
+
+import os
+
+from mptest.httpdconf import *
+from mptest.testconf import * 
+from mptest.testsetup import register, apache_version
+from mptest.util import findUnusedPort
+
+class SegmentationFaultTest(PerRequestTestBase):
+    """Scans the error log and looks for evidence of a segmentation fault.
+    This test does not make an http request, and does not require httpd 
+    to be running."""
+    
+    disable = False # set disable = True to disable this test
+
+    def runTest(self):
+        """SegmentationFaultTest: scan log for 'Segmentation fault'"""
+         #'child pid 2711 exit signal Segmentation fault (11)'
+        
+        error_log = os.path.join(self.httpd.server_root,self.httpd.error_log)
+
+        print "\n  * Testing", self.shortDescription()
+
+
+        f = open(error_log)
+        # for some reason re doesn't like \n, why?
+        import string
+        log = "".join(map(string.strip, f.readlines()))
+        f.close()
+
+        if re.search("Segmentation fault", log):
+            self.fail("'Segmentation fault' found in error_log")    
+
+register(SegmentationFaultTest)
+
+