mirror of
https://github.com/home-assistant/core.git
synced 2025-08-10 16:15:08 +02:00
Move to the new handler for migrate_paypal_agreement (#149934)
This commit is contained in:
@@ -4,11 +4,13 @@ from __future__ import annotations
|
|||||||
|
|
||||||
import asyncio
|
import asyncio
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
from aiohttp.client_exceptions import ClientError
|
from hass_nabucasa import (
|
||||||
from hass_nabucasa import Cloud, cloud_api
|
Cloud,
|
||||||
from hass_nabucasa.payments_api import PaymentsApiError, SubscriptionInfo
|
MigratePaypalAgreementInfo,
|
||||||
|
PaymentsApiError,
|
||||||
|
SubscriptionInfo,
|
||||||
|
)
|
||||||
|
|
||||||
from .client import CloudClient
|
from .client import CloudClient
|
||||||
from .const import REQUEST_TIMEOUT
|
from .const import REQUEST_TIMEOUT
|
||||||
@@ -29,17 +31,17 @@ async def async_subscription_info(cloud: Cloud[CloudClient]) -> SubscriptionInfo
|
|||||||
|
|
||||||
async def async_migrate_paypal_agreement(
|
async def async_migrate_paypal_agreement(
|
||||||
cloud: Cloud[CloudClient],
|
cloud: Cloud[CloudClient],
|
||||||
) -> dict[str, Any] | None:
|
) -> MigratePaypalAgreementInfo | None:
|
||||||
"""Migrate a paypal agreement from legacy."""
|
"""Migrate a paypal agreement from legacy."""
|
||||||
try:
|
try:
|
||||||
async with asyncio.timeout(REQUEST_TIMEOUT):
|
async with asyncio.timeout(REQUEST_TIMEOUT):
|
||||||
return await cloud_api.async_migrate_paypal_agreement(cloud)
|
return await cloud.payments.migrate_paypal_agreement()
|
||||||
except TimeoutError:
|
except TimeoutError:
|
||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"A timeout of %s was reached while trying to start agreement migration",
|
"A timeout of %s was reached while trying to start agreement migration",
|
||||||
REQUEST_TIMEOUT,
|
REQUEST_TIMEOUT,
|
||||||
)
|
)
|
||||||
except ClientError as exception:
|
except PaymentsApiError as exception:
|
||||||
_LOGGER.error("Failed to start agreement migration - %s", exception)
|
_LOGGER.error("Failed to start agreement migration - %s", exception)
|
||||||
|
|
||||||
return None
|
return None
|
||||||
|
@@ -74,6 +74,7 @@ async def cloud_fixture() -> AsyncGenerator[MagicMock]:
|
|||||||
mock_cloud.payments = MagicMock(
|
mock_cloud.payments = MagicMock(
|
||||||
spec=payments_api.PaymentsApi,
|
spec=payments_api.PaymentsApi,
|
||||||
subscription_info=AsyncMock(),
|
subscription_info=AsyncMock(),
|
||||||
|
migrate_paypal_agreement=AsyncMock(),
|
||||||
)
|
)
|
||||||
mock_cloud.ice_servers = MagicMock(
|
mock_cloud.ice_servers = MagicMock(
|
||||||
spec=IceServers,
|
spec=IceServers,
|
||||||
|
@@ -4,6 +4,7 @@ from datetime import timedelta
|
|||||||
from http import HTTPStatus
|
from http import HTTPStatus
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
|
from hass_nabucasa.payments_api import PaymentsApiError
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant.components.cloud.const import DOMAIN
|
from homeassistant.components.cloud.const import DOMAIN
|
||||||
@@ -210,7 +211,13 @@ async def test_legacy_subscription_repair_flow_timeout(
|
|||||||
"preview": None,
|
"preview": None,
|
||||||
}
|
}
|
||||||
|
|
||||||
with patch("homeassistant.components.cloud.repairs.MAX_RETRIES", new=0):
|
with (
|
||||||
|
patch("homeassistant.components.cloud.repairs.MAX_RETRIES", new=0),
|
||||||
|
patch(
|
||||||
|
"hass_nabucasa.payments_api.PaymentsApi.migrate_paypal_agreement",
|
||||||
|
side_effect=PaymentsApiError("some error", status=403),
|
||||||
|
),
|
||||||
|
):
|
||||||
resp = await client.post(f"/api/repairs/issues/fix/{flow_id}")
|
resp = await client.post(f"/api/repairs/issues/fix/{flow_id}")
|
||||||
assert resp.status == HTTPStatus.OK
|
assert resp.status == HTTPStatus.OK
|
||||||
data = await resp.json()
|
data = await resp.json()
|
||||||
|
@@ -25,6 +25,7 @@ async def mocked_cloud_object(hass: HomeAssistant) -> Cloud:
|
|||||||
payments=Mock(
|
payments=Mock(
|
||||||
spec=payments_api.PaymentsApi,
|
spec=payments_api.PaymentsApi,
|
||||||
subscription_info=AsyncMock(),
|
subscription_info=AsyncMock(),
|
||||||
|
migrate_paypal_agreement=AsyncMock(),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -52,10 +53,7 @@ async def test_migrate_paypal_agreement_with_timeout_error(
|
|||||||
mocked_cloud: Cloud,
|
mocked_cloud: Cloud,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test that we handle timeout error."""
|
"""Test that we handle timeout error."""
|
||||||
aioclient_mock.post(
|
mocked_cloud.payments.migrate_paypal_agreement.side_effect = TimeoutError()
|
||||||
"https://accounts.nabucasa.com/payments/migrate_paypal_agreement",
|
|
||||||
exc=TimeoutError(),
|
|
||||||
)
|
|
||||||
|
|
||||||
assert await async_migrate_paypal_agreement(mocked_cloud) is None
|
assert await async_migrate_paypal_agreement(mocked_cloud) is None
|
||||||
assert (
|
assert (
|
||||||
|
Reference in New Issue
Block a user