Robert Brewer avatar Robert Brewer committed 508b050

New test for u0 gateway

Comments (0)

Files changed (3)

cheroot/test/helper.py

 
         # Override the server error_log method so we can test writes to it.
         def logsink(msg="", level=20, traceback=False):
+            if traceback:
+                traceback = format_exc()
             cls.log.append((msg, level, traceback))
         cls.log = []
         cls.httpserver.error_log = logsink

cheroot/test/test_wsgi.py

 class WSGITests(helper.CherootWebCase):
 
     def setup_server(cls):
+
+        def hello(environ, start_response):
+            status = '200 OK'
+            response_headers = [('Content-type', 'text/plain'),
+                                ('Content-Length', '11')]
+            start_response(status, response_headers)
+            return [ntob('Hello world')]
+
         def foo(environ, start_response):
             status = '200 OK'
             response_headers = [('Content-type', 'text/plain')]
             '/bar': bar,
             '/baz': baz,
             '/qoph': qoph,
+            '/hello': hello,
             })
     setup_server = classmethod(setup_server)
 
         self.assertInLog(
             "WSGI response header value %s is not of type str." % repr(5))
 
+    def test_notfound(self):
+        self.getPage("/tev")
+        self.assertStatus(404)
+
+    def test_gateway_u0(self):
+        old_gw = self.httpserver.gateway
+        self.httpserver.gateway = wsgi.WSGIGateway_u0
+        try:
+            self.getPage("/hello")
+            self.assertStatus(200)
+        finally:
+            self.httpserver.gateway = old_gw
+
         try:
             if py3k:
                 for key in ["PATH_INFO", "SCRIPT_NAME", "QUERY_STRING"]:
-                    env[key] = env_10[key].decode(env['wsgi.url_encoding'])
+                    # Re-encode since our "decoded" string is just
+                    # bytes masquerading as unicode via Latin-1
+                    val = env_10[key].encode('ISO-8859-1')
+                    # ...now decode according to the configured encoding
+                    env[key] = val.decode(env['wsgi.url_encoding'])
             else:
                 # SCRIPT_NAME is the empty string, who cares what encoding it is?
                 env["PATH_INFO"] = req.path.decode(env['wsgi.url_encoding'])
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.