Allow managing cloud webhook (#18672)

* Add cloud webhook support

* Simplify payload

* Add cloud http api tests

* Fix tests

* Lint

* Handle cloud webhooks

* Fix things

* Fix name

* Rename it to cloudhook

* Final rename

* Final final rename?

* Fix docstring

* More tests

* Lint

* Add types

* Fix things
This commit is contained in:
Paulus Schoutsen 2018-11-26 14:10:18 +01:00 committed by GitHub
parent 4a661e351f
commit 7848381f43
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 611 additions and 39 deletions

View file

@ -527,3 +527,45 @@ async def test_websocket_update_preferences(hass, hass_ws_client,
assert not setup_api[PREF_ENABLE_GOOGLE]
assert not setup_api[PREF_ENABLE_ALEXA]
assert not setup_api[PREF_GOOGLE_ALLOW_UNLOCK]
async def test_enabling_webhook(hass, hass_ws_client, setup_api):
"""Test we call right code to enable webhooks."""
hass.data[DOMAIN].id_token = jwt.encode({
'email': 'hello@home-assistant.io',
'custom:sub-exp': '2018-01-03'
}, 'test')
client = await hass_ws_client(hass)
with patch('homeassistant.components.cloud.cloudhooks.Cloudhooks'
'.async_create', return_value=mock_coro()) as mock_enable:
await client.send_json({
'id': 5,
'type': 'cloud/cloudhook/create',
'webhook_id': 'mock-webhook-id',
})
response = await client.receive_json()
assert response['success']
assert len(mock_enable.mock_calls) == 1
assert mock_enable.mock_calls[0][1][0] == 'mock-webhook-id'
async def test_disabling_webhook(hass, hass_ws_client, setup_api):
"""Test we call right code to disable webhooks."""
hass.data[DOMAIN].id_token = jwt.encode({
'email': 'hello@home-assistant.io',
'custom:sub-exp': '2018-01-03'
}, 'test')
client = await hass_ws_client(hass)
with patch('homeassistant.components.cloud.cloudhooks.Cloudhooks'
'.async_delete', return_value=mock_coro()) as mock_disable:
await client.send_json({
'id': 5,
'type': 'cloud/cloudhook/delete',
'webhook_id': 'mock-webhook-id',
})
response = await client.receive_json()
assert response['success']
assert len(mock_disable.mock_calls) == 1
assert mock_disable.mock_calls[0][1][0] == 'mock-webhook-id'