Skip to content

Commit

Permalink
Add async_migrate_paypal_agreement function to cloud_api (#380)
Browse files Browse the repository at this point in the history
* Add async_migrate_subscription function to cloud_api

* Bump version to 0.57.0

* Adjust after rebase

* Update tests/test_cloud_api.py

* Update tests/test_cloud_api.py
  • Loading branch information
ludeeus authored Nov 30, 2022
1 parent 59b8339 commit e4d8aee
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
12 changes: 12 additions & 0 deletions hass_nabucasa/cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,15 @@ async def async_subscription_info(cloud):
await cloud.auth.async_renew_access_token()

return data


@_check_token
async def async_migrate_paypal_agreement(cloud):
"""Migrate a paypal agreement from legacy."""
resp = await cloud.websession.post(
f"https://{cloud.accounts_server}/migrate_paypal_agreement",
headers={"authorization": cloud.id_token},
)
_do_log_response(resp)
resp.raise_for_status()
return await resp.json()
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from setuptools import setup

VERSION = "0.56.0"
VERSION = "0.57.0"

setup(
name="hass-nabucasa",
Expand Down
18 changes: 18 additions & 0 deletions tests/test_cloud_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,21 @@ async def test_subscription_info(auth_cloud_mock, aioclient_mock):
"provider": "mock-provider",
}
assert len(mock_renew.mock_calls) == 1


async def test_migrate_paypal_agreement(auth_cloud_mock, aioclient_mock):
"""Test a paypal agreement from legacy."""
aioclient_mock.post(
"https://example.com/migrate_paypal_agreement",
json={
"url": "https://example.com/some/path",
},
)
auth_cloud_mock.id_token = "mock-id-token"
auth_cloud_mock.accounts_server = "example.com"

data = await cloud_api.async_migrate_paypal_agreement(auth_cloud_mock)
assert len(aioclient_mock.mock_calls) == 1
assert data == {
"url": "https://example.com/some/path",
}

0 comments on commit e4d8aee

Please sign in to comment.