Migrate twilio webhooks to the webhook component (#17715)
* Migrate twilio webhooks to the webhook component * Fix typos in twilio * Mock out twilio in the tests * Lint * Fix regression in twilio response
This commit is contained in:
parent
599390d985
commit
5024a80d61
8 changed files with 155 additions and 59 deletions
41
tests/components/twilio/test_init.py
Normal file
41
tests/components/twilio/test_init.py
Normal file
|
@ -0,0 +1,41 @@
|
|||
"""Test the init file of Twilio."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from homeassistant import data_entry_flow
|
||||
from homeassistant.components import twilio
|
||||
from homeassistant.core import callback
|
||||
from tests.common import MockDependency
|
||||
|
||||
|
||||
@MockDependency('twilio', 'rest')
|
||||
@MockDependency('twilio', 'twiml')
|
||||
async def test_config_flow_registers_webhook(hass, aiohttp_client):
|
||||
"""Test setting up Twilio and sending webhook."""
|
||||
with patch('homeassistant.util.get_local_ip', return_value='example.com'):
|
||||
result = await hass.config_entries.flow.async_init('twilio', context={
|
||||
'source': 'user'
|
||||
})
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_FORM, result
|
||||
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result['flow_id'], {})
|
||||
assert result['type'] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY
|
||||
webhook_id = result['result'].data['webhook_id']
|
||||
|
||||
twilio_events = []
|
||||
|
||||
@callback
|
||||
def handle_event(event):
|
||||
"""Handle Twilio event."""
|
||||
twilio_events.append(event)
|
||||
|
||||
hass.bus.async_listen(twilio.RECEIVED_DATA, handle_event)
|
||||
|
||||
client = await aiohttp_client(hass.http.app)
|
||||
await client.post('/api/webhook/{}'.format(webhook_id), data={
|
||||
'hello': 'twilio'
|
||||
})
|
||||
|
||||
assert len(twilio_events) == 1
|
||||
assert twilio_events[0].data['webhook_id'] == webhook_id
|
||||
assert twilio_events[0].data['hello'] == 'twilio'
|
Loading…
Add table
Add a link
Reference in a new issue