Skip to content

Commit b80c52c

Browse files
committed
fix tests
1 parent 75cd992 commit b80c52c

File tree

3 files changed

+60
-5
lines changed

3 files changed

+60
-5
lines changed

tests/integrations/aiohttp/test_aiohttp.py

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ async def hello(request):
475475

476476
@pytest.mark.asyncio
477477
async def test_crumb_capture(
478-
sentry_init, aiohttp_raw_server, aiohttp_client, loop, capture_events
478+
sentry_init, aiohttp_raw_server, aiohttp_client, capture_events
479479
):
480480
def before_breadcrumb(crumb, hint):
481481
crumb["data"]["extra"] = "foo"
@@ -516,6 +516,60 @@ async def handler(request):
516516
)
517517

518518

519+
@pytest.mark.parametrize(
520+
"status_code,level",
521+
[
522+
(200, None),
523+
(301, None),
524+
(403, "warning"),
525+
(405, "warning"),
526+
(500, "error"),
527+
],
528+
)
529+
@pytest.mark.asyncio
530+
async def test_crumb_capture_client_error(
531+
sentry_init,
532+
aiohttp_raw_server,
533+
aiohttp_client,
534+
capture_events,
535+
status_code,
536+
level,
537+
):
538+
sentry_init(integrations=[AioHttpIntegration()])
539+
540+
async def handler(request):
541+
return web.Response(status=status_code)
542+
543+
raw_server = await aiohttp_raw_server(handler)
544+
545+
with start_transaction():
546+
events = capture_events()
547+
548+
client = await aiohttp_client(raw_server)
549+
resp = await client.get("/")
550+
assert resp.status == status_code
551+
capture_message("Testing!")
552+
553+
(event,) = events
554+
555+
crumb = event["breadcrumbs"]["values"][0]
556+
assert crumb["type"] == "http"
557+
if level is None:
558+
assert "level" not in crumb
559+
else:
560+
assert crumb["level"] == level
561+
assert crumb["category"] == "httplib"
562+
assert crumb["data"] == ApproxDict(
563+
{
564+
"url": "http://127.0.0.1:{}/".format(raw_server.port),
565+
"http.fragment": "",
566+
"http.method": "GET",
567+
"http.query": "",
568+
"http.response.status_code": status_code,
569+
}
570+
)
571+
572+
519573
@pytest.mark.asyncio
520574
async def test_outgoing_trace_headers(sentry_init, aiohttp_raw_server, aiohttp_client):
521575
sentry_init(

tests/integrations/httpx/test_httpx.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,6 @@ def test_crumb_capture_client_error(
111111
SPANDATA.HTTP_FRAGMENT: "",
112112
SPANDATA.HTTP_QUERY: "",
113113
SPANDATA.HTTP_STATUS_CODE: status_code,
114-
"reason": "OK",
115-
"extra": "foo",
116114
}
117115
)
118116

tests/integrations/stdlib/test_httplib.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import random
22
from http.client import HTTPConnection, HTTPSConnection
33
from socket import SocketIO
4+
from urllib.error import HTTPError
45
from urllib.request import urlopen
56
from unittest import mock
67

@@ -57,7 +58,10 @@ def test_crumb_capture_client_error(sentry_init, capture_events, status_code, le
5758
events = capture_events()
5859

5960
url = f"http://localhost:{PORT}/status/{status_code}" # noqa:E231
60-
urlopen(url)
61+
try:
62+
urlopen(url)
63+
except HTTPError:
64+
pass
6165

6266
capture_message("Testing!")
6367

@@ -77,7 +81,6 @@ def test_crumb_capture_client_error(sentry_init, capture_events, status_code, le
7781
"url": url,
7882
SPANDATA.HTTP_METHOD: "GET",
7983
SPANDATA.HTTP_STATUS_CODE: status_code,
80-
"reason": "OK",
8184
SPANDATA.HTTP_FRAGMENT: "",
8285
SPANDATA.HTTP_QUERY: "",
8386
}

0 commit comments

Comments
 (0)