mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Add tests for Jellyfin init (#79968)
This commit is contained in:
parent
84acb416b8
commit
7fae85ee85
@ -612,7 +612,6 @@ omit =
|
||||
homeassistant/components/izone/__init__.py
|
||||
homeassistant/components/izone/climate.py
|
||||
homeassistant/components/izone/discovery.py
|
||||
homeassistant/components/jellyfin/__init__.py
|
||||
homeassistant/components/jellyfin/media_source.py
|
||||
homeassistant/components/joaoapps_join/*
|
||||
homeassistant/components/juicenet/__init__.py
|
||||
|
@ -10,7 +10,28 @@ from jellyfin_apiclient_python.configuration import Config
|
||||
from jellyfin_apiclient_python.connection_manager import ConnectionManager
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.jellyfin.const import DOMAIN
|
||||
from homeassistant.const import CONF_PASSWORD, CONF_URL, CONF_USERNAME
|
||||
|
||||
from . import load_json_fixture
|
||||
from .const import TEST_PASSWORD, TEST_URL, TEST_USERNAME
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_config_entry() -> MockConfigEntry:
|
||||
"""Return the default mocked config entry."""
|
||||
return MockConfigEntry(
|
||||
title="Jellyfin",
|
||||
domain=DOMAIN,
|
||||
data={
|
||||
CONF_URL: TEST_URL,
|
||||
CONF_USERNAME: TEST_USERNAME,
|
||||
CONF_PASSWORD: TEST_PASSWORD,
|
||||
},
|
||||
unique_id="USER-UUID",
|
||||
)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
|
48
tests/components/jellyfin/test_init.py
Normal file
48
tests/components/jellyfin/test_init.py
Normal file
@ -0,0 +1,48 @@
|
||||
"""Tests for the Jellyfin integration."""
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homeassistant.components.jellyfin.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import async_load_json_fixture
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_config_entry_not_ready(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_jellyfin: MagicMock,
|
||||
mock_client: MagicMock,
|
||||
) -> None:
|
||||
"""Test the Jellyfin configuration entry not ready."""
|
||||
mock_client.auth.connect_to_address.return_value = await async_load_json_fixture(
|
||||
hass,
|
||||
"auth-connect-address-failure.json",
|
||||
)
|
||||
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state is ConfigEntryState.SETUP_RETRY
|
||||
|
||||
|
||||
async def test_load_unload_config_entry(
|
||||
hass: HomeAssistant,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
mock_jellyfin: MagicMock,
|
||||
) -> None:
|
||||
"""Test the Jellyfin configuration entry loading/unloading."""
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.entry_id in hass.data[DOMAIN]
|
||||
assert mock_config_entry.state is ConfigEntryState.LOADED
|
||||
|
||||
await hass.config_entries.async_unload(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_config_entry.entry_id not in hass.data[DOMAIN]
|
||||
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
|
Loading…
x
Reference in New Issue
Block a user