Fix error handling in subscription info retrieval and update tests

This commit is contained in:
ludeeus 2025-07-08 11:15:38 +00:00
parent d2bf27195a
commit 33ac13185a
No known key found for this signature in database
2 changed files with 23 additions and 4 deletions

View File

@ -23,7 +23,11 @@ async def async_subscription_info(cloud: Cloud[CloudClient]) -> SubscriptionInfo
return await cloud.payments.subscription_info() return await cloud.payments.subscription_info()
except PaymentsApiError as exception: except PaymentsApiError as exception:
_LOGGER.error("Failed to fetch subscription information - %s", exception) _LOGGER.error("Failed to fetch subscription information - %s", exception)
except TimeoutError:
_LOGGER.error(
"A timeout of %s was reached while trying to fetch subscription information",
REQUEST_TIMEOUT,
)
return None return None

View File

@ -29,19 +29,34 @@ async def mocked_cloud_object(hass: HomeAssistant) -> Cloud:
) )
async def test_fetching_subscription_with_timeout_error( async def test_fetching_subscription_with_api_error(
aioclient_mock: AiohttpClientMocker, aioclient_mock: AiohttpClientMocker,
caplog: pytest.LogCaptureFixture, caplog: pytest.LogCaptureFixture,
mocked_cloud: Cloud, mocked_cloud: Cloud,
) -> None: ) -> None:
"""Test that we handle timeout error.""" """Test that we handle timeout error."""
mocked_cloud.payments.subscription_info.side_effect = payments_api.PaymentsApiError( mocked_cloud.payments.subscription_info.side_effect = payments_api.PaymentsApiError(
"Timeout reached while calling API" "There was an error with the API"
) )
assert await async_subscription_info(mocked_cloud) is None assert await async_subscription_info(mocked_cloud) is None
assert ( assert (
"Failed to fetch subscription information - Timeout reached while calling API" "Failed to fetch subscription information - There was an error with the API"
in caplog.text
)
async def test_fetching_subscription_with_timeout_error(
aioclient_mock: AiohttpClientMocker,
caplog: pytest.LogCaptureFixture,
mocked_cloud: Cloud,
) -> None:
"""Test that we handle timeout error."""
mocked_cloud.payments.subscription_info.side_effect = TimeoutError()
assert await async_subscription_info(mocked_cloud) is None
assert (
"A timeout of 10 was reached while trying to fetch subscription information"
in caplog.text in caplog.text
) )