Commits

Olemis Lang  committed d46c206

TracGViz: Enhanced versions of dummy_request and send_response for Trac=1.0

  • Participants
  • Parent commits f22ee0f
  • Branches providers

Comments (0)

Files changed (2)

File trac-dev/gviz/tracgviz/testing/util.py

 from trac.web.api import Request
 from trac.web.chrome import Chrome
 from trac.web.main import RequestDispatcher
-
+
 from urlparse import urlparse
+from wsgiref.util import setup_testing_defaults
 
 def dummy_request(env, uname=None):
-    environ = {
-                'trac.base_url' : str(env._abs_href()), 
-                'SCRIPT_NAME' : urlparse(str(env._abs_href())).path
-                }
+    environ = {}
+    setup_testing_defaults(environ)
+    environ.update({
+                'REQUEST_METHOD' : 'GET',
+                'SCRIPT_NAME' : urlparse(str(env._abs_href())).path,
+                'trac.base_url' : str(env._abs_href()),
+                })
     req = Request(environ, lambda *args, **kwds: None)
     # Intercept redirection
     req.redirect = lambda *args, **kwds: None
     # Setup user information
     if uname is not None :
-      environ['REMOTE_USER'] = req.authname = uname
-    
+        environ['REMOTE_USER'] = req.authname = uname
+
     rd = RequestDispatcher(env)
     chrome = Chrome(env)
     req.callbacks.update({
         'authname': rd.authenticate,
         'chrome': chrome.prepare_request,
-        'hdf': rd._get_hdf,
+        'hdf': getattr(rd, '_get_hdf', None),
+        'lc_time': rd._get_lc_time,
+        'locale' : getattr(rd, '_get_locale', None),
         'perm': rd._get_perm,
         'session': rd._get_session,
         'tz': rd._get_timezone,

File trac-dev/gviz/tracgviz/util.py

     r"""Send an HTTP response back to the caller.
     """
     req.send_response(status)
-    req.send_header('Content-Type', mimetype)
-    if req._outcharset == 'utf-8':
-      req.send_header('Content-Length', len(response))
+    req.send_header('Content-Type', mimetype + ';charset=utf-8')
+    if isinstance(response, unicode):
+      response = response.encode('utf-8')
+    req.send_header('Content-Length', len(response))
     for k, v in dict(extra_headers).iteritems():
         req.send_header(k, v)
     req.end_headers()