Fix cloud const (#19052)

* Fix cloud const

* Fix tests
This commit is contained in:
Paulus Schoutsen 2018-12-06 09:20:53 +01:00 committed by GitHub
parent 26a38f1fae
commit 962358bf87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 23 additions and 1 deletions

View File

@ -1,8 +1,11 @@
"""Cloud APIs."""
from functools import wraps
import logging
from . import auth_api
_LOGGER = logging.getLogger(__name__)
def _check_token(func):
"""Decorate a function to verify valid token."""
@ -15,7 +18,21 @@ def _check_token(func):
return check_token
def _log_response(func):
"""Decorate a function to log bad responses."""
@wraps(func)
async def log_response(*args):
"""Log response if it's bad."""
resp = await func(*args)
meth = _LOGGER.debug if resp.status < 400 else _LOGGER.warning
meth('Fetched %s (%s)', resp.url, resp.status)
return resp
return log_response
@_check_token
@_log_response
async def async_create_cloudhook(cloud):
"""Create a cloudhook."""
websession = cloud.hass.helpers.aiohttp_client.async_get_clientsession()

View File

@ -18,7 +18,7 @@ SERVERS = {
'amazonaws.com/prod/smart_home_sync'),
'subscription_info_url': ('https://stripe-api.nabucasa.com/payments/'
'subscription_info'),
'cloudhook_create_url': 'https://webhook-api.nabucasa.com/generate'
'cloudhook_create_url': 'https://webhooks-api.nabucasa.com/generate'
}
}

View File

@ -177,6 +177,11 @@ class AiohttpClientMockResponse:
"""Return dict of cookies."""
return self._cookies
@property
def url(self):
"""Return yarl of URL."""
return self._url
@property
def content(self):
"""Return content."""