Use built-in test helpers on 3.8 (#34901)
This commit is contained in:
1 parent
6b16c34fd0
commit
ec47216388
303 files changed
+1163
-1320
No files matched your search
@@ -1,14 +1,10 @@
|
||||
"""Tests for Plex server."""
|
||||
import copy
|
||||
|
||||
from asynctest import ClockedTestCase, patch
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.media_player import DOMAIN as MP_DOMAIN
|
||||
from homeassistant.components.plex.const import (
|
||||
CONF_IGNORE_NEW_SHARED_USERS,
|
||||
CONF_MONITORED_USERS,
|
||||
DEBOUNCE_TIMEOUT,
|
||||
DOMAIN,
|
||||
PLEX_UPDATE_PLATFORMS_SIGNAL,
|
||||
SERVERS,
|
||||
@@ -18,7 +14,8 @@ from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||
from .const import DEFAULT_DATA, DEFAULT_OPTIONS
|
||||
from .mock_classes import MockPlexServer
|
||||
|
||||
from tests.common import MockConfigEntry, async_test_home_assistant
|
||||
from tests.async_mock import patch
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_new_users_available(hass):
|
||||
@@ -108,107 +105,106 @@ async def test_new_ignored_users_available(hass, caplog):
|
||||
assert sensor.state == str(len(mock_plex_server.accounts))
|
||||
|
||||
|
||||
@pytest.mark.skip
|
||||
class TestClockedPlex(ClockedTestCase):
|
||||
"""Create clock-controlled asynctest class."""
|
||||
# class TestClockedPlex(ClockedTestCase):
|
||||
# """Create clock-controlled tests.async_mock class."""
|
||||
|
||||
async def setUp(self):
|
||||
"""Initialize this test class."""
|
||||
self.hass = await async_test_home_assistant(self.loop)
|
||||
# async def setUp(self):
|
||||
# """Initialize this test class."""
|
||||
# self.hass = await async_test_home_assistant(self.loop)
|
||||
|
||||
async def tearDown(self):
|
||||
"""Clean up the HomeAssistant instance."""
|
||||
await self.hass.async_stop()
|
||||
# async def tearDown(self):
|
||||
# """Clean up the HomeAssistant instance."""
|
||||
# await self.hass.async_stop()
|
||||
|
||||
async def test_mark_sessions_idle(self):
|
||||
"""Test marking media_players as idle when sessions end."""
|
||||
hass = self.hass
|
||||
# async def test_mark_sessions_idle(self):
|
||||
# """Test marking media_players as idle when sessions end."""
|
||||
# hass = self.hass
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=DEFAULT_DATA,
|
||||
options=DEFAULT_OPTIONS,
|
||||
unique_id=DEFAULT_DATA["server_id"],
|
||||
)
|
||||
# entry = MockConfigEntry(
|
||||
# domain=DOMAIN,
|
||||
# data=DEFAULT_DATA,
|
||||
# options=DEFAULT_OPTIONS,
|
||||
# unique_id=DEFAULT_DATA["server_id"],
|
||||
# )
|
||||
|
||||
mock_plex_server = MockPlexServer(config_entry=entry)
|
||||
# mock_plex_server = MockPlexServer(config_entry=entry)
|
||||
|
||||
with patch("plexapi.server.PlexServer", return_value=mock_plex_server), patch(
|
||||
"homeassistant.components.plex.PlexWebsocket.listen"
|
||||
):
|
||||
entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
# with patch("plexapi.server.PlexServer", return_value=mock_plex_server), patch(
|
||||
# "homeassistant.components.plex.PlexWebsocket.listen"
|
||||
# ):
|
||||
# entry.add_to_hass(hass)
|
||||
# assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
# await hass.async_block_till_done()
|
||||
|
||||
server_id = mock_plex_server.machineIdentifier
|
||||
# server_id = mock_plex_server.machineIdentifier
|
||||
|
||||
async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
await hass.async_block_till_done()
|
||||
# async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
# await hass.async_block_till_done()
|
||||
|
||||
sensor = hass.states.get("sensor.plex_plex_server_1")
|
||||
assert sensor.state == str(len(mock_plex_server.accounts))
|
||||
# sensor = hass.states.get("sensor.plex_plex_server_1")
|
||||
# assert sensor.state == str(len(mock_plex_server.accounts))
|
||||
|
||||
mock_plex_server.clear_clients()
|
||||
mock_plex_server.clear_sessions()
|
||||
# mock_plex_server.clear_clients()
|
||||
# mock_plex_server.clear_sessions()
|
||||
|
||||
await self.advance(DEBOUNCE_TIMEOUT)
|
||||
async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
await hass.async_block_till_done()
|
||||
# await self.advance(DEBOUNCE_TIMEOUT)
|
||||
# async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
# await hass.async_block_till_done()
|
||||
|
||||
sensor = hass.states.get("sensor.plex_plex_server_1")
|
||||
assert sensor.state == "0"
|
||||
# sensor = hass.states.get("sensor.plex_plex_server_1")
|
||||
# assert sensor.state == "0"
|
||||
|
||||
async def test_debouncer(self):
|
||||
"""Test debouncer behavior."""
|
||||
hass = self.hass
|
||||
# async def test_debouncer(self):
|
||||
# """Test debouncer behavior."""
|
||||
# hass = self.hass
|
||||
|
||||
entry = MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
data=DEFAULT_DATA,
|
||||
options=DEFAULT_OPTIONS,
|
||||
unique_id=DEFAULT_DATA["server_id"],
|
||||
)
|
||||
# entry = MockConfigEntry(
|
||||
# domain=DOMAIN,
|
||||
# data=DEFAULT_DATA,
|
||||
# options=DEFAULT_OPTIONS,
|
||||
# unique_id=DEFAULT_DATA["server_id"],
|
||||
# )
|
||||
|
||||
mock_plex_server = MockPlexServer(config_entry=entry)
|
||||
# mock_plex_server = MockPlexServer(config_entry=entry)
|
||||
|
||||
with patch("plexapi.server.PlexServer", return_value=mock_plex_server), patch(
|
||||
"homeassistant.components.plex.PlexWebsocket.listen"
|
||||
):
|
||||
entry.add_to_hass(hass)
|
||||
assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
# with patch("plexapi.server.PlexServer", return_value=mock_plex_server), patch(
|
||||
# "homeassistant.components.plex.PlexWebsocket.listen"
|
||||
# ):
|
||||
# entry.add_to_hass(hass)
|
||||
# assert await hass.config_entries.async_setup(entry.entry_id)
|
||||
# await hass.async_block_till_done()
|
||||
|
||||
server_id = mock_plex_server.machineIdentifier
|
||||
# server_id = mock_plex_server.machineIdentifier
|
||||
|
||||
with patch.object(mock_plex_server, "clients", return_value=[]), patch.object(
|
||||
mock_plex_server, "sessions", return_value=[]
|
||||
) as mock_update:
|
||||
# Called immediately
|
||||
async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
await hass.async_block_till_done()
|
||||
assert mock_update.call_count == 1
|
||||
# with patch.object(mock_plex_server, "clients", return_value=[]), patch.object(
|
||||
# mock_plex_server, "sessions", return_value=[]
|
||||
# ) as mock_update:
|
||||
# # Called immediately
|
||||
# async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
# await hass.async_block_till_done()
|
||||
# assert mock_update.call_count == 1
|
||||
|
||||
# Throttled
|
||||
async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
await hass.async_block_till_done()
|
||||
assert mock_update.call_count == 1
|
||||
# # Throttled
|
||||
# async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
# await hass.async_block_till_done()
|
||||
# assert mock_update.call_count == 1
|
||||
|
||||
# Throttled
|
||||
async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
await hass.async_block_till_done()
|
||||
assert mock_update.call_count == 1
|
||||
# # Throttled
|
||||
# async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
# await hass.async_block_till_done()
|
||||
# assert mock_update.call_count == 1
|
||||
|
||||
# Called from scheduler
|
||||
await self.advance(DEBOUNCE_TIMEOUT)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_update.call_count == 2
|
||||
# # Called from scheduler
|
||||
# await self.advance(DEBOUNCE_TIMEOUT)
|
||||
# await hass.async_block_till_done()
|
||||
# assert mock_update.call_count == 2
|
||||
|
||||
# Throttled
|
||||
async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
await hass.async_block_till_done()
|
||||
assert mock_update.call_count == 2
|
||||
# # Throttled
|
||||
# async_dispatcher_send(hass, PLEX_UPDATE_PLATFORMS_SIGNAL.format(server_id))
|
||||
# await hass.async_block_till_done()
|
||||
# assert mock_update.call_count == 2
|
||||
|
||||
# Called from scheduler
|
||||
await self.advance(DEBOUNCE_TIMEOUT)
|
||||
await hass.async_block_till_done()
|
||||
assert mock_update.call_count == 3
|
||||
# # Called from scheduler
|
||||
# await self.advance(DEBOUNCE_TIMEOUT)
|
||||
# await hass.async_block_till_done()
|
||||
# assert mock_update.call_count == 3
|
||||
Reference in new issue
Block a user