forked from getsentry/sentry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_sessions.py
More file actions
34 lines (27 loc) · 902 Bytes
/
test_sessions.py
File metadata and controls
34 lines (27 loc) · 902 Bytes
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
from sentry_sdk import Hub
def test_basic(sentry_init, capture_envelopes):
sentry_init(release="fun-release", environment="not-fun-env")
envelopes = capture_envelopes()
hub = Hub.current
hub.start_session()
try:
with hub.configure_scope() as scope:
scope.set_user({"id": "42"})
raise Exception("all is wrong")
except Exception:
hub.capture_exception()
hub.end_session()
hub.flush()
assert len(envelopes) == 2
assert envelopes[0].get_event() is not None
sess = envelopes[1]
assert len(sess.items) == 1
sess_event = sess.items[0].payload.json
assert sess_event["did"] == "42"
assert sess_event["init"]
assert sess_event["status"] == "exited"
assert sess_event["errors"] == 1
assert sess_event["attrs"] == {
"release": "fun-release",
"environment": "not-fun-env",
}