Skip to content

Commit adb3c3b

Browse files
committed
stdlib
1 parent eda4db5 commit adb3c3b

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

tests/integrations/requests/test_requests.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ def test_crumb_capture(sentry_init, capture_events):
4545
(500, "error"),
4646
],
4747
)
48-
def test_crumb_capture_warning(sentry_init, capture_events, status_code, level):
48+
def test_crumb_capture_client_error(sentry_init, capture_events, status_code, level):
4949
sentry_init(integrations=[StdlibIntegration()])
5050

5151
events = capture_events()

tests/integrations/stdlib/test_httplib.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,48 @@ def test_crumb_capture(sentry_init, capture_events):
4242
)
4343

4444

45+
@pytest.mark.parametrize(
46+
"status_code,level",
47+
[
48+
(200, None),
49+
(301, None),
50+
(403, "warning"),
51+
(405, "warning"),
52+
(500, "error"),
53+
],
54+
)
55+
def test_crumb_capture_client_error(sentry_init, capture_events, status_code, level):
56+
sentry_init(integrations=[StdlibIntegration()])
57+
events = capture_events()
58+
59+
url = f"http://localhost:{PORT}/status/{status_code}" # noqa:E231
60+
urlopen(url)
61+
62+
capture_message("Testing!")
63+
64+
(event,) = events
65+
(crumb,) = event["breadcrumbs"]["values"]
66+
67+
assert crumb["type"] == "http"
68+
assert crumb["category"] == "httplib"
69+
70+
if level is None:
71+
assert "level" not in crumb
72+
else:
73+
assert crumb["level"] == level
74+
75+
assert crumb["data"] == ApproxDict(
76+
{
77+
"url": url,
78+
SPANDATA.HTTP_METHOD: "GET",
79+
SPANDATA.HTTP_STATUS_CODE: status_code,
80+
"reason": "OK",
81+
SPANDATA.HTTP_FRAGMENT: "",
82+
SPANDATA.HTTP_QUERY: "",
83+
}
84+
)
85+
86+
4587
def test_crumb_capture_hint(sentry_init, capture_events):
4688
def before_breadcrumb(crumb, hint):
4789
crumb["data"]["extra"] = "foo"

0 commit comments

Comments
 (0)