33
44
55@responses .activate
6- def test_sends_error_to_sentry (seam : Seam , monkeypatch ):
6+ def test_sends_error_to_sentry (seam : Seam , fake_sentry ):
77 rsp = responses .Response (
88 method = "GET" ,
99 url = seam .api_url + "/devices/list" ,
@@ -13,42 +13,31 @@ def test_sends_error_to_sentry(seam: Seam, monkeypatch):
1313 )
1414 responses .add (rsp )
1515
16- sentry_init_args = {}
17- sentry_dsn = "https://sentry.io/123"
18- monkeypatch .setenv ("SENTRY_DSN" , sentry_dsn )
19- monkeypatch .setattr ("sentry_sdk.init" , lambda * a , ** kw : sentry_init_args .update (kw ))
20-
2116 client_with_sentry = Seam (
2217 api_key = seam .api_key ,
2318 api_url = seam .api_url ,
2419 should_report_exceptions = True ,
2520 )
2621
27- assert sentry_init_args ["dsn" ] == sentry_dsn
28- assert sentry_init_args ["default_integrations" ] is False
29-
30- sentry_capture_exception_calls = []
31- monkeypatch .setattr ("sentry_sdk.capture_exception" , lambda * a , ** kw : sentry_capture_exception_calls .append ((a , kw )))
22+ assert fake_sentry ["sentry_init_args" ]["dsn" ] == fake_sentry ["sentry_dsn" ]
3223
33- sentry_add_breadcrumb_calls = []
34- monkeypatch .setattr ("sentry_sdk.add_breadcrumb" , lambda * a , ** kw : sentry_add_breadcrumb_calls .append ((a , kw )))
3524 try :
3625 client_with_sentry .devices .list ()
3726 assert False
38- except :
27+ except Exception as error :
3928 pass
4029
4130 assert rsp .call_count == 1
4231
43- assert len (sentry_capture_exception_calls ) == 1
44- assert type (sentry_capture_exception_calls [0 ][0 ][0 ]) is KeyError
32+ assert len (fake_sentry [ " sentry_capture_exception_calls" ] ) == 1
33+ assert type (fake_sentry [ " sentry_capture_exception_calls" ] [0 ][0 ][0 ]) is KeyError
4534
46- assert len (sentry_add_breadcrumb_calls ) == 1
47- assert sentry_add_breadcrumb_calls [0 ][1 ]['category' ] == "http"
48- assert sentry_add_breadcrumb_calls [0 ][1 ]["data" ]["request_id" ] == "1234"
35+ assert len (fake_sentry [ " sentry_add_breadcrumb_calls" ] ) == 1
36+ assert fake_sentry [ " sentry_add_breadcrumb_calls" ] [0 ][1 ]['category' ] == "http"
37+ assert fake_sentry [ " sentry_add_breadcrumb_calls" ] [0 ][1 ]["data" ]["request_id" ] == "1234"
4938
5039@responses .activate
51- def test_skips_sentry_reporting (seam : Seam , monkeypatch ):
40+ def test_skips_sentry_reporting (seam : Seam , fake_sentry ):
5241 rsp = responses .Response (
5342 method = "GET" ,
5443 url = seam .api_url + "/devices/list" ,
@@ -57,17 +46,11 @@ def test_skips_sentry_reporting(seam: Seam, monkeypatch):
5746 )
5847 responses .add (rsp )
5948
60- monkeypatch .setenv ("SENTRY_DSN" , "https://sentry.io/123" )
61- monkeypatch .setattr ("sentry_sdk.init" , lambda * a , ** kw : None )
62-
6349 client_without_sentry = Seam (
6450 api_key = seam .api_key ,
6551 api_url = seam .api_url ,
6652 )
6753
68- sentry_capture_exception_calls = []
69- monkeypatch .setattr ("sentry_sdk.capture_exception" , lambda * a , ** kw : sentry_capture_exception_calls .append ((a , kw )))
70-
7154 try :
7255 client_without_sentry .devices .list ()
7356 assert False
@@ -76,29 +59,21 @@ def test_skips_sentry_reporting(seam: Seam, monkeypatch):
7659
7760 assert rsp .call_count == 1
7861
79- assert len (sentry_capture_exception_calls ) == 0
80-
81- def test_skips_report_for_known_error (seam : Seam , monkeypatch ):
82- sentry_init_args = {}
83- sentry_dsn = "https://sentry.io/123"
84- monkeypatch .setenv ("SENTRY_DSN" , sentry_dsn )
85- monkeypatch .setattr ("sentry_sdk.init" , lambda * a , ** kw : sentry_init_args .update (kw ))
62+ assert len (fake_sentry ["sentry_capture_exception_calls" ]) == 0
8663
64+ def test_skips_report_for_known_error (seam : Seam , fake_sentry ):
8765 client_without_sentry = Seam (
8866 api_key = seam .api_key ,
8967 api_url = seam .api_url ,
9068 should_report_exceptions = True
9169 )
9270
93- assert sentry_init_args ["dsn" ] == sentry_dsn
94-
95- sentry_capture_exception_calls = []
96- monkeypatch .setattr ("sentry_sdk.capture_exception" , lambda * a , ** kw : sentry_capture_exception_calls .append ((a , kw )))
71+ assert fake_sentry ["sentry_init_args" ]["dsn" ] == fake_sentry ["sentry_dsn" ]
9772
9873 try :
9974 client_without_sentry .devices .get ("123" )
10075 assert False
10176 except :
10277 pass
10378
104- assert len (sentry_capture_exception_calls ) == 0
79+ assert len (fake_sentry [ " sentry_capture_exception_calls" ] ) == 0
0 commit comments