Migrate freedns tests from coroutine to async/await (#30390)

This commit is contained in:
Franck Nijhof 2020-01-02 21:22:30 +01:00 committed by Andrew Sayre
parent 5b2b86987b
commit 332cbbd8b1

View File

@ -1,6 +1,4 @@
"""Test the FreeDNS component.""" """Test the FreeDNS component."""
import asyncio
import pytest import pytest
from homeassistant.components import freedns from homeassistant.components import freedns
@ -37,8 +35,7 @@ def setup_freedns(hass, aioclient_mock):
) )
@asyncio.coroutine async def test_setup(hass, aioclient_mock):
def test_setup(hass, aioclient_mock):
"""Test setup works if update passes.""" """Test setup works if update passes."""
params = {} params = {}
params[ACCESS_TOKEN] = "" params[ACCESS_TOKEN] = ""
@ -46,7 +43,7 @@ def test_setup(hass, aioclient_mock):
UPDATE_URL, params=params, text="ERROR: Address has not changed." UPDATE_URL, params=params, text="ERROR: Address has not changed."
) )
result = yield from async_setup_component( result = await async_setup_component(
hass, hass,
freedns.DOMAIN, freedns.DOMAIN,
{ {
@ -60,18 +57,17 @@ def test_setup(hass, aioclient_mock):
assert aioclient_mock.call_count == 1 assert aioclient_mock.call_count == 1
async_fire_time_changed(hass, utcnow() + UPDATE_INTERVAL) async_fire_time_changed(hass, utcnow() + UPDATE_INTERVAL)
yield from hass.async_block_till_done() await hass.async_block_till_done()
assert aioclient_mock.call_count == 2 assert aioclient_mock.call_count == 2
@asyncio.coroutine async def test_setup_fails_if_wrong_token(hass, aioclient_mock):
def test_setup_fails_if_wrong_token(hass, aioclient_mock):
"""Test setup fails if first update fails through wrong token.""" """Test setup fails if first update fails through wrong token."""
params = {} params = {}
params[ACCESS_TOKEN] = "" params[ACCESS_TOKEN] = ""
aioclient_mock.get(UPDATE_URL, params=params, text="ERROR: Invalid update URL (2)") aioclient_mock.get(UPDATE_URL, params=params, text="ERROR: Invalid update URL (2)")
result = yield from async_setup_component( result = await async_setup_component(
hass, hass,
freedns.DOMAIN, freedns.DOMAIN,
{ {