23
23
import aiohttp
24
24
import aiohttp .test_utils
25
25
import yarl
26
+ from http_server_mock import HttpServerMock
26
27
from pkg_resources import iter_entry_points
27
28
28
29
from opentelemetry import context
@@ -313,18 +314,26 @@ async def request_handler(request):
313
314
def test_credential_removal (self ):
314
315
trace_configs = [aiohttp_client .create_trace_config ()]
315
316
316
- url = "http://username:password@httpbin.org/status/200"
317
- with self .subTest (url = url ):
317
+ app = HttpServerMock ("test_credential_removal" )
318
318
319
- async def do_request (url ):
320
- async with aiohttp .ClientSession (
321
- trace_configs = trace_configs ,
322
- ) as session :
323
- async with session .get (url ):
324
- pass
319
+ @app .route ("/status/200" )
320
+ def index ():
321
+ return "hello"
325
322
326
- loop = asyncio .get_event_loop ()
327
- loop .run_until_complete (do_request (url ))
323
+ url = "http://username:password@localhost:5000/status/200"
324
+
325
+ with app .run ("localhost" , 5000 ):
326
+ with self .subTest (url = url ):
327
+
328
+ async def do_request (url ):
329
+ async with aiohttp .ClientSession (
330
+ trace_configs = trace_configs ,
331
+ ) as session :
332
+ async with session .get (url ):
333
+ pass
334
+
335
+ loop = asyncio .get_event_loop ()
336
+ loop .run_until_complete (do_request (url ))
328
337
329
338
self .assert_spans (
330
339
[
@@ -333,7 +342,9 @@ async def do_request(url):
333
342
(StatusCode .UNSET , None ),
334
343
{
335
344
SpanAttributes .HTTP_METHOD : "GET" ,
336
- SpanAttributes .HTTP_URL : "http://httpbin.org/status/200" ,
345
+ SpanAttributes .HTTP_URL : (
346
+ "http://localhost:5000/status/200"
347
+ ),
337
348
SpanAttributes .HTTP_STATUS_CODE : int (HTTPStatus .OK ),
338
349
},
339
350
)
0 commit comments