@@ -34,61 +34,74 @@ async def handle_echo(request: web.Request) -> web.Response:
3434 return runner , f"http://localhost:{ unused_tcp_port } "
3535
3636 @pytest .mark .asyncio
37- async def test_http_connector_with_mock_server (self , mock_http_server : tuple [web .AppRunner , str ]) -> None :
38- """Test HTTP connector with a mock HTTP server"""
37+ async def test_http_connector_with_mock_server (
38+ self , mock_http_server : tuple [web .AppRunner , str ]
39+ ) -> None :
40+ """Test HTTP connector with a mock HTTP server.
41+
42+ Args:
43+ mock_http_server: Fixture that provides a mock HTTP server.
44+ """
3945 runner , server_url = mock_http_server
40-
46+
4147 # Start the mock server
4248 await runner .setup ()
43- site = web .TCPSite (runner , " localhost" , int (server_url .split (":" )[- 1 ]))
49+ site = web .TCPSite (runner , ' localhost' , int (server_url .split (':' )[- 1 ]))
4450 await site .start ()
45-
51+
4652 try :
4753 # Test the HTTP connector
4854 connector = HTTPDestination (f"{ server_url } /echo" )
4955 test_data = {"test" : "data" }
50-
56+
5157 # Mock the session to capture the request
52- with patch (" aiohttp.ClientSession.post" ) as mock_post :
58+ with patch (' aiohttp.ClientSession.post' ) as mock_post :
5359 mock_response = MagicMock ()
5460 mock_response .__aenter__ .return_value .status = 200
55- mock_response .__aenter__ .return_value .json .return_value = {
56- "echo" : test_data
57- }
61+ mock_response .__aenter__ .return_value .json .return_value = {"echo" : test_data }
5862 mock_post .return_value = mock_response
59-
63+
6064 await connector .send (test_data )
61-
65+
6266 # Verify the request was made correctly
63- mock_post .assert_called_once_with (f"{ server_url } /echo" , json = test_data )
64-
67+ mock_post .assert_called_once_with (
68+ f"{ server_url } /echo" ,
69+ json = test_data
70+ )
71+
6572 finally :
6673 # Clean up the server
6774 await runner .cleanup ()
68-
75+
6976 @pytest .mark .asyncio
70- async def test_http_connector_with_real_request (self , mock_http_server ):
71- """Test HTTP connector with a real request to mock server"""
77+ async def test_http_connector_with_real_request (
78+ self , mock_http_server : tuple [web .AppRunner , str ]
79+ ) -> None :
80+ """Test HTTP connector with a real request to mock server.
81+
82+ Args:
83+ mock_http_server: Fixture that provides a mock HTTP server.
84+ """
7285 runner , server_url = mock_http_server
73-
86+
7487 # Start the mock server
7588 await runner .setup ()
76- site = web .TCPSite (runner , " localhost" , int (server_url .split (":" )[- 1 ]))
89+ site = web .TCPSite (runner , ' localhost' , int (server_url .split (':' )[- 1 ]))
7790 await site .start ()
78-
91+
7992 try :
8093 # Test the HTTP connector with a real request
8194 connector = HTTPDestination (f"{ server_url } /echo" )
8295 test_data = {"message" : "Hello, World!" }
83-
96+
8497 # This will make a real HTTP request to our mock server
8598 async with aiohttp .ClientSession () as session :
86- with patch (" aiohttp.ClientSession" , return_value = session ):
99+ with patch (' aiohttp.ClientSession' , return_value = session ):
87100 await connector .send (test_data )
88-
101+
89102 # Verify the request was made by checking the server logs
90103 # or other side effects if needed
91-
104+
92105 finally :
93106 # Clean up the server
94107 await runner .cleanup ()
0 commit comments