@@ -15,9 +15,12 @@ def create_mock_session(timeout=None):
15
15
mock_session = Mock (spec = aiohttp .ClientSession )
16
16
if timeout :
17
17
mock_session .timeout = timeout
18
+ mock_session ._timeout = timeout # Some code accesses private attribute
18
19
else :
19
20
# Create a default timeout object
20
- mock_session .timeout = Mock (total = 300 , sock_read = None )
21
+ default_timeout = Mock (total = 300 , sock_read = None )
22
+ mock_session .timeout = default_timeout
23
+ mock_session ._timeout = default_timeout # Some code accesses private attribute
21
24
return mock_session
22
25
23
26
@@ -503,8 +506,8 @@ async def test_inherited_transport_attributes():
503
506
504
507
505
508
@pytest .mark .asyncio
506
- async def test_no_session_auto_creates ():
507
- """Test transport auto-manages session if not provided."""
509
+ async def test_session_reuse ():
510
+ """Test transport reuses provided session ."""
508
511
mock_session = create_mock_session ()
509
512
transport = AIOHTTPTransport (session = mock_session )
510
513
@@ -517,20 +520,17 @@ async def test_no_session_auto_creates():
517
520
mock_aiohttp_response .raise_for_status = Mock ()
518
521
mock_aiohttp_response .read = AsyncMock (return_value = b"test" )
519
522
520
- # Without explicit session, should auto-create and cleanup
521
- with patch ("onvif.zeep_aiohttp.ClientSession" ) as mock_session_class :
522
- mock_session = Mock (spec = aiohttp .ClientSession )
523
- mock_session .get = AsyncMock (return_value = mock_aiohttp_response )
524
- mock_session .close = AsyncMock ()
525
- mock_session_class .return_value = mock_session
523
+ mock_session .get = AsyncMock (return_value = mock_aiohttp_response )
524
+
525
+ # Make multiple requests
526
+ result1 = await transport .get ("http://example.com" )
527
+ result2 = await transport .get ("http://example.com" )
526
528
527
- # Should work without explicit context manager
528
- result = await transport .get ("http://example.com" )
529
- assert result .content == b"test"
529
+ assert result1 .content == b"test"
530
+ assert result2 .content == b"test"
530
531
531
- # Session should have been created and closed
532
- mock_session_class .assert_called ()
533
- mock_session .close .assert_called ()
532
+ # Session should be reused
533
+ assert mock_session .get .call_count == 2
534
534
535
535
536
536
def test_sync_load_creates_new_loop ():
0 commit comments