Skip to content

Commit

Permalink
Fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
balloob committed Nov 26, 2018
1 parent c64ee21 commit 65ec2c7
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 11 deletions.
4 changes: 1 addition & 3 deletions homeassistant/components/cloud/cloud_api.py
Expand Up @@ -16,12 +16,10 @@ async def check_token(cloud, *args):


@_check_token
async def async_create_cloudhook(cloud, webhook_id):
async def async_create_cloudhook(cloud):
"""Create a cloudhook."""
websession = cloud.hass.helpers.aiohttp_client.async_get_clientsession()
return await websession.post(
cloud.cloudhook_create_url, headers={
'authorization': cloud.id_token
}, json={
'webhook_id': webhook_id
})
3 changes: 1 addition & 2 deletions homeassistant/components/cloud/cloudhooks.py
Expand Up @@ -32,8 +32,7 @@ async def async_create(self, webhook_id):

# Create cloud hook
with async_timeout.timeout(10):
resp = await cloud_api.async_create_cloudhook(
self.cloud, webhook_id)
resp = await cloud_api.async_create_cloudhook(self.cloud)

data = await resp.json()
cloudhook_id = data['cloudhook_id']
Expand Down
4 changes: 2 additions & 2 deletions homeassistant/util/aiohttp.py
Expand Up @@ -22,7 +22,7 @@ def __init__(self, content: bytes, method: str = 'GET',
self._content = content

@property
def query(self) -> MultiDict[str]:
def query(self) -> 'MultiDict[str]':
"""Return a dictionary with the query variables."""
return MultiDict(parse_qsl(self.query_string, keep_blank_values=True))

Expand All @@ -35,7 +35,7 @@ async def json(self) -> Any:
"""Return the body as JSON."""
return json.loads(self._text)

async def post(self) -> MultiDict[str]:
async def post(self) -> 'MultiDict[str]':
"""Return POST parameters."""
return MultiDict(parse_qsl(self._text, keep_blank_values=True))

Expand Down
13 changes: 9 additions & 4 deletions tests/components/cloud/test_cloud_api.py
Expand Up @@ -14,15 +14,20 @@ def mock_check_token():
yield mock_check_token


async def test_create_webhook(hass, aioclient_mock):
"""Test creating a webhook."""
async def test_create_cloudhook(hass, aioclient_mock):
"""Test creating a cloudhook."""
aioclient_mock.post('https://example.com/bla', json={
'webhook_id': 'mock-webhook'
'cloudhook_id': 'mock-webhook',
'url': 'https://blabla'
})
cloud = Mock(
hass=hass,
id_token='mock-id-token',
cloudhook_create_url='https://example.com/bla',
)
await cloud_api.async_create_cloudhook(cloud, 'mock-webhook')
resp = await cloud_api.async_create_cloudhook(cloud)
assert len(aioclient_mock.mock_calls) == 1
assert await resp.json() == {
'cloudhook_id': 'mock-webhook',
'url': 'https://blabla'
}

0 comments on commit 65ec2c7

Please sign in to comment.