18
18
19
19
20
20
@pytest .fixture
21
- def app (sentry_init ):
22
- sentry_init (
23
- integrations = [
24
- flask_sentry .FlaskIntegration (),
25
- LoggingIntegration (event_level = "ERROR" ),
26
- ]
27
- )
28
-
21
+ def app ():
29
22
app = Flask (__name__ )
30
23
app .config ["TESTING" ] = True
31
24
app .secret_key = "haha"
@@ -40,7 +33,8 @@ def hi():
40
33
return app
41
34
42
35
43
- def test_has_context (app , capture_events ):
36
+ def test_has_context (sentry_init , app , capture_events ):
37
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
44
38
events = capture_events ()
45
39
46
40
client = app .test_client ()
@@ -55,7 +49,9 @@ def test_has_context(app, capture_events):
55
49
56
50
@pytest .mark .parametrize ("debug" , (True , False ))
57
51
@pytest .mark .parametrize ("testing" , (True , False ))
58
- def test_errors (capture_exceptions , app , debug , testing ):
52
+ def test_errors (sentry_init , capture_exceptions , app , debug , testing ):
53
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
54
+
59
55
app .debug = debug
60
56
app .testing = testing
61
57
@@ -75,7 +71,9 @@ def index():
75
71
assert isinstance (exc , ZeroDivisionError )
76
72
77
73
78
- def test_flask_login_not_installed (app , capture_events , monkeypatch ):
74
+ def test_flask_login_not_installed (sentry_init , app , capture_events , monkeypatch ):
75
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
76
+
79
77
monkeypatch .setattr (flask_sentry , "current_user" , None )
80
78
81
79
events = capture_events ()
@@ -87,7 +85,9 @@ def test_flask_login_not_installed(app, capture_events, monkeypatch):
87
85
assert event .get ("user" , {}).get ("id" ) is None
88
86
89
87
90
- def test_flask_login_not_configured (app , capture_events , monkeypatch ):
88
+ def test_flask_login_not_configured (sentry_init , app , capture_events , monkeypatch ):
89
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
90
+
91
91
assert flask_sentry .current_user is not None
92
92
93
93
events = capture_events ()
@@ -98,7 +98,11 @@ def test_flask_login_not_configured(app, capture_events, monkeypatch):
98
98
assert event .get ("user" , {}).get ("id" ) is None
99
99
100
100
101
- def test_flask_login_partially_configured (app , capture_events , monkeypatch ):
101
+ def test_flask_login_partially_configured (
102
+ sentry_init , app , capture_events , monkeypatch
103
+ ):
104
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
105
+
102
106
events = capture_events ()
103
107
104
108
login_manager = LoginManager ()
@@ -112,7 +116,9 @@ def test_flask_login_partially_configured(app, capture_events, monkeypatch):
112
116
113
117
114
118
@pytest .mark .parametrize ("user_id" , [None , "42" , 3 ])
115
- def test_flask_login_configured (app , user_id , capture_events , monkeypatch ):
119
+ def test_flask_login_configured (sentry_init , app , user_id , capture_events , monkeypatch ):
120
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
121
+
116
122
class User (object ):
117
123
is_authenticated = is_active = True
118
124
is_anonymous = user_id is not None
@@ -146,7 +152,9 @@ def login():
146
152
assert event ["user" ]["id" ] == str (user_id )
147
153
148
154
149
- def test_flask_large_json_request (capture_events , app ):
155
+ def test_flask_large_json_request (sentry_init , capture_events , app ):
156
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
157
+
150
158
data = {"foo" : {"bar" : "a" * 2000 }}
151
159
152
160
@app .route ("/" , methods = ["POST" ])
@@ -171,7 +179,9 @@ def index():
171
179
assert event ["request" ]["data_info" ] == {"ct" : "json" , "repr" : "structured" }
172
180
173
181
174
- def test_flask_large_formdata_request (capture_events , app ):
182
+ def test_flask_large_formdata_request (sentry_init , capture_events , app ):
183
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
184
+
175
185
data = {"foo" : "a" * 2000 }
176
186
177
187
@app .route ("/" , methods = ["POST" ])
@@ -197,7 +207,9 @@ def index():
197
207
198
208
199
209
@pytest .mark .parametrize ("input_char" , [u"a" , b"a" ])
200
- def test_flask_large_text_request (input_char , capture_events , app ):
210
+ def test_flask_large_text_request (sentry_init , input_char , capture_events , app ):
211
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
212
+
201
213
data = input_char * 2000
202
214
203
215
@app .route ("/" , methods = ["POST" ])
@@ -225,7 +237,9 @@ def index():
225
237
assert event ["request" ]["data_info" ] == {"ct" : "plain" , "repr" : "other" }
226
238
227
239
228
- def test_flask_large_bytes_request (capture_events , app ):
240
+ def test_flask_large_bytes_request (sentry_init , capture_events , app ):
241
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
242
+
229
243
data = b"\xc3 " * 2000
230
244
231
245
@app .route ("/" , methods = ["POST" ])
@@ -250,7 +264,9 @@ def index():
250
264
assert event ["request" ]["data_info" ] == {"ct" : "bytes" , "repr" : "base64" }
251
265
252
266
253
- def test_flask_files_and_form (capture_events , app ):
267
+ def test_flask_files_and_form (sentry_init , capture_events , app ):
268
+ sentry_init (integrations = [flask_sentry .FlaskIntegration ()])
269
+
254
270
data = {"foo" : "a" * 2000 , "file" : (BytesIO (b"hello" ), "hello.txt" )}
255
271
256
272
@app .route ("/" , methods = ["POST" ])
@@ -279,7 +295,16 @@ def index():
279
295
assert not event ["request" ]["data" ]["file" ]
280
296
281
297
282
- def test_errors_not_reported_twice (capture_events , app ):
298
+ @pytest .mark .parametrize (
299
+ "integrations" ,
300
+ [
301
+ [flask_sentry .FlaskIntegration ()],
302
+ [flask_sentry .FlaskIntegration (), LoggingIntegration (event_level = "ERROR" )],
303
+ ],
304
+ )
305
+ def test_errors_not_reported_twice (sentry_init , integrations , capture_events , app ):
306
+ sentry_init (integrations = integrations )
307
+
283
308
@app .route ("/" )
284
309
def index ():
285
310
try :
@@ -297,8 +322,14 @@ def index():
297
322
assert len (events ) == 1
298
323
299
324
300
- def test_logging (capture_events , app ):
325
+ def test_logging (sentry_init , capture_events , app ):
301
326
# ensure that Flask's logger magic doesn't break ours
327
+ sentry_init (
328
+ integrations = [
329
+ flask_sentry .FlaskIntegration (),
330
+ LoggingIntegration (event_level = "ERROR" ),
331
+ ]
332
+ )
302
333
303
334
@app .route ("/" )
304
335
def index ():
0 commit comments