Skip to content

Commit a22b5e8

Browse files
committed
Migrate to using aiohttp
1 parent 80de8a2 commit a22b5e8

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

onvif/zeep_aiohttp.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,15 @@ def _aiohttp_to_requests_response(
116116
new._content = content
117117
new.status_code = aiohttp_response.status
118118
new.headers = dict(aiohttp_response.headers)
119-
new.cookies = aiohttp_response.cookies
119+
# Convert aiohttp cookies to requests format
120+
if aiohttp_response.cookies:
121+
for name, cookie in aiohttp_response.cookies.items():
122+
new.cookies.set(
123+
name,
124+
cookie.value,
125+
domain=cookie.get("domain"),
126+
path=cookie.get("path"),
127+
)
120128
new.encoding = aiohttp_response.charset
121129
return new
122130

tests/test_zeep_transport.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,11 @@ async def test_cookies_in_requests_response():
451451
"""Test cookies are properly transferred to requests response."""
452452
transport = AIOHTTPTransport()
453453

454-
# Mock cookies
455-
mock_cookies = {"session": "abc123"}
454+
# Mock cookies using SimpleCookie format
455+
from http.cookies import SimpleCookie
456+
457+
mock_cookies = SimpleCookie()
458+
mock_cookies["session"] = "abc123"
456459

457460
# Mock response with cookies
458461
mock_aiohttp_response = Mock(spec=aiohttp.ClientResponse)
@@ -469,7 +472,8 @@ async def test_cookies_in_requests_response():
469472

470473
# Test requests response (from get)
471474
requests_result = await transport.get("http://example.com")
472-
assert requests_result.cookies == mock_cookies
475+
assert "session" in requests_result.cookies
476+
assert requests_result.cookies["session"] == "abc123"
473477

474478

475479
@pytest.mark.asyncio

0 commit comments

Comments
 (0)