Robert Brewer avatar Robert Brewer committed 4a6f09a

Merged apache/wsgi test silencers from trunk.

Comments (0)

Files changed (14)

cherrypy/test/modfcgid.py

     """TestHarness for fcgid and CherryPy."""
     
     def _run(self, conf):
+        cherrypy.server.using_wsgi = True
+        cherrypy.server.using_apache = True
         cherrypy.server.httpserver = servers.FlupFCGIServer(
             application=cherrypy.tree, bindAddress=('127.0.0.1', 4000))
         cherrypy.server.httpserver.bind_addr = ('127.0.0.1', 4000)

cherrypy/test/modpy.py

 conf_modpython_gateway = """
 # Apache2 server conf file for testing CherryPy with modpython_gateway.
 
+ServerName 127.0.0.1
 DocumentRoot "/"
 Listen %s
 LoadModule python_module modules/mod_python.so
 conf_cpmodpy = """
 # Apache2 server conf file for testing CherryPy with _cpmodpy.
 
+ServerName 127.0.0.1
 DocumentRoot "/"
 Listen %s
 LoadModule python_module modules/mod_python.so
     use_wsgi = False
     
     def _run(self, conf):
+        import cherrypy
+        cherrypy.server.using_apache = True
+        
         from cherrypy.test import webtest
         webtest.WebCase.PORT = self.port
         webtest.WebCase.harness = self
         print "Running tests:", self.server
         
         if self.use_wsgi:
+            cherrypy.server.using_wsgi = True
             conf_template = conf_modpython_gateway
         else:
+            cherrypy.server.using_wsgi = False
             conf_template = conf_cpmodpy
         
         # mod_python, since it runs in the Apache process, must be

cherrypy/test/modwsgi.py

     use_wsgi = True
     
     def _run(self, conf):
+        cherrypy.server.using_wsgi = True
+        cherrypy.server.using_apache = True
+        
         from cherrypy.test import webtest
         webtest.WebCase.PORT = self.port
         webtest.WebCase.harness = self

cherrypy/test/test.py

         print "PID:", os.getpid()
         print
         
+        # Override these in _run as needed:
+        cherrypy.server.using_wsgi = True
+        cherrypy.server.using_apache = False
+        
         if isinstance(conf, basestring):
             parser = cherrypy.config._Parser()
             conf = parser.dict_from_file(conf).get('global', {})

cherrypy/test/test_caching.py

         self.getPage("/a.gif", [('If-Modified-Since', lm1)])
         self.assertStatus(304)
         self.assertNoHeader("Last-Modified")
-        self.assertHeader("Age")
+        if not getattr(cherrypy.server, "using_apache", False):
+            self.assertHeader("Age")
 
 
 if __name__ == '__main__':

cherrypy/test/test_config.py

         self.getPage("/repr?key=thing1")
         self.assertBody(repr(cherrypy.lib.http.response_codes[404]))
         
-        self.getPage("/repr?key=thing2")
-        from cherrypy.tutorial import thing2
-        self.assertBody(repr(thing2))
+        if not getattr(cherrypy.server, "using_apache", False):
+            # The object ID's won't match up when using Apache, since the
+            # server and client are running in different processes.
+            self.getPage("/repr?key=thing2")
+            from cherrypy.tutorial import thing2
+            self.assertBody(repr(thing2))
         
         self.getPage("/repr?key=complex")
         self.assertBody("(3+2j)")

cherrypy/test/test_core.py

 favicon_path = os.path.join(os.getcwd(), localDir, "../favicon.ico")
 
 defined_http_methods = ("OPTIONS", "GET", "HEAD", "POST", "PUT", "DELETE",
-                        "TRACE", "CONNECT", "PROPFIND")
+                        "TRACE", "PROPFIND")
 
 
 def setup_server():
         
         def index(self):
             m = cherrypy.request.method
-            if m in defined_http_methods:
+            if m in defined_http_methods or m == "CONNECT":
                 return m
             
             if m == "LINK":
         msg = "Illegal response status from server (781 is out of range)."
         self.assertErrorPage(500, msg)
         
-        self.getPage("/status/unknown")
-        self.assertBody('funky')
-        self.assertStatus(431)
+        if not getattr(cherrypy.server, 'using_apache', False):
+            self.getPage("/status/unknown")
+            self.assertBody('funky')
+            self.assertStatus(431)
         
         self.getPage("/status/bad")
         self.assertStatus(500)
             self.getPage("/error/page_yield")
             self.assertErrorPage(500, pattern=valerr)
             
-            if cherrypy.server.protocol_version == "HTTP/1.0":
+            if (cherrypy.server.protocol_version == "HTTP/1.0" or
+                getattr(cherrypy.server, "using_apache", False)):
                 self.getPage("/error/page_streamed")
                 # Because this error is raised after the response body has
                 # started, the status should not change to an error status.
                "IOError: [Errno 2] No such file or directory: 'nonexistent.html'")
         self.assertInBody(msg)
         
-        if (hasattr(self, 'harness') and
-            "modpython" in self.harness.__class__.__name__.lower()):
+        if getattr(cherrypy.server, "using_apache", False):
             pass
         else:
             # Test throw_errors (ticket #186).
                      headers=[("Content-type", "application/json")])
         self.assertBody("application/json")
     
-    def testHTTPMethods(self):
+    def test_basic_HTTPMethods(self):
         helper.webtest.methods_with_bodies = ("POST", "PUT", "PROPFIND")
         
         # Test that all defined HTTP methods work.
         self.assertBody('<h1>Choose your document</h1>\n<ul>\n</ul>')
         self.assertStatus(200)
     
