Add prusalink test cases and fix config flow (#77544)
This commit is contained in:
parent
b0a05530b0
commit
c11925f7a9
4 changed files with 69 additions and 16 deletions
|
@ -1,16 +1,23 @@
|
|||
"""Test setting up and unloading PrusaLink."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import patch
|
||||
|
||||
from pyprusalink import InvalidAuth, PrusaLinkError
|
||||
import pytest
|
||||
|
||||
from homeassistant.config_entries import ConfigEntry, ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util.dt import utcnow
|
||||
|
||||
from tests.common import async_fire_time_changed
|
||||
|
||||
|
||||
async def test_sensors_no_job(
|
||||
async def test_unloading(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: ConfigEntry,
|
||||
mock_api,
|
||||
):
|
||||
"""Test sensors while no job active."""
|
||||
"""Test unloading prusalink."""
|
||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
|
@ -21,3 +28,25 @@ async def test_sensors_no_job(
|
|||
|
||||
for state in hass.states.async_all():
|
||||
assert state.state == "unavailable"
|
||||
|
||||
|
||||
@pytest.mark.parametrize("exception", [InvalidAuth, PrusaLinkError])
|
||||
async def test_failed_update(
|
||||
hass: HomeAssistant, mock_config_entry: ConfigEntry, mock_api, exception
|
||||
):
|
||||
"""Test failed update marks prusalink unavailable."""
|
||||
assert await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
assert mock_config_entry.state == ConfigEntryState.LOADED
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.prusalink.PrusaLink.get_printer",
|
||||
side_effect=exception,
|
||||
), patch(
|
||||
"homeassistant.components.prusalink.PrusaLink.get_job",
|
||||
side_effect=exception,
|
||||
):
|
||||
async_fire_time_changed(hass, utcnow() + timedelta(seconds=30), fire_all=True)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
for state in hass.states.async_all():
|
||||
assert state.state == "unavailable"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue