Skip to content

Commit

Permalink
set response status codes for unhandled exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
acer618 committed Oct 6, 2023
1 parent cc4411f commit ad8e85d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from unittest import mock

import pytest
from pyramid.request import Request

from pyramid_zipkin import request_helper
from pyramid.request import Request


@pytest.fixture
Expand All @@ -15,6 +15,7 @@ def dummy_request():
request.path = 'bla'
return request


@pytest.fixture
def get_request():
request = Request.blank('GET /sample')
Expand All @@ -24,6 +25,7 @@ def get_request():
request.unique_request_id = '17133d482ba4f605'
return request


@pytest.fixture
def dummy_response():
response = mock.Mock()
Expand Down
8 changes: 4 additions & 4 deletions tests/tween_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ def test_zipkin_tween_post_handler_hook(
mock_span.return_value.__enter__.return_value,
)


@pytest.mark.parametrize(['set_callback', 'called'], [(False, 0), (True, 1)])
@pytest.mark.parametrize('is_tracing', [True])
def test_zipkin_tween_exception(
Expand All @@ -89,7 +90,7 @@ def test_zipkin_tween_exception(
called,
):
"""
If request processing throws an exception verify response_status_code = 500 is being set
If request processing has an exception set response_status_code to 500
"""

mock_post_handler_hook = mock.Mock()
Expand All @@ -107,8 +108,8 @@ def test_zipkin_tween_exception(

try:
tween.zipkin_tween(handler, dummy_response)(get_request)
pytest.fail('exception was expected to be thrown')
except Exception as e:
pytest.fail('exception was expected to be thrown!')
except:
pass

spans = transport.get_payloads()
Expand Down Expand Up @@ -147,7 +148,6 @@ def test_zipkin_tween_no_exception(
spans = transport.get_payloads()
assert len(spans) == 1
span = json.loads(spans[0])[0]
span = decoded_spans[0]
span['tags']['response_status_code'] = '200'

assert handler.call_count == 1
Expand Down

0 comments on commit ad8e85d

Please sign in to comment.