The following two tests fail after upgrading aiohttp to 3.10.6 and newer.
____________________________________________________________________________________________________________________________________________________________________________________ test_connection_error _____________________________________________________________________________________________________________________________________________________________________________________
aresponses = <aresponses.main.ResponsesMockServer object at 0x7fee166ffc90>
@pytest.mark.asyncio
async def test_connection_error(aresponses):
"""Test to make validate proper connection error handling."""
aresponses.add("fan.local", "/mf", "POST", response=basic_info)
with pytest.raises(aiomodernforms.ModernFormsConnectionError):
async with aiomodernforms.ModernFormsDevice("fan.local") as device:
> await device.update()
tests/test_aiomodernforms.py:595:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry
ret = await target(*args, **kwargs)
aiomodernforms/modernforms.py:101: in update
state_data = await self._request()
venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry
ret = await target(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <aiomodernforms.modernforms.ModernFormsDevice object at 0x7fee166febd0>, commands = {'queryDynamicShadowData': True}
@backoff.on_exception(
backoff.expo, ModernFormsConnectionError, max_tries=3, logger=None
)
async def _request(self, commands: Optional[dict] = None) -> Any:
"""Handle a request to a Modern Forms Fan device."""
scheme = "https" if self._tls else "http"
url = URL.build(
scheme=scheme,
host=self._host,
port=self._port,
path=self._base_path,
)
auth = None
if self._username and self._password:
auth = aiohttp.BasicAuth(self._username, self._password)
headers = {
"User-Agent": self._user_agent,
"Accept": "application/json",
}
if self._session is None:
self._session = aiohttp.ClientSession()
self._close_session = True
# If updating the state, always request for a state response
if commands is None:
commands = {COMMAND_QUERY_STATUS: True}
try:
with async_timeout.timeout(self._request_timeout):
response = await self._session.request(
"POST",
url,
auth=auth,
json=commands,
headers=headers,
ssl=self._verify_ssl,
)
except asyncio.TimeoutError as exception:
raise ModernFormsConnectionTimeoutError(
"Timeout occurred while connecting to Modern Forms device at"
+ f" {self._host}"
) from exception
except (aiohttp.ClientError, socket.gaierror) as exception:
raise ModernFormsConnectionError(
"Error occurred while communicating with Modern Forms device at"
+ f" {self._host}"
) from exception
content_type = response.headers.get("Content-Type", "")
if (response.status // 100) in [4, 5]:
contents = await response.read()
response.close()
if content_type == "application/json":
raise ModernFormsError(
response.status, json.loads(contents.decode("utf8"))
)
> raise ModernFormsError(
response.status, {"message": contents.decode("utf8")}
)
E aiomodernforms.exceptions.ModernFormsError: (500, {'message': '500: Internal Server Error'})
aiomodernforms/modernforms.py:172: ModernFormsError
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Captured log call ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ERROR aiohttp.server:web_protocol.py:448 Missing return statement on request handler
Traceback (most recent call last):
File "/tmp/aiomodernforms/venv/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 653, in finish_response
prepare_meth = resp.prepare
^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'prepare'
_____________________________________________________________________________________________________________________________________________________________________________________ test_empty_response ______________________________________________________________________________________________________________________________________________________________________________________
aresponses = <aresponses.main.ResponsesMockServer object at 0x7fee16e13690>
@pytest.mark.asyncio
async def test_empty_response(aresponses):
"""Test for an Empty Response."""
aresponses.add("fan.local", "/mf", "POST", response=basic_info)
async def send_empty_state(request):
await request.json()
return aresponses.Response(
status=200,
content_type="application/json",
text="{}",
)
aresponses.add("fan.local", "/mf", "POST", response=send_empty_state)
with pytest.raises(ModernFormsConnectionError):
async with aiomodernforms.ModernFormsDevice("fan.local") as device:
> await device.update()
tests/test_aiomodernforms.py:661:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry
ret = await target(*args, **kwargs)
aiomodernforms/modernforms.py:100: in update
info_data = await self._request({COMMAND_QUERY_STATIC_DATA: True})
venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry
ret = await target(*args, **kwargs)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
self = <aiomodernforms.modernforms.ModernFormsDevice object at 0x7fee166b5e90>, commands = {'queryStaticShadowData': True}
@backoff.on_exception(
backoff.expo, ModernFormsConnectionError, max_tries=3, logger=None
)
async def _request(self, commands: Optional[dict] = None) -> Any:
"""Handle a request to a Modern Forms Fan device."""
scheme = "https" if self._tls else "http"
url = URL.build(
scheme=scheme,
host=self._host,
port=self._port,
path=self._base_path,
)
auth = None
if self._username and self._password:
auth = aiohttp.BasicAuth(self._username, self._password)
headers = {
"User-Agent": self._user_agent,
"Accept": "application/json",
}
if self._session is None:
self._session = aiohttp.ClientSession()
self._close_session = True
# If updating the state, always request for a state response
if commands is None:
commands = {COMMAND_QUERY_STATUS: True}
try:
with async_timeout.timeout(self._request_timeout):
response = await self._session.request(
"POST",
url,
auth=auth,
json=commands,
headers=headers,
ssl=self._verify_ssl,
)
except asyncio.TimeoutError as exception:
raise ModernFormsConnectionTimeoutError(
"Timeout occurred while connecting to Modern Forms device at"
+ f" {self._host}"
) from exception
except (aiohttp.ClientError, socket.gaierror) as exception:
raise ModernFormsConnectionError(
"Error occurred while communicating with Modern Forms device at"
+ f" {self._host}"
) from exception
content_type = response.headers.get("Content-Type", "")
if (response.status // 100) in [4, 5]:
contents = await response.read()
response.close()
if content_type == "application/json":
raise ModernFormsError(
response.status, json.loads(contents.decode("utf8"))
)
> raise ModernFormsError(
response.status, {"message": contents.decode("utf8")}
)
E aiomodernforms.exceptions.ModernFormsError: (500, {'message': '500: Internal Server Error'})
aiomodernforms/modernforms.py:172: ModernFormsError
The following two tests fail after upgrading aiohttp to 3.10.6 and newer.
____________________________________________________________________________________________________________________________________________________________________________________ test_connection_error _____________________________________________________________________________________________________________________________________________________________________________________ aresponses = <aresponses.main.ResponsesMockServer object at 0x7fee166ffc90> @pytest.mark.asyncio async def test_connection_error(aresponses): """Test to make validate proper connection error handling.""" aresponses.add("fan.local", "/mf", "POST", response=basic_info) with pytest.raises(aiomodernforms.ModernFormsConnectionError): async with aiomodernforms.ModernFormsDevice("fan.local") as device: > await device.update() tests/test_aiomodernforms.py:595: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry ret = await target(*args, **kwargs) aiomodernforms/modernforms.py:101: in update state_data = await self._request() venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry ret = await target(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <aiomodernforms.modernforms.ModernFormsDevice object at 0x7fee166febd0>, commands = {'queryDynamicShadowData': True} @backoff.on_exception( backoff.expo, ModernFormsConnectionError, max_tries=3, logger=None ) async def _request(self, commands: Optional[dict] = None) -> Any: """Handle a request to a Modern Forms Fan device.""" scheme = "https" if self._tls else "http" url = URL.build( scheme=scheme, host=self._host, port=self._port, path=self._base_path, ) auth = None if self._username and self._password: auth = aiohttp.BasicAuth(self._username, self._password) headers = { "User-Agent": self._user_agent, "Accept": "application/json", } if self._session is None: self._session = aiohttp.ClientSession() self._close_session = True # If updating the state, always request for a state response if commands is None: commands = {COMMAND_QUERY_STATUS: True} try: with async_timeout.timeout(self._request_timeout): response = await self._session.request( "POST", url, auth=auth, json=commands, headers=headers, ssl=self._verify_ssl, ) except asyncio.TimeoutError as exception: raise ModernFormsConnectionTimeoutError( "Timeout occurred while connecting to Modern Forms device at" + f" {self._host}" ) from exception except (aiohttp.ClientError, socket.gaierror) as exception: raise ModernFormsConnectionError( "Error occurred while communicating with Modern Forms device at" + f" {self._host}" ) from exception content_type = response.headers.get("Content-Type", "") if (response.status // 100) in [4, 5]: contents = await response.read() response.close() if content_type == "application/json": raise ModernFormsError( response.status, json.loads(contents.decode("utf8")) ) > raise ModernFormsError( response.status, {"message": contents.decode("utf8")} ) E aiomodernforms.exceptions.ModernFormsError: (500, {'message': '500: Internal Server Error'}) aiomodernforms/modernforms.py:172: ModernFormsError -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- Captured log call --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ERROR aiohttp.server:web_protocol.py:448 Missing return statement on request handler Traceback (most recent call last): File "/tmp/aiomodernforms/venv/lib/python3.11/site-packages/aiohttp/web_protocol.py", line 653, in finish_response prepare_meth = resp.prepare ^^^^^^^^^^^^ AttributeError: 'NoneType' object has no attribute 'prepare' _____________________________________________________________________________________________________________________________________________________________________________________ test_empty_response ______________________________________________________________________________________________________________________________________________________________________________________ aresponses = <aresponses.main.ResponsesMockServer object at 0x7fee16e13690> @pytest.mark.asyncio async def test_empty_response(aresponses): """Test for an Empty Response.""" aresponses.add("fan.local", "/mf", "POST", response=basic_info) async def send_empty_state(request): await request.json() return aresponses.Response( status=200, content_type="application/json", text="{}", ) aresponses.add("fan.local", "/mf", "POST", response=send_empty_state) with pytest.raises(ModernFormsConnectionError): async with aiomodernforms.ModernFormsDevice("fan.local") as device: > await device.update() tests/test_aiomodernforms.py:661: _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry ret = await target(*args, **kwargs) aiomodernforms/modernforms.py:100: in update info_data = await self._request({COMMAND_QUERY_STATIC_DATA: True}) venv/lib/python3.11/site-packages/backoff/_async.py:151: in retry ret = await target(*args, **kwargs) _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ self = <aiomodernforms.modernforms.ModernFormsDevice object at 0x7fee166b5e90>, commands = {'queryStaticShadowData': True} @backoff.on_exception( backoff.expo, ModernFormsConnectionError, max_tries=3, logger=None ) async def _request(self, commands: Optional[dict] = None) -> Any: """Handle a request to a Modern Forms Fan device.""" scheme = "https" if self._tls else "http" url = URL.build( scheme=scheme, host=self._host, port=self._port, path=self._base_path, ) auth = None if self._username and self._password: auth = aiohttp.BasicAuth(self._username, self._password) headers = { "User-Agent": self._user_agent, "Accept": "application/json", } if self._session is None: self._session = aiohttp.ClientSession() self._close_session = True # If updating the state, always request for a state response if commands is None: commands = {COMMAND_QUERY_STATUS: True} try: with async_timeout.timeout(self._request_timeout): response = await self._session.request( "POST", url, auth=auth, json=commands, headers=headers, ssl=self._verify_ssl, ) except asyncio.TimeoutError as exception: raise ModernFormsConnectionTimeoutError( "Timeout occurred while connecting to Modern Forms device at" + f" {self._host}" ) from exception except (aiohttp.ClientError, socket.gaierror) as exception: raise ModernFormsConnectionError( "Error occurred while communicating with Modern Forms device at" + f" {self._host}" ) from exception content_type = response.headers.get("Content-Type", "") if (response.status // 100) in [4, 5]: contents = await response.read() response.close() if content_type == "application/json": raise ModernFormsError( response.status, json.loads(contents.decode("utf8")) ) > raise ModernFormsError( response.status, {"message": contents.decode("utf8")} ) E aiomodernforms.exceptions.ModernFormsError: (500, {'message': '500: Internal Server Error'}) aiomodernforms/modernforms.py:172: ModernFormsError