From b81260e9128eb30428af67baba560831f22d941c Mon Sep 17 00:00:00 2001 From: Paulus Schoutsen Date: Fri, 11 Jan 2019 10:10:36 -0800 Subject: [PATCH] Fix tests --- tests/components/hassio/conftest.py | 7 ++++++- tests/components/hassio/test_auth.py | 10 ---------- 2 files changed, 6 insertions(+), 11 deletions(-) diff --git a/tests/components/hassio/conftest.py b/tests/components/hassio/conftest.py index 17a26b4fd2f..f69be17a9e7 100644 --- a/tests/components/hassio/conftest.py +++ b/tests/components/hassio/conftest.py @@ -44,18 +44,23 @@ def hassio_stubs(hassio_env, hass, hass_client, aioclient_mock): @pytest.fixture def hassio_client(hassio_stubs, hass, hass_client): + """Return a Hass.io HTTP client.""" yield hass.loop.run_until_complete(hass_client()) @pytest.fixture def hassio_noauth_client(hassio_stubs, hass, aiohttp_client): + """Return a Hass.io HTTP client without auth.""" yield hass.loop.run_until_complete(aiohttp_client(hass.http.app)) @pytest.fixture def hassio_handler(hass, aioclient_mock): """Create mock hassio handler.""" - websession = hass.helpers.aiohttp_client.async_get_clientsession() + async def get_client_session(): + return hass.helpers.aiohttp_client.async_get_clientsession() + + websession = hass.loop.run_until_complete(get_client_session()) with patch.dict(os.environ, {'HASSIO_TOKEN': HASSIO_TOKEN}): yield HassIO(hass.loop, websession, "127.0.0.1") diff --git a/tests/components/hassio/test_auth.py b/tests/components/hassio/test_auth.py index fdf3230dedc..44eedde5d1d 100644 --- a/tests/components/hassio/test_auth.py +++ b/tests/components/hassio/test_auth.py @@ -10,8 +10,6 @@ from . import API_PASSWORD async def test_login_success(hass, hassio_client): """Test no auth needed for .""" - await register_auth_provider(hass, {'type': 'homeassistant'}) - with patch('homeassistant.auth.providers.homeassistant.' 'HassAuthProvider.async_validate_login', Mock(return_value=mock_coro())) as mock_login: @@ -34,8 +32,6 @@ async def test_login_success(hass, hassio_client): async def test_login_error(hass, hassio_client): """Test no auth needed for error.""" - await register_auth_provider(hass, {'type': 'homeassistant'}) - with patch('homeassistant.auth.providers.homeassistant.' 'HassAuthProvider.async_validate_login', Mock(side_effect=HomeAssistantError())) as mock_login: @@ -58,8 +54,6 @@ async def test_login_error(hass, hassio_client): async def test_login_no_data(hass, hassio_client): """Test auth with no data -> error.""" - await register_auth_provider(hass, {'type': 'homeassistant'}) - with patch('homeassistant.auth.providers.homeassistant.' 'HassAuthProvider.async_validate_login', Mock(side_effect=HomeAssistantError())) as mock_login: @@ -77,8 +71,6 @@ async def test_login_no_data(hass, hassio_client): async def test_login_no_username(hass, hassio_client): """Test auth with no username in data -> error.""" - await register_auth_provider(hass, {'type': 'homeassistant'}) - with patch('homeassistant.auth.providers.homeassistant.' 'HassAuthProvider.async_validate_login', Mock(side_effect=HomeAssistantError())) as mock_login: @@ -100,8 +92,6 @@ async def test_login_no_username(hass, hassio_client): async def test_login_success_extra(hass, hassio_client): """Test auth with extra data.""" - await register_auth_provider(hass, {'type': 'homeassistant'}) - with patch('homeassistant.auth.providers.homeassistant.' 'HassAuthProvider.async_validate_login', Mock(return_value=mock_coro())) as mock_login: