This repository was archived by the owner on Jun 28, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_sentry_errors.py
More file actions
79 lines (62 loc) · 2.04 KB
/
test_sentry_errors.py
File metadata and controls
79 lines (62 loc) · 2.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import responses
from seamapi import Seam
@responses.activate
def test_sends_error_to_sentry(seam: Seam, fake_sentry):
rsp = responses.Response(
method="GET",
url=seam.api_url + "/devices/list",
# Missing top-level `devices` key
json={"foo": []},
headers={"seam-request-id": "1234"},
)
responses.add(rsp)
client_with_sentry = Seam(
api_key=seam.api_key,
api_url=seam.api_url,
should_report_exceptions=True,
)
assert fake_sentry["sentry_init_args"]["dsn"] == fake_sentry["sentry_dsn"]
try:
client_with_sentry.devices.list()
assert False
except Exception as error:
pass
assert rsp.call_count == 1
assert len(fake_sentry["sentry_capture_exception_calls"]) == 1
assert type(fake_sentry["sentry_capture_exception_calls"][0][0][0]) is KeyError
assert len(fake_sentry["sentry_add_breadcrumb_calls"]) == 1
assert fake_sentry["sentry_add_breadcrumb_calls"][0][1]['category'] == "http"
assert fake_sentry["sentry_add_breadcrumb_calls"][0][1]["data"]["request_id"] == "1234"
@responses.activate
def test_skips_sentry_reporting(seam: Seam, fake_sentry):
rsp = responses.Response(
method="GET",
url=seam.api_url + "/devices/list",
# Missing top-level `devices` key
json={"foo": []}
)
responses.add(rsp)
client_without_sentry = Seam(
api_key=seam.api_key,
api_url=seam.api_url,
)
try:
client_without_sentry.devices.list()
assert False
except:
pass
assert rsp.call_count == 1
assert len(fake_sentry["sentry_capture_exception_calls"]) == 0
def test_skips_report_for_known_error(seam: Seam, fake_sentry):
client_without_sentry = Seam(
api_key=seam.api_key,
api_url=seam.api_url,
should_report_exceptions=True
)
assert fake_sentry["sentry_init_args"]["dsn"] == fake_sentry["sentry_dsn"]
try:
client_without_sentry.devices.get("123")
assert False
except:
pass
assert len(fake_sentry["sentry_capture_exception_calls"]) == 0