mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Fix transport retries after close (#568)
This commit is contained in:
parent
4a00199506
commit
01f3827d73
@ -88,6 +88,8 @@ class AesTransport(BaseTransport):
|
|||||||
|
|
||||||
async def client_post(self, url, params=None, data=None, json=None, headers=None):
|
async def client_post(self, url, params=None, data=None, json=None, headers=None):
|
||||||
"""Send an http post request to the device."""
|
"""Send an http post request to the device."""
|
||||||
|
if not self._http_client:
|
||||||
|
self._http_client = httpx.AsyncClient()
|
||||||
response_data = None
|
response_data = None
|
||||||
cookies = None
|
cookies = None
|
||||||
if self._session_cookie:
|
if self._session_cookie:
|
||||||
|
@ -118,6 +118,8 @@ class KlapTransport(BaseTransport):
|
|||||||
|
|
||||||
async def client_post(self, url, params=None, data=None):
|
async def client_post(self, url, params=None, data=None):
|
||||||
"""Send an http post request to the device."""
|
"""Send an http post request to the device."""
|
||||||
|
if not self._http_client:
|
||||||
|
self._http_client = httpx.AsyncClient()
|
||||||
response_data = None
|
response_data = None
|
||||||
cookies = None
|
cookies = None
|
||||||
if self._session_cookie:
|
if self._session_cookie:
|
||||||
|
@ -32,7 +32,7 @@ class _mock_response:
|
|||||||
async def test_protocol_retries(mocker, retry_count, protocol_class, transport_class):
|
async def test_protocol_retries(mocker, retry_count, protocol_class, transport_class):
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
conn = mocker.patch.object(
|
conn = mocker.patch.object(
|
||||||
transport_class, "client_post", side_effect=Exception("dummy exception")
|
httpx.AsyncClient, "post", side_effect=Exception("dummy exception")
|
||||||
)
|
)
|
||||||
with pytest.raises(SmartDeviceException):
|
with pytest.raises(SmartDeviceException):
|
||||||
await protocol_class(host, transport=transport_class(host)).query(
|
await protocol_class(host, transport=transport_class(host)).query(
|
||||||
@ -49,8 +49,8 @@ async def test_protocol_no_retry_on_connection_error(
|
|||||||
):
|
):
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
conn = mocker.patch.object(
|
conn = mocker.patch.object(
|
||||||
transport_class,
|
httpx.AsyncClient,
|
||||||
"client_post",
|
"post",
|
||||||
side_effect=httpx.ConnectError("foo"),
|
side_effect=httpx.ConnectError("foo"),
|
||||||
)
|
)
|
||||||
with pytest.raises(SmartDeviceException):
|
with pytest.raises(SmartDeviceException):
|
||||||
@ -68,8 +68,8 @@ async def test_protocol_retry_recoverable_error(
|
|||||||
):
|
):
|
||||||
host = "127.0.0.1"
|
host = "127.0.0.1"
|
||||||
conn = mocker.patch.object(
|
conn = mocker.patch.object(
|
||||||
transport_class,
|
httpx.AsyncClient,
|
||||||
"client_post",
|
"post",
|
||||||
side_effect=httpx.CloseError("foo"),
|
side_effect=httpx.CloseError("foo"),
|
||||||
)
|
)
|
||||||
with pytest.raises(SmartDeviceException):
|
with pytest.raises(SmartDeviceException):
|
||||||
|
Loading…
Reference in New Issue
Block a user