Expose create/delete cloudhook (#21606)
* Expose create/delete cloudhook * Make sure we dont publish cloudhooks when not connected
This commit is contained in:
parent
c25cbccca9
commit
f5ed6432eb
6 changed files with 153 additions and 6 deletions
|
@ -5,6 +5,7 @@ from unittest.mock import patch, MagicMock, mock_open
|
|||
|
||||
import pytest
|
||||
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.components import cloud
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
|
@ -175,3 +176,71 @@ def test_subscription_not_expired(hass):
|
|||
patch('homeassistant.util.dt.utcnow',
|
||||
return_value=utcnow().replace(year=2017, month=11, day=9)):
|
||||
assert not cl.subscription_expired
|
||||
|
||||
|
||||
async def test_create_cloudhook_no_login(hass):
|
||||
"""Test create cloudhook when not logged in."""
|
||||
assert await async_setup_component(hass, 'cloud', {})
|
||||
coro = mock_coro({'yo': 'hey'})
|
||||
with patch('homeassistant.components.cloud.cloudhooks.'
|
||||
'Cloudhooks.async_create', return_value=coro) as mock_create, \
|
||||
pytest.raises(cloud.CloudNotAvailable):
|
||||
await hass.components.cloud.async_create_cloudhook('hello')
|
||||
|
||||
assert len(mock_create.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_delete_cloudhook_no_login(hass):
|
||||
"""Test delete cloudhook when not logged in."""
|
||||
assert await async_setup_component(hass, 'cloud', {})
|
||||
coro = mock_coro({'yo': 'hey'})
|
||||
with patch('homeassistant.components.cloud.cloudhooks.'
|
||||
'Cloudhooks.async_delete', return_value=coro) as mock_delete, \
|
||||
pytest.raises(cloud.CloudNotAvailable):
|
||||
await hass.components.cloud.async_delete_cloudhook('hello')
|
||||
|
||||
assert len(mock_delete.mock_calls) == 0
|
||||
|
||||
|
||||
async def test_create_cloudhook(hass):
|
||||
"""Test create cloudhook."""
|
||||
assert await async_setup_component(hass, 'cloud', {})
|
||||
coro = mock_coro({'yo': 'hey'})
|
||||
with patch('homeassistant.components.cloud.cloudhooks.'
|
||||
'Cloudhooks.async_create', return_value=coro) as mock_create, \
|
||||
patch('homeassistant.components.cloud.async_is_logged_in',
|
||||
return_value=True):
|
||||
result = await hass.components.cloud.async_create_cloudhook('hello')
|
||||
|
||||
assert result == {'yo': 'hey'}
|
||||
assert len(mock_create.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_delete_cloudhook(hass):
|
||||
"""Test delete cloudhook."""
|
||||
assert await async_setup_component(hass, 'cloud', {})
|
||||
coro = mock_coro({'yo': 'hey'})
|
||||
with patch('homeassistant.components.cloud.cloudhooks.'
|
||||
'Cloudhooks.async_delete', return_value=coro) as mock_delete, \
|
||||
patch('homeassistant.components.cloud.async_is_logged_in',
|
||||
return_value=True):
|
||||
result = await hass.components.cloud.async_delete_cloudhook('hello')
|
||||
|
||||
assert result == {'yo': 'hey'}
|
||||
assert len(mock_delete.mock_calls) == 1
|
||||
|
||||
|
||||
async def test_async_logged_in(hass):
|
||||
"""Test if is_logged_in works."""
|
||||
# Cloud not loaded
|
||||
assert hass.components.cloud.async_is_logged_in() is False
|
||||
|
||||
assert await async_setup_component(hass, 'cloud', {})
|
||||
|
||||
# Cloud loaded, not logged in
|
||||
assert hass.components.cloud.async_is_logged_in() is False
|
||||
|
||||
hass.data['cloud'].id_token = "some token"
|
||||
|
||||
# Cloud loaded, logged in
|
||||
assert hass.components.cloud.async_is_logged_in() is True
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue