Use a future for mock coro (#34989)

This commit is contained in:
Paulus Schoutsen 2020-04-30 16:31:00 -07:00 committed by GitHub
parent ba7391528f
commit 76f392476b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
26 changed files with 154 additions and 262 deletions

View file

@ -5,34 +5,31 @@ from homeassistant import data_entry_flow
from homeassistant.components import twilio
from homeassistant.core import callback
from tests.common import MockDependency
async def test_config_flow_registers_webhook(hass, aiohttp_client):
"""Test setting up Twilio and sending webhook."""
with MockDependency("twilio", "rest"), MockDependency("twilio", "twiml"):
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
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"]
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 = []
twilio_events = []
@callback
def handle_event(event):
"""Handle Twilio event."""
twilio_events.append(event)
@callback
def handle_event(event):
"""Handle Twilio event."""
twilio_events.append(event)
hass.bus.async_listen(twilio.RECEIVED_DATA, handle_event)
hass.bus.async_listen(twilio.RECEIVED_DATA, handle_event)
client = await aiohttp_client(hass.http.app)
await client.post(f"/api/webhook/{webhook_id}", data={"hello": "twilio"})
client = await aiohttp_client(hass.http.app)
await client.post(f"/api/webhook/{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"
assert len(twilio_events) == 1
assert twilio_events[0].data["webhook_id"] == webhook_id
assert twilio_events[0].data["hello"] == "twilio"