Skip to content

Commit

Permalink
also test asgi middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
sentrivana committed Oct 3, 2024
1 parent ff7d3b8 commit 935c12e
Showing 1 changed file with 74 additions and 0 deletions.
74 changes: 74 additions & 0 deletions tests/integrations/django/asgi/test_asgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,3 +624,77 @@ async def test_async_view(sentry_init, capture_events, application):
(event,) = events
assert event["type"] == "transaction"
assert event["transaction"] == "/simple_async_view"


@pytest.mark.parametrize("application", APPS)
@pytest.mark.asyncio
async def test_transaction_http_method_default(
sentry_init, capture_events, application
):
"""
By default OPTIONS and HEAD requests do not create a transaction.
"""
sentry_init(
integrations=[
DjangoIntegration(
middleware_spans=False,
signals_spans=False,
)
],
traces_sample_rate=1.0,
)
events = capture_events()

comm = HttpCommunicator(application, "GET", "/simple_async_view")
await comm.get_response()
await comm.wait()

comm = HttpCommunicator(application, "OPTIONS", "/simple_async_view")
await comm.get_response()
await comm.wait()

comm = HttpCommunicator(application, "HEAD", "/simple_async_view")
await comm.get_response()
await comm.wait()

(event,) = events

assert len(events) == 1
assert event["request"]["method"] == "GET"


@pytest.mark.parametrize("application", APPS)
@pytest.mark.asyncio
async def test_transaction_http_method_custom(sentry_init, capture_events, application):
sentry_init(
integrations=[
DjangoIntegration(
http_methods_to_capture=(
"OPTIONS",
"head",
), # capitalization does not matter
middleware_spans=False,
signals_spans=False,
)
],
traces_sample_rate=1.0,
)
events = capture_events()

comm = HttpCommunicator(application, "GET", "/simple_async_view")
await comm.get_response()
await comm.wait()

comm = HttpCommunicator(application, "OPTIONS", "/simple_async_view")
await comm.get_response()
await comm.wait()

comm = HttpCommunicator(application, "HEAD", "/simple_async_view")
await comm.get_response()
await comm.wait()

assert len(events) == 2

(event1, event2) = events
assert event1["request"]["method"] == "OPTIONS"
assert event2["request"]["method"] == "HEAD"

0 comments on commit 935c12e

Please sign in to comment.