← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~lifeless/python-oops-wsgi/timeline into lp:python-oops-wsgi

 

Robert Collins has proposed merging lp:~lifeless/python-oops-wsgi/timeline into lp:python-oops-wsgi.

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~lifeless/python-oops-wsgi/timeline/+merge/75960

Integrate with timeline/oops-timeline by snarfing the well known wsgi location for a Timeline and providing it to oops.Config.create()
-- 
https://code.launchpad.net/~lifeless/python-oops-wsgi/timeline/+merge/75960
Your team Launchpad code reviewers is requested to review the proposed merge of lp:~lifeless/python-oops-wsgi/timeline into lp:python-oops-wsgi.
=== modified file 'oops_wsgi/__init__.py'
--- oops_wsgi/__init__.py	2011-08-24 03:45:02 +0000
+++ oops_wsgi/__init__.py	2011-09-19 06:54:40 +0000
@@ -88,6 +88,10 @@
 The `oops.context` variable is a dict used for generating the report - keys and
 values added to that can be used in the `config.on_create` hooks to populate
 custom data without needing to resort to global variables.
+
+If a timeline is present in the WSGI environ (as 'timeline.timeline') it is
+automatically captured to the oops context when generating an OOPS. See the
+oops-timeline module for hooks to use this.
 """
 
 
@@ -102,7 +106,7 @@
 # established at this point, and setup.py will use a version of next-$(revno).
 # If the releaselevel is 'final', then the tarball will be major.minor.micro.
 # Otherwise it is major.minor.micro~$(revno).
-__version__ = (0, 0, 3, 'beta', 0)
+__version__ = (0, 0, 4, 'beta', 0)
 
 __all__ = [
     'install_hooks',

=== modified file 'oops_wsgi/middleware.py'
--- oops_wsgi/middleware.py	2011-08-24 03:45:02 +0000
+++ oops_wsgi/middleware.py	2011-09-19 06:54:40 +0000
@@ -87,6 +87,8 @@
         def make_context(exc_info=None):
             context = dict(url=construct_url(environ), wsgi_environ=environ)
             context.update(environ.get('oops.context', {}))
+            if 'timeline.timeline' in environ:
+                context['timeline'] = environ['timeline.timeline']
             if exc_info is not None:
                 context['exc_info'] = exc_info
             return context

=== modified file 'oops_wsgi/tests/test_middleware.py'
--- oops_wsgi/tests/test_middleware.py	2011-08-24 03:45:02 +0000
+++ oops_wsgi/tests/test_middleware.py	2011-09-19 06:54:40 +0000
@@ -43,7 +43,7 @@
 class MatchesOOPS:
     """Matches an OOPS checking some keys and ignoring the rest."""
 
-    def __init__(self, checkkeys):
+    def __init__(self, checkkeys=None):
         """Create a MatchesOOPS.
 
         :param checkkeys: A dict describing the keys to check. For each key in
@@ -54,7 +54,7 @@
         will check the id is 2, that req_vars is equivalent to [("foo", "bar")]
         and will ignore all other keys in the report.
         """
-        self.checkkeys = checkkeys
+        self.checkkeys = checkkeys or {}
 
     def match(self, report):
         sentinel = object()
@@ -98,11 +98,14 @@
         return environ
 
     def wrap_and_run(self, inner, config, failing_write=False,
-            failing_start=False, failing_server_write=False, params=None):
+            failing_start=False, failing_server_write=False, params=None,
+            environ_extra=None):
         if not params:
             params = {}
         app = make_app(inner, config, **params)
         environ = self.make_outer_environ()
+        if environ_extra:
+            environ.update(environ_extra)
         def start_response(status, headers, exc_info=None):
             if exc_info:
                 # If an exception is raised after we have written (via the app
@@ -349,6 +352,17 @@
                 ValueError, ('boom, yo',))),
             ]))
 
+    def test_timeline_dot_timeline_in_context(self):
+        # If the environ has a timeline.timeline when raising, it is copied to
+        # the context - this permits the oops-timeline hooks to find it.
+        def inner(environ, start_response):
+            raise ValueError('boom, yo')
+        config = self.config_for_oopsing(capture_create=True)
+        timeline = object()
+        self.wrap_and_run(
+            inner, config, environ_extra={'timeline.timeline': timeline})
+        self.assertEqual(timeline, self.calls[0]['timeline'])
+
     def test_error_in_app_context_sets_oops_context(self):
         # When the app blows up we attach the environment and the oops.context
         # wsgi variable injects straight into the context.

=== modified file 'setup.py'
--- setup.py	2011-08-23 23:52:12 +0000
+++ setup.py	2011-09-19 06:54:40 +0000
@@ -23,7 +23,7 @@
         os.path.join(os.path.dirname(__file__), 'README'), 'rb').read()
 
 setup(name="oops_wsgi",
-      version="0.0.3",
+      version="0.0.4",
       description=\
               "OOPS wsgi middleware.",
       long_description=description,


Follow ups