Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test fix #582

Draft
wants to merge 5 commits into
base: v1.5.x
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion baseplate/frameworks/pyramid/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import logging
import sys

from itertools import chain
from typing import Any
from typing import Callable
from typing import Dict
Expand Down Expand Up @@ -81,9 +82,22 @@ def baseplate_tween(request: Request) -> Response:
request.trace.finish(exc_info=sys.exc_info())
raise
else:
print("\n\n\n\nhere")
if request.trace:
request.trace.set_tag("http.status_code", response.status_code)
response.app_iter = SpanFinishingAppIterWrapper(request.trace, response.app_iter)
if hasattr(response, "explanation") and response.explanation:
print("\n\n\n\nhere2")
response.app_iter = SpanFinishingAppIterWrapper(
request.trace,
chain(
response.app_iter,
[str.encode(response._status), str.encode(response.explanation)],
),
)
else:
response.app_iter = SpanFinishingAppIterWrapper(
request.trace, response.app_iter
)
finally:
# avoid a reference cycle
request.start_server_span = None
Expand Down
6 changes: 4 additions & 2 deletions tests/integration/pyramid_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from baseplate.frameworks.pyramid import BaseplateConfigurator, ServerSpanInitialized
from pyramid.config import Configurator
from pyramid.httpexceptions import HTTPNotImplemented
except ImportError:
raise unittest.SkipTest("pyramid/webtest is not installed")

Expand Down Expand Up @@ -65,7 +66,7 @@ def make_iter():


def render_exception_view(request):
return
return HTTPNotImplemented(title="a fancy title", explanation="a fancy explanation")


def render_bad_exception_view(request):
Expand Down Expand Up @@ -230,11 +231,12 @@ def test_exception_caught(self):
self.assertIsInstance(captured_exc, TestException)

def test_control_flow_exception_not_caught(self):
self.test_app.get("/example?control_flow_exception")
response = self.test_app.get("/example?control_flow_exception", status=501)

self.assertTrue(self.server_observer.on_start.called)
self.assertTrue(self.server_observer.on_finish.called)
self.assertTrue(self.context_init_event_subscriber.called)
self.assertIn(b"a fancy explanation", response.body)
args, _ = self.server_observer.on_finish.call_args
self.assertEqual(args[0], None)

Expand Down