+    def test_CONNECT_method(self):
+        if getattr(cherrypy.server, "using_apache", False):
+            print "skipped due to known Apache differences...",
+            return
+        
+        self.getPage("/method/", method="CONNECT")
+        self.assertBody("CONNECT")
+    
     def testFavicon(self):
         # favicon.ico is served by staticfile.
         icofilename = os.path.join(localDir, "../favicon.ico")
             self.assertHeader('Set-Cookie', 'Last=Piranha;')
     
     def testMaxRequestSize(self):
+        if getattr(cherrypy.server, "using_apache", False):
+            print "skipped due to known Apache differences...",
+            return
+        
         for size in (500, 5000, 50000):
             self.getPage("/", headers=[('From', "x" * 500)])
             self.assertStatus(413)

cherrypy/test/test_encoding.py

         # readable page, since 1) the gzip header is already set,
         # and 2) we may have already written some of the body.
         # The fix is to never stream yields when using gzip.
-        if cherrypy.server.protocol_version == "HTTP/1.0":
+        if (cherrypy.server.protocol_version == "HTTP/1.0" or
+            getattr(cherrypy.server, "using_apache", False)):
             self.getPage('/gzip/noshow_stream',
                          headers=[("Accept-Encoding", "gzip")])
             self.assertHeader('Content-Encoding', 'gzip')

cherrypy/test/test_http.py

                           response_body)
 
     def test_malformed_request_line(self):
+        if getattr(cherrypy.server, "using_apache", False):
+            print "skipped due to known Apache differences...",
+            return
+        
         # Test missing version in Request-Line
         if self.scheme == 'https':
             c = httplib.HTTPSConnection('127.0.0.1:%s' % self.PORT)

cherrypy/test/test_httpauth.py

         
         auth = base_auth % (nonce, response, '00000001')
         self.getPage('/digest/', [('Authorization', auth)])
-        self.assertStatus('401 Unauthorized')
+        self.assertStatus(401)
 
         # Test that must pass
         base_auth = 'Digest username="test", realm="localhost", nonce="%s", uri="/digest/", algorithm=MD5, response="%s", qop=auth, nc=%s, cnonce="1522e61005789929"'

cherrypy/test/test_objectmapping.py

             self.assertStatus('302 Found')
             self.assertHeader('Location', '%s/dir1/' % self.base())
             
-            # Test that we can use URL's which aren't all valid Python identifiers
-            # This should also test the %XX-unquoting of URL's.
-            self.getPage("/Von%20B%fclow?ID=14")
-            self.assertBody("ID is 14")
-            
-            # Test that %2F in the path doesn't get unquoted too early;
-            # that is, it should not be used to separate path components.
-            # See ticket #393.
-            self.getPage("/page%2Fname")
-            self.assertBody("default:('page/name',)")
+            if not getattr(cherrypy.server, "using_apache", False):
+                # Test that we can use URL's which aren't all valid Python identifiers
+                # This should also test the %XX-unquoting of URL's.
+                self.getPage("/Von%20B%fclow?ID=14")
+                self.assertBody("ID is 14")
+                
+                # Test that %2F in the path doesn't get unquoted too early;
+                # that is, it should not be used to separate path components.
+                # See ticket #393.
+                self.getPage("/page%2Fname")
+                self.assertBody("default:('page/name',)")
             
             self.getPage("/dir1/dir2/script_name")
             self.assertBody(url)

cherrypy/test/test_tools.py

         self.assertBody("True")
         
         # If body is "razdrez", then on_end_request is being called too early.
-        if cherrypy.server.protocol_version == "HTTP/1.0":
+        if (cherrypy.server.protocol_version == "HTTP/1.0" or
+            getattr(cherrypy.server, "using_apache", False)):
             self.getPage("/demo/errinstream?id=5")
             # Because this error is raised after the response body has
             # started, the status should not change to an error status.

cherrypy/test/test_wsgi_vhost.py

 class WSGI_VirtualHost_Test(helper.CPWebCase):
     
     def test_welcome(self):
+        if not cherrypy.server.using_wsgi:
+            print "skipped (not using WSGI)...",
+            return
+        
         for year in xrange(1997, 2008):
             self.getPage("/", headers=[('Host', 'www.classof%s.example' % year)])
             self.assertBody("Welcome to the Class of %s website!" % year)

cherrypy/test/test_wsgiapps.py

         self.assertBody("I'm a regular CherryPy page handler!")
     
     def test_04_pure_wsgi(self):
+        import cherrypy
+        if not cherrypy.server.using_wsgi:
+            print "skipped (not using WSGI)...",
+            return
         self.getPage("/hosted/app1")
         self.assertHeader("Content-Type", "text/plain")
         self.assertInBody(self.wsgi_output)
 
     def test_05_wrapped_cp_app(self):
+        import cherrypy
+        if not cherrypy.server.using_wsgi:
+            print "skipped (not using WSGI)...",
+            return
         self.getPage("/hosted/app2/")
         body = list("I'm a regular CherryPy page handler!")
         body.reverse()
         self.assertInBody(body)
 
     def test_06_empty_string_app(self):
+        import cherrypy
+        if not cherrypy.server.using_wsgi:
+            print "skipped (not using WSGI)...",
+            return
         self.getPage("/hosted/app3")
         self.assertHeader("Content-Type", "text/plain")
         self.assertInBody('Hello world')
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.