1
1
import platform
2
- import sys
3
2
import random
4
- import responses
5
- import pytest
3
+ import sys
6
4
7
- from sentry_sdk . consts import MATCH_ALL
5
+ import pytest
8
6
9
7
try :
10
8
# py3
25
23
except ImportError :
26
24
import mock # python < 3.3
27
25
26
+
28
27
from sentry_sdk import capture_message , start_transaction
28
+ from sentry_sdk .consts import MATCH_ALL
29
29
from sentry_sdk .tracing import Transaction
30
30
from sentry_sdk .integrations .stdlib import StdlibIntegration
31
31
32
+ from tests .conftest import create_mock_http_server
32
33
33
- def test_crumb_capture (sentry_init , capture_events ):
34
- sentry_init (integrations = [StdlibIntegration ()])
34
+ PORT = create_mock_http_server ()
35
35
36
- url = "http://example.com/"
37
- responses .add (responses .GET , url , status = 200 )
38
36
37
+ def test_crumb_capture (sentry_init , capture_events ):
38
+ sentry_init (integrations = [StdlibIntegration ()])
39
39
events = capture_events ()
40
40
41
- response = urlopen (url )
42
- assert response .getcode () == 200
41
+ url = "http://localhost:{}/some/random/url" .format (PORT )
42
+ urlopen (url )
43
+
43
44
capture_message ("Testing!" )
44
45
45
46
(event ,) = events
46
47
(crumb ,) = event ["breadcrumbs" ]["values" ]
48
+
47
49
assert crumb ["type" ] == "http"
48
50
assert crumb ["category" ] == "httplib"
49
51
assert crumb ["data" ] == {
@@ -62,14 +64,11 @@ def before_breadcrumb(crumb, hint):
62
64
return crumb
63
65
64
66
sentry_init (integrations = [StdlibIntegration ()], before_breadcrumb = before_breadcrumb )
65
-
66
- url = "http://example.com/"
67
- responses .add (responses .GET , url , status = 200 )
68
-
69
67
events = capture_events ()
70
68
69
+ url = "http://localhost:{}/some/random/url" .format (PORT )
71
70
response = urlopen (url )
72
- assert response . getcode () == 200
71
+
73
72
capture_message ("Testing!" )
74
73
75
74
(event ,) = events
@@ -113,7 +112,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
113
112
sentry_init ()
114
113
events = capture_events ()
115
114
116
- conn = HTTPSConnection ( "httpstat.us " , 443 )
115
+ conn = HTTPConnection ( "localhost " , PORT )
117
116
118
117
# make sure we release the resource, even if the test fails
119
118
request .addfinalizer (conn .close )
@@ -138,7 +137,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
138
137
assert crumb ["type" ] == "http"
139
138
assert crumb ["category" ] == "httplib"
140
139
assert crumb ["data" ] == {
141
- "url" : "https ://httpstat.us /200" ,
140
+ "url" : "http ://localhost:{} /200" . format ( PORT ) ,
142
141
"method" : "GET" ,
143
142
"status_code" : 200 ,
144
143
"reason" : "OK" ,
0 commit comments