11import platform
2- import sys
32import random
4- import responses
5- import pytest
3+ import sys
64
7- from sentry_sdk . consts import MATCH_ALL
5+ import pytest
86
97try :
108 # py3
2523except ImportError :
2624 import mock # python < 3.3
2725
26+
2827from sentry_sdk import capture_message , start_transaction
28+ from sentry_sdk .consts import MATCH_ALL
2929from sentry_sdk .tracing import Transaction
3030from sentry_sdk .integrations .stdlib import StdlibIntegration
3131
32+ from tests .conftest import create_mock_http_server
3233
33- def test_crumb_capture (sentry_init , capture_events ):
34- sentry_init (integrations = [StdlibIntegration ()])
34+ PORT = create_mock_http_server ()
3535
36- url = "http://example.com/"
37- responses .add (responses .GET , url , status = 200 )
3836
37+ def test_crumb_capture (sentry_init , capture_events ):
38+ sentry_init (integrations = [StdlibIntegration ()])
3939 events = capture_events ()
4040
41- response = urlopen (url )
42- assert response .getcode () == 200
41+ url = "http://localhost:{}/some/random/url" .format (PORT )
42+ urlopen (url )
43+
4344 capture_message ("Testing!" )
4445
4546 (event ,) = events
4647 (crumb ,) = event ["breadcrumbs" ]["values" ]
48+
4749 assert crumb ["type" ] == "http"
4850 assert crumb ["category" ] == "httplib"
4951 assert crumb ["data" ] == {
@@ -62,14 +64,11 @@ def before_breadcrumb(crumb, hint):
6264 return crumb
6365
6466 sentry_init (integrations = [StdlibIntegration ()], before_breadcrumb = before_breadcrumb )
65-
66- url = "http://example.com/"
67- responses .add (responses .GET , url , status = 200 )
68-
6967 events = capture_events ()
7068
69+ url = "http://localhost:{}/some/random/url" .format (PORT )
7170 response = urlopen (url )
72- assert response . getcode () == 200
71+
7372 capture_message ("Testing!" )
7473
7574 (event ,) = events
@@ -113,7 +112,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
113112 sentry_init ()
114113 events = capture_events ()
115114
116- conn = HTTPSConnection ( "httpstat.us " , 443 )
115+ conn = HTTPConnection ( "localhost " , PORT )
117116
118117 # make sure we release the resource, even if the test fails
119118 request .addfinalizer (conn .close )
@@ -138,7 +137,7 @@ def test_httplib_misuse(sentry_init, capture_events, request):
138137 assert crumb ["type" ] == "http"
139138 assert crumb ["category" ] == "httplib"
140139 assert crumb ["data" ] == {
141- "url" : "https ://httpstat.us /200" ,
140+ "url" : "http ://localhost:{} /200" . format ( PORT ) ,
142141 "method" : "GET" ,
143142 "status_code" : 200 ,
144143 "reason" : "OK" ,
0 commit comments