Skip to content

Commit 05c1844

Browse files
committed
test(pyramid): Add test as requested in getsentry#303
1 parent 1354596 commit 05c1844

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

tests/integrations/pyramid/test_pyramid.py

+37
Original file line numberDiff line numberDiff line change
@@ -327,3 +327,40 @@ def authenticated_userid(self, request):
327327
client.get("/message")
328328

329329
assert len(events) == 1
330+
331+
332+
def tween_factory(handler, registry):
333+
def tween(request):
334+
try:
335+
response = handler(request)
336+
except:
337+
mroute = request.matched_route
338+
if mroute and mroute.name in ("index",):
339+
status_code = 400
340+
return Response(
341+
text=json.dumps(dict()),
342+
status_code=status_code,
343+
content_type="application/json",
344+
)
345+
return response
346+
347+
return tween
348+
349+
350+
def test_tween_ok(sentry_init, pyramid_config, capture_exceptions, route, get_client):
351+
sentry_init(integrations=[PyramidIntegration()])
352+
errors = capture_exceptions()
353+
354+
@route("/")
355+
def index(request):
356+
raise Exception()
357+
358+
pyramid_config.add_tween(
359+
"tests.integrations.pyramid.test_pyramid.tween_factory",
360+
under=pyramid.tweens.INGRESS,
361+
)
362+
363+
client = get_client()
364+
client.get("/")
365+
366+
assert not errors

0 commit comments

Comments
 (0)