forked from getsentry/sentry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_scope.py
More file actions
64 lines (48 loc) · 1.49 KB
/
test_scope.py
File metadata and controls
64 lines (48 loc) · 1.49 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
import copy
from sentry_sdk import capture_exception
from sentry_sdk.scope import Scope
def test_copying():
s1 = Scope()
s1.fingerprint = {}
s1.set_tag("foo", "bar")
s2 = copy.copy(s1)
assert "foo" in s2._tags
s1.set_tag("bam", "baz")
assert "bam" in s1._tags
assert "bam" not in s2._tags
assert s1._fingerprint is s2._fingerprint
def test_merging(sentry_init, capture_events):
sentry_init()
s = Scope()
s.set_user({"id": "42"})
events = capture_events()
capture_exception(NameError(), scope=s)
(event,) = events
assert event["user"] == {"id": "42"}
def test_common_args():
s = Scope()
s.update_from_kwargs(
user={"id": 23},
level="warning",
extras={"k": "v"},
contexts={"os": {"name": "Blafasel"}},
tags={"x": "y"},
fingerprint=["foo"],
)
s2 = Scope()
s2.set_extra("foo", "bar")
s2.set_tag("a", "b")
s2.set_context("device", {"a": "b"})
s2.update_from_scope(s)
assert s._user == {"id": 23}
assert s._level == "warning"
assert s._extras == {"k": "v"}
assert s._contexts == {"os": {"name": "Blafasel"}}
assert s._tags == {"x": "y"}
assert s._fingerprint == ["foo"]
assert s._user == s2._user
assert s._level == s2._level
assert s._fingerprint == s2._fingerprint
assert s2._extras == {"k": "v", "foo": "bar"}
assert s2._tags == {"a": "b", "x": "y"}
assert s2._contexts == {"os": {"name": "Blafasel"}, "device": {"a": "b"}}