mirror of
https://github.com/home-assistant/core.git
synced 2025-07-14 16:57:10 +00:00
Fix tests
This commit is contained in:
parent
7be197b845
commit
b81260e912
@ -44,18 +44,23 @@ def hassio_stubs(hassio_env, hass, hass_client, aioclient_mock):
|
|||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hassio_client(hassio_stubs, hass, hass_client):
|
def hassio_client(hassio_stubs, hass, hass_client):
|
||||||
|
"""Return a Hass.io HTTP client."""
|
||||||
yield hass.loop.run_until_complete(hass_client())
|
yield hass.loop.run_until_complete(hass_client())
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hassio_noauth_client(hassio_stubs, hass, aiohttp_client):
|
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))
|
yield hass.loop.run_until_complete(aiohttp_client(hass.http.app))
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def hassio_handler(hass, aioclient_mock):
|
def hassio_handler(hass, aioclient_mock):
|
||||||
"""Create mock hassio handler."""
|
"""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}):
|
with patch.dict(os.environ, {'HASSIO_TOKEN': HASSIO_TOKEN}):
|
||||||
yield HassIO(hass.loop, websession, "127.0.0.1")
|
yield HassIO(hass.loop, websession, "127.0.0.1")
|
||||||
|
@ -10,8 +10,6 @@ from . import API_PASSWORD
|
|||||||
|
|
||||||
async def test_login_success(hass, hassio_client):
|
async def test_login_success(hass, hassio_client):
|
||||||
"""Test no auth needed for ."""
|
"""Test no auth needed for ."""
|
||||||
await register_auth_provider(hass, {'type': 'homeassistant'})
|
|
||||||
|
|
||||||
with patch('homeassistant.auth.providers.homeassistant.'
|
with patch('homeassistant.auth.providers.homeassistant.'
|
||||||
'HassAuthProvider.async_validate_login',
|
'HassAuthProvider.async_validate_login',
|
||||||
Mock(return_value=mock_coro())) as mock_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):
|
async def test_login_error(hass, hassio_client):
|
||||||
"""Test no auth needed for error."""
|
"""Test no auth needed for error."""
|
||||||
await register_auth_provider(hass, {'type': 'homeassistant'})
|
|
||||||
|
|
||||||
with patch('homeassistant.auth.providers.homeassistant.'
|
with patch('homeassistant.auth.providers.homeassistant.'
|
||||||
'HassAuthProvider.async_validate_login',
|
'HassAuthProvider.async_validate_login',
|
||||||
Mock(side_effect=HomeAssistantError())) as mock_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):
|
async def test_login_no_data(hass, hassio_client):
|
||||||
"""Test auth with no data -> error."""
|
"""Test auth with no data -> error."""
|
||||||
await register_auth_provider(hass, {'type': 'homeassistant'})
|
|
||||||
|
|
||||||
with patch('homeassistant.auth.providers.homeassistant.'
|
with patch('homeassistant.auth.providers.homeassistant.'
|
||||||
'HassAuthProvider.async_validate_login',
|
'HassAuthProvider.async_validate_login',
|
||||||
Mock(side_effect=HomeAssistantError())) as mock_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):
|
async def test_login_no_username(hass, hassio_client):
|
||||||
"""Test auth with no username in data -> error."""
|
"""Test auth with no username in data -> error."""
|
||||||
await register_auth_provider(hass, {'type': 'homeassistant'})
|
|
||||||
|
|
||||||
with patch('homeassistant.auth.providers.homeassistant.'
|
with patch('homeassistant.auth.providers.homeassistant.'
|
||||||
'HassAuthProvider.async_validate_login',
|
'HassAuthProvider.async_validate_login',
|
||||||
Mock(side_effect=HomeAssistantError())) as mock_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):
|
async def test_login_success_extra(hass, hassio_client):
|
||||||
"""Test auth with extra data."""
|
"""Test auth with extra data."""
|
||||||
await register_auth_provider(hass, {'type': 'homeassistant'})
|
|
||||||
|
|
||||||
with patch('homeassistant.auth.providers.homeassistant.'
|
with patch('homeassistant.auth.providers.homeassistant.'
|
||||||
'HassAuthProvider.async_validate_login',
|
'HassAuthProvider.async_validate_login',
|
||||||
Mock(return_value=mock_coro())) as mock_login:
|
Mock(return_value=mock_coro())) as mock_login:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user