-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
62 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,69 @@ | ||
"""Test cloud webhooks.""" | ||
from unittest.mock import Mock, patch | ||
|
||
import pytest | ||
|
||
from homeassistant.components.cloud import prefs, webhooks | ||
|
||
from tests.common import mock_coro | ||
|
||
|
||
def test_publish_webhooks_on_connect(): | ||
"""Test that we publish webhooks when connected to cloud.""" | ||
assert False | ||
@pytest.fixture | ||
def mock_webhooks(hass): | ||
cloud = Mock() | ||
cloud.hass = hass | ||
cloud.hass.async_add_executor_job = Mock(return_value=mock_coro()) | ||
cloud.iot = Mock(async_send_message=Mock(return_value=mock_coro())) | ||
cloud.webhook_create_url = 'https://webhook-create.url' | ||
cloud.prefs = prefs.CloudPreferences(hass) | ||
hass.loop.run_until_complete(cloud.prefs.async_initialize(True)) | ||
return webhooks.Webhooks(cloud) | ||
|
||
|
||
def test_enable(): | ||
async def test_enable(mock_webhooks, aioclient_mock): | ||
"""Test enabling webhooks.""" | ||
assert False | ||
aioclient_mock.post('https://webhook-create.url', json={ | ||
'webhook_id': 'mock-cloud-id', | ||
'url': 'https://hooks.nabu.casa/ZXCZCXZ', | ||
}) | ||
|
||
hook = { | ||
'webhook_id': 'mock-webhook-id', | ||
'cloud_id': 'mock-cloud-id', | ||
'cloud_url': 'https://hooks.nabu.casa/ZXCZCXZ', | ||
} | ||
|
||
assert hook == await mock_webhooks.async_enable('mock-webhook-id') | ||
|
||
assert mock_webhooks.cloud.prefs.webhooks == { | ||
'mock-webhook-id': hook | ||
} | ||
|
||
publish_calls = mock_webhooks.cloud.iot.async_send_message.mock_calls | ||
assert len(publish_calls) == 1 | ||
assert publish_calls[0][1][0] == 'webhook-register' | ||
assert publish_calls[0][1][1] == { | ||
'webhook_ids': ['mock-cloud-id'] | ||
} | ||
|
||
|
||
async def test_disable(mock_webhooks): | ||
"""Test disabling webhooks.""" | ||
mock_webhooks.cloud.prefs._prefs['webhooks'] = { | ||
'mock-webhook-id': { | ||
'webhook_id': 'mock-webhook-id', | ||
'cloud_id': 'mock-cloud-id', | ||
'cloud_url': 'https://hooks.nabu.casa/ZXCZCXZ', | ||
} | ||
} | ||
|
||
await mock_webhooks.async_disable('mock-webhook-id') | ||
|
||
assert mock_webhooks.cloud.prefs.webhooks == {} | ||
|
||
def test_disable(): | ||
"""Test webhooks.""" | ||
assert False | ||
publish_calls = mock_webhooks.cloud.iot.async_send_message.mock_calls | ||
assert len(publish_calls) == 1 | ||
assert publish_calls[0][1][0] == 'webhook-register' | ||
assert publish_calls[0][1][1] == { | ||
'webhook_ids': [] | ||
} |