Commits

Robert Brewer committed a85c7fd

mod_python improvements:

1. Fix to test_config.
2. Skipped some additional tests for known bugs.
3. Documented that mod_python doesn't allow chunked encoding in request.

Comments (0)

Files changed (6)

cherrypy/test/modpy.py

 
 1. Apache processes Range headers automatically; CherryPy's truncated
     output is then truncated again by Apache. See test_core.testRanges.
+    This was worked around in http://www.cherrypy.org/changeset/1319.
 2. Apache does not allow custom HTTP methods like CONNECT as per the spec.
     See test_core.testHTTPMethods.
 3. Max request header and body settings do not work with Apache.
 5. Apache does not allow custom error codes as per the spec.
 6. Apache (or perhaps modpython, or modpython_gateway) unquotes %xx in the
     Request-URI too early.
+7. mod_python will not read request bodies which use the "chunked"
+    transfer-coding (it passes REQUEST_CHUNKED_ERROR to ap_setup_client_block
+    instead of REQUEST_CHUNKED_DECHUNK, see Apache2's http_protocol.c and
+    mod_python's requestobject.c).
 """
 
 import os
     def _run(self, conf):
         from cherrypy.test import webtest
         webtest.WebCase.PORT = self.port
+        webtest.WebCase.harness = self
         print
         print "Running tests:", self.server
         

cherrypy/test/test.py

         # and we wouldn't be able to globally override the port anymore.
         from cherrypy.test import helper
         webtest.WebCase.PORT = self.port
+        webtest.WebCase.harness = self
         print
         print "Running tests:", self.server
         helper.run_test_suite(self.tests, self.server, conf)
         
         if self.server == 'cpmodpy':
             from cherrypy.test import modpy
-            m = modpy.ModPythonTestHarness(self.tests, self.server,
+            h = modpy.ModPythonTestHarness(self.tests, self.server,
                                            self.protocol, self.port)
-            m.use_wsgi = False
-            m.run(conf)
+            h.use_wsgi = False
         elif self.server == 'modpygw':
             from cherrypy.test import modpy
-            m = modpy.ModPythonTestHarness(self.tests, self.server,
+            h = modpy.ModPythonTestHarness(self.tests, self.server,
                                            self.protocol, self.port)
-            m.use_wsgi = True
-            m.run(conf)
+            h.use_wsgi = True
         else:
-            TestHarness(self.tests, self.server,
-                        self.protocol, self.port).run(conf)
+            h = TestHarness(self.tests, self.server, self.protocol, self.port)
+        
+        h.run(conf)
         
         if self.profile:
             del conf['profiling.on']

cherrypy/test/test_config.py

         nex = index
         
         def bar(self, key):
-            return cherrypy.request.config.get(key, "None")
+            return `cherrypy.request.config.get(key, None)`
         bar.exposed = True
         bar._cp_config = {'foo': 'this3', 'bax': 'this4'}
     
             ('/foo/',    'foo', 'this2'),
             ('/foo/',    'bar', 'that'),
             ('/foo/',    'bax', 'None'),
-            ('/foo/bar', 'baz', 'that2'),
+            ('/foo/bar', 'baz', "'that2'"),
             ('/foo/nex', 'baz', 'that2'),
             # If 'foo' == 'this', then the mount point '/another' leaks into '/'.
             ('/another/','foo', 'None'),
         for path, key, expected in tests:
             self.getPage(path + "?key=" + key)
             self.assertBody(expected)
-    
-    def testExternalDispatch(self):
-        # 'cherrypy.request' should reference a default instance
-        cherrypy.request.app = cherrypy.tree.apps[""]
-        cherrypy.request.dispatch("/foo/bar")
+        
         expectedconf = {
             # From CP defaults
             'tools.log_headers.on': False,
             'foo': 'this3',
             'bax': 'this4',
             }
-        for k, v in expectedconf.iteritems():
-            self.assertEqual(cherrypy.request.config[k], v)
+        for key, expected in expectedconf.iteritems():
+            self.getPage("/foo/bar?key=" + key)
+            self.assertBody(`expected`)
 
 
 if __name__ == '__main__':

cherrypy/test/test_conn.py

         try:
             httpserver = cherrypy.server.httpservers.keys()[0]
             old_timeout = httpserver.timeout
-        except AttributeError:
+        except (AttributeError, IndexError):
             print "skipped ",
             return
         
             print "skipped ",
             return
         
+        if (hasattr(self, 'harness') and
+            "modpython" in self.harness.__class__.__name__.lower()):
+            # mod_python forbids chunked encoding
+            print "skipped ",
+            return
+        
         self.PROTOCOL = "HTTP/1.1"
         
         # Set our HTTP_CONN to an instance so it persists between requests.

cherrypy/test/test_core.py

                "[Errno 2] No such file or directory: 'nonexistent.html'")
         self.assertInBody(msg)
         
-        # Test throw_errors (ticket #186).
-        self.getPage("/error/rethrow")
-        self.assertInBody("raise ValueError()")
+        # Ugly hack to skip the test if we're using _cpmodpy.
+        if cherrypy.servers.httpservers:
+            # Test throw_errors (ticket #186).
+            self.getPage("/error/rethrow")
+            self.assertInBody("raise ValueError()")
     
     def testRanges(self):
         self.getPage("/ranges/get_ranges?bytes=3-6")

cherrypy/test/test_wsgi_ns.py

 from cherrypy.test import test
 test.prefer_parent_path()
 
+import cherrypy
+
 
 def setup_server():
     
-    import cherrypy
-    
-    
     class ChangeCase(object):
         
         def __init__(self, app, to=None):
 class WSGI_Namespace_Test(helper.CPWebCase):
     
     def test_pipeline(self):
+        if not cherrypy.server.httpservers:
+            print "skipped ",
+            return
+        
         self.getPage("/")
         # If body is "HEXXO WORXD!", the middleware was applied out of order.
         self.assertBody("HERRO WORRD!")
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.