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/01/12 00:56:59 UTC

svn commit: r368173 - in /httpd/mod_python/trunk/test: htdocs/tests.py test.py

Author: jgallacher
Date: Wed Jan 11 15:56:53 2006
New Revision: 368173

URL: http://svn.apache.org/viewcvs?rev=368173&view=rev
Log:
Added unit tests for several different uses of req.add_handler.
Ref MODPYTHON-98

Modified:
    httpd/mod_python/trunk/test/htdocs/tests.py
    httpd/mod_python/trunk/test/test.py

Modified: httpd/mod_python/trunk/test/htdocs/tests.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/htdocs/tests.py?rev=368173&r1=368172&r2=368173&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/htdocs/tests.py (original)
+++ httpd/mod_python/trunk/test/htdocs/tests.py Wed Jan 11 15:56:53 2006
@@ -594,6 +594,36 @@
         
     return apache.OK
 
+def req_add_bad_handler(req):
+    # bad_handler does not exist so adding it should 
+    # should raise an AttributeError exception
+    
+    req.log_error("req_add_bad_handler")
+    req.add_handler("PythonHandler", "tests::bad_handler")
+    req.write("test ok")
+
+    return apache.OK
+
+def req_add_empty_handler_string(req):
+    # Adding an empty string as a handler should should 
+    # should raise an exception
+    
+    req.log_error("req_add_empty_handler_string")
+    req.add_handler("PythonHandler", "")
+    req.write("check error_log")
+
+    return apache.OK
+
+def accesshandler_add_handler_to_empty_hl(req):
+    # Prior to version 3.2.6, adding a python handler 
+    # to and empty handler list would cause a segfault
+ 
+    req.secret_message = "foo"
+    req.log_error("accesshandler_add_handler_to_empty_hl")
+    req.add_handler("PythonHandler", "tests::simple_handler")
+
+    return apache.OK
+
 def req_allow_methods(req):
 
     req.allow_methods(["PYTHONIZE"])

Modified: httpd/mod_python/trunk/test/test.py
URL: http://svn.apache.org/viewcvs/httpd/mod_python/trunk/test/test.py?rev=368173&r1=368172&r2=368173&view=diff
==============================================================================
--- httpd/mod_python/trunk/test/test.py (original)
+++ httpd/mod_python/trunk/test/test.py Wed Jan 11 15:56:53 2006
@@ -467,6 +467,81 @@
         if (rsp != "test ok"):
             self.fail(`rsp`)
 
+    def test_req_add_bad_handler_conf(self):
+
+        c = VirtualHost("*",
+                        ServerName("test_req_add_bad_handler"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        Directory(DOCUMENT_ROOT,
+                                  SetHandler("mod_python"),
+                                  PythonHandler("tests::req_add_bad_handler"),
+                                  PythonDebug("On")))
+        return str(c)
+
+    def test_req_add_bad_handler(self):
+        # adding a non-existent handler with req.add_handler should raise
+        # an exception.
+
+        print """\n  * Testing req.add_handler("PythonHandler", "bad_handler")"""
+        rsp = self.vhost_get("test_req_add_bad_handler")
+
+        # look for evidence of the exception in the error log 
+        time.sleep(1)
+        f = open(os.path.join(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""")
+
+    def test_req_add_empty_handler_string_conf(self):
+
+        c = VirtualHost("*",
+                        ServerName("test_req_add_empty_handler_string"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        Directory(DOCUMENT_ROOT,
+                                  SetHandler("mod_python"),
+                                  PythonHandler("tests::req_add_empty_handler_string"),
+                                  PythonDebug("On")))
+        return str(c)
+
+    def test_req_add_empty_handler_string(self):
+        # 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")
+
+        # look for evidence of the exception in the error log 
+        time.sleep(1)
+        f = open(os.path.join(SERVER_ROOT, "logs/error_log"))
+        log = f.read()
+        f.close()
+        if log.find("contains no 'handler'") == -1:
+            self.fail("""Could not find "contains no 'handler'" in error_log""")
+
+    def test_accesshandler_add_handler_to_empty_hl_conf(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("tests::req_add_empty_handler_string"),
+        c = VirtualHost("*",
+                        ServerName("test_accesshandler_add_handler_to_empty_hl"),
+                        DocumentRoot(DOCUMENT_ROOT),
+                        Directory(DOCUMENT_ROOT,
+                                  SetHandler("mod_python"),
+                                  PythonAccessHandler("tests::accesshandler_add_handler_to_empty_hl"),
+                                  PythonDebug("On")))
+        return str(c)
+
+    def test_accesshandler_add_handler_to_empty_hl(self):
+
+        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`)
+
     def test_req_allow_methods_conf(self):
 
         c = VirtualHost("*",
@@ -1803,6 +1878,9 @@
         perRequestSuite = unittest.TestSuite()
         perRequestSuite.addTest(PerRequestTestCase("test_req_document_root"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_add_handler"))
+        perRequestSuite.addTest(PerRequestTestCase("test_req_add_bad_handler"))
+        perRequestSuite.addTest(PerRequestTestCase("test_req_add_empty_handler_string"))
+        perRequestSuite.addTest(PerRequestTestCase("test_accesshandler_add_handler_to_empty_hl"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_allow_methods"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_get_basic_auth_pw"))
         perRequestSuite.addTest(PerRequestTestCase("test_req_requires"))