forked from getsentry/sentry-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_wsgi.py
More file actions
64 lines (45 loc) · 1.64 KB
/
Copy pathtest_wsgi.py
File metadata and controls
64 lines (45 loc) · 1.64 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
from werkzeug.test import Client
import pytest
from sentry_sdk.integrations.wsgi import SentryWsgiMiddleware
@pytest.fixture
def crashing_app():
def app(environ, start_response):
1 / 0
return app
@pytest.fixture
def crashing_env_modifing_app():
class TooSmartClass(object):
def __init__(self, environ):
self.environ = environ
def __repr__(self):
if "my_representation" in self.environ:
return self.environ["my_representation"]
self.environ["my_representation"] = "<This is me>"
return self.environ["my_representation"]
def app(environ, start_response):
environ["tsc"] = TooSmartClass(environ)
1 / 0
return app
def test_basic(sentry_init, crashing_app, capture_events):
sentry_init(send_default_pii=True)
app = SentryWsgiMiddleware(crashing_app)
client = Client(app)
events = capture_events()
with pytest.raises(ZeroDivisionError):
client.get("/")
event, = events
assert event["request"] == {
"env": {"SERVER_NAME": "localhost", "SERVER_PORT": "80"},
"headers": {"Content-Length": "0", "Content-Type": "", "Host": "localhost"},
"method": "GET",
"query_string": "",
"url": "http://localhost/",
}
def test_env_modifing_app(sentry_init, crashing_env_modifing_app, capture_events):
sentry_init(send_default_pii=True)
app = SentryWsgiMiddleware(crashing_env_modifing_app)
client = Client(app)
events = capture_events()
with pytest.raises(ZeroDivisionError):
client.get("/")
assert len(events) == 1 # only one exception is raised