parent
27dd4ca9b3
commit
fd065e7aea
1 changed files with 178 additions and 143 deletions
|
@ -1,13 +1,10 @@
|
||||||
"""The tests for the Radarr platform."""
|
"""The tests for the Radarr platform."""
|
||||||
import unittest
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
import homeassistant.components.radarr.sensor as radarr
|
|
||||||
from homeassistant.const import DATA_GIGABYTES
|
from homeassistant.const import DATA_GIGABYTES
|
||||||
|
from homeassistant.setup import async_setup_component
|
||||||
|
|
||||||
from tests.async_mock import patch
|
from tests.async_mock import patch
|
||||||
from tests.common import get_test_home_assistant
|
|
||||||
|
|
||||||
|
|
||||||
def mocked_exception(*args, **kwargs):
|
def mocked_exception(*args, **kwargs):
|
||||||
|
@ -192,32 +189,10 @@ def mocked_requests_get(*args, **kwargs):
|
||||||
return MockResponse({"error": "Unauthorized"}, 401)
|
return MockResponse({"error": "Unauthorized"}, 401)
|
||||||
|
|
||||||
|
|
||||||
class TestRadarrSetup(unittest.TestCase):
|
async def test_diskspace_no_paths(hass):
|
||||||
"""Test the Radarr platform."""
|
"""Test getting all disk space."""
|
||||||
|
config = {
|
||||||
# pylint: disable=invalid-name
|
"sensor": {
|
||||||
DEVICES = []
|
|
||||||
|
|
||||||
def add_entities(self, devices, update):
|
|
||||||
"""Mock add devices."""
|
|
||||||
for device in devices:
|
|
||||||
self.DEVICES.append(device)
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""Initialize values for this testcase class."""
|
|
||||||
self.DEVICES = []
|
|
||||||
self.hass = get_test_home_assistant()
|
|
||||||
self.hass.config.time_zone = "America/Los_Angeles"
|
|
||||||
self.addCleanup(self.tear_down_cleanup)
|
|
||||||
|
|
||||||
def tear_down_cleanup(self):
|
|
||||||
"""Stop everything that was started."""
|
|
||||||
self.hass.stop()
|
|
||||||
|
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
|
||||||
def test_diskspace_no_paths(self, req_mock):
|
|
||||||
"""Test getting all disk space."""
|
|
||||||
config = {
|
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "2",
|
"days": "2",
|
||||||
|
@ -225,19 +200,28 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": [],
|
"include_paths": [],
|
||||||
"monitored_conditions": ["diskspace"],
|
"monitored_conditions": ["diskspace"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
|
||||||
device.update()
|
|
||||||
assert "263.10" == device.state
|
|
||||||
assert "mdi:harddisk" == device.icon
|
|
||||||
assert DATA_GIGABYTES == device.unit_of_measurement
|
|
||||||
assert "Radarr Disk Space" == device.name
|
|
||||||
assert "263.10/465.42GB (56.53%)" == device.device_state_attributes["/data"]
|
|
||||||
|
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
with patch(
|
||||||
def test_diskspace_paths(self, req_mock):
|
"requests.get",
|
||||||
"""Test getting diskspace for included paths."""
|
side_effect=mocked_requests_get,
|
||||||
config = {
|
):
|
||||||
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity = hass.states.get("sensor.radarr_disk_space")
|
||||||
|
assert entity is not None
|
||||||
|
assert "263.10" == entity.state
|
||||||
|
assert "mdi:harddisk" == entity.attributes["icon"]
|
||||||
|
assert DATA_GIGABYTES == entity.attributes["unit_of_measurement"]
|
||||||
|
assert "Radarr Disk Space" == entity.attributes["friendly_name"]
|
||||||
|
assert "263.10/465.42GB (56.53%)" == entity.attributes["/data"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_diskspace_paths(hass):
|
||||||
|
"""Test getting diskspace for included paths."""
|
||||||
|
config = {
|
||||||
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "2",
|
"days": "2",
|
||||||
|
@ -245,19 +229,28 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": ["/data"],
|
"include_paths": ["/data"],
|
||||||
"monitored_conditions": ["diskspace"],
|
"monitored_conditions": ["diskspace"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
|
||||||
device.update()
|
|
||||||
assert "263.10" == device.state
|
|
||||||
assert "mdi:harddisk" == device.icon
|
|
||||||
assert DATA_GIGABYTES == device.unit_of_measurement
|
|
||||||
assert "Radarr Disk Space" == device.name
|
|
||||||
assert "263.10/465.42GB (56.53%)" == device.device_state_attributes["/data"]
|
|
||||||
|
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
with patch(
|
||||||
def test_commands(self, req_mock):
|
"requests.get",
|
||||||
"""Test getting running commands."""
|
side_effect=mocked_requests_get,
|
||||||
config = {
|
):
|
||||||
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity = hass.states.get("sensor.radarr_disk_space")
|
||||||
|
assert entity is not None
|
||||||
|
assert "263.10" == entity.state
|
||||||
|
assert "mdi:harddisk" == entity.attributes["icon"]
|
||||||
|
assert DATA_GIGABYTES == entity.attributes["unit_of_measurement"]
|
||||||
|
assert "Radarr Disk Space" == entity.attributes["friendly_name"]
|
||||||
|
assert "263.10/465.42GB (56.53%)" == entity.attributes["/data"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_commands(hass):
|
||||||
|
"""Test getting running commands."""
|
||||||
|
config = {
|
||||||
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "2",
|
"days": "2",
|
||||||
|
@ -265,19 +258,28 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": ["/data"],
|
"include_paths": ["/data"],
|
||||||
"monitored_conditions": ["commands"],
|
"monitored_conditions": ["commands"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
|
||||||
device.update()
|
|
||||||
assert 1 == device.state
|
|
||||||
assert "mdi:code-braces" == device.icon
|
|
||||||
assert "Commands" == device.unit_of_measurement
|
|
||||||
assert "Radarr Commands" == device.name
|
|
||||||
assert "pending" == device.device_state_attributes["RescanMovie"]
|
|
||||||
|
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
with patch(
|
||||||
def test_movies(self, req_mock):
|
"requests.get",
|
||||||
"""Test getting the number of movies."""
|
side_effect=mocked_requests_get,
|
||||||
config = {
|
):
|
||||||
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity = hass.states.get("sensor.radarr_commands")
|
||||||
|
assert entity is not None
|
||||||
|
assert 1 == int(entity.state)
|
||||||
|
assert "mdi:code-braces" == entity.attributes["icon"]
|
||||||
|
assert "Commands" == entity.attributes["unit_of_measurement"]
|
||||||
|
assert "Radarr Commands" == entity.attributes["friendly_name"]
|
||||||
|
assert "pending" == entity.attributes["RescanMovie"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_movies(hass):
|
||||||
|
"""Test getting the number of movies."""
|
||||||
|
config = {
|
||||||
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "2",
|
"days": "2",
|
||||||
|
@ -285,19 +287,28 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": ["/data"],
|
"include_paths": ["/data"],
|
||||||
"monitored_conditions": ["movies"],
|
"monitored_conditions": ["movies"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
|
||||||
device.update()
|
|
||||||
assert 1 == device.state
|
|
||||||
assert "mdi:television" == device.icon
|
|
||||||
assert "Movies" == device.unit_of_measurement
|
|
||||||
assert "Radarr Movies" == device.name
|
|
||||||
assert "false" == device.device_state_attributes["Assassin's Creed (2016)"]
|
|
||||||
|
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
with patch(
|
||||||
def test_upcoming_multiple_days(self, req_mock):
|
"requests.get",
|
||||||
"""Test the upcoming movies for multiple days."""
|
side_effect=mocked_requests_get,
|
||||||
config = {
|
):
|
||||||
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
|
entity = hass.states.get("sensor.radarr_movies")
|
||||||
|
assert entity is not None
|
||||||
|
assert 1 == int(entity.state)
|
||||||
|
assert "mdi:television" == entity.attributes["icon"]
|
||||||
|
assert "Movies" == entity.attributes["unit_of_measurement"]
|
||||||
|
assert "Radarr Movies" == entity.attributes["friendly_name"]
|
||||||
|
assert "false" == entity.attributes["Assassin's Creed (2016)"]
|
||||||
|
|
||||||
|
|
||||||
|
async def test_upcoming_multiple_days(hass):
|
||||||
|
"""Test the upcoming movies for multiple days."""
|
||||||
|
config = {
|
||||||
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "2",
|
"days": "2",
|
||||||
|
@ -305,26 +316,32 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": ["/data"],
|
"include_paths": ["/data"],
|
||||||
"monitored_conditions": ["upcoming"],
|
"monitored_conditions": ["upcoming"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
|
||||||
device.update()
|
|
||||||
assert 1 == device.state
|
|
||||||
assert "mdi:television" == device.icon
|
|
||||||
assert "Movies" == device.unit_of_measurement
|
|
||||||
assert "Radarr Upcoming" == device.name
|
|
||||||
assert (
|
|
||||||
"2017-01-27T00:00:00Z"
|
|
||||||
== device.device_state_attributes["Resident Evil (2017)"]
|
|
||||||
)
|
|
||||||
|
|
||||||
@pytest.mark.skip
|
with patch(
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
"requests.get",
|
||||||
def test_upcoming_today(self, req_mock):
|
side_effect=mocked_requests_get,
|
||||||
"""Test filtering for a single day.
|
):
|
||||||
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
|
||||||
Radarr needs to respond with at least 2 days.
|
entity = hass.states.get("sensor.radarr_upcoming")
|
||||||
"""
|
assert entity is not None
|
||||||
config = {
|
assert 1 == int(entity.state)
|
||||||
|
assert "mdi:television" == entity.attributes["icon"]
|
||||||
|
assert "Movies" == entity.attributes["unit_of_measurement"]
|
||||||
|
assert "Radarr Upcoming" == entity.attributes["friendly_name"]
|
||||||
|
assert "2017-01-27T00:00:00Z" == entity.attributes["Resident Evil (2017)"]
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.skip
|
||||||
|
async def test_upcoming_today(hass):
|
||||||
|
"""Test filtering for a single day.
|
||||||
|
|
||||||
|
Radarr needs to respond with at least 2 days.
|
||||||
|
"""
|
||||||
|
config = {
|
||||||
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "1",
|
"days": "1",
|
||||||
|
@ -332,22 +349,25 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": ["/data"],
|
"include_paths": ["/data"],
|
||||||
"monitored_conditions": ["upcoming"],
|
"monitored_conditions": ["upcoming"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
with patch(
|
||||||
device.update()
|
"requests.get",
|
||||||
assert 1 == device.state
|
side_effect=mocked_requests_get,
|
||||||
assert "mdi:television" == device.icon
|
):
|
||||||
assert "Movies" == device.unit_of_measurement
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
assert "Radarr Upcoming" == device.name
|
await hass.async_block_till_done()
|
||||||
assert (
|
entity = hass.states.get("sensor.radarr_upcoming")
|
||||||
"2017-01-27T00:00:00Z"
|
assert 1 == int(entity.state)
|
||||||
== device.device_state_attributes["Resident Evil (2017)"]
|
assert "mdi:television" == entity.attributes["icon"]
|
||||||
)
|
assert "Movies" == entity.attributes["unit_of_measurement"]
|
||||||
|
assert "Radarr Upcoming" == entity.attributes["friendly_name"]
|
||||||
|
assert "2017-01-27T00:00:00Z" == entity.attributes["Resident Evil (2017)"]
|
||||||
|
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
|
||||||
def test_system_status(self, req_mock):
|
async def test_system_status(hass):
|
||||||
"""Test the getting of the system status."""
|
"""Test the getting of the system status."""
|
||||||
config = {
|
config = {
|
||||||
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "2",
|
"days": "2",
|
||||||
|
@ -355,19 +375,25 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": ["/data"],
|
"include_paths": ["/data"],
|
||||||
"monitored_conditions": ["status"],
|
"monitored_conditions": ["status"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
with patch(
|
||||||
device.update()
|
"requests.get",
|
||||||
assert "0.2.0.210" == device.state
|
side_effect=mocked_requests_get,
|
||||||
assert "mdi:information" == device.icon
|
):
|
||||||
assert "Radarr Status" == device.name
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
assert "4.8.13.1" == device.device_state_attributes["osVersion"]
|
await hass.async_block_till_done()
|
||||||
|
entity = hass.states.get("sensor.radarr_status")
|
||||||
|
assert entity is not None
|
||||||
|
assert "0.2.0.210" == entity.state
|
||||||
|
assert "mdi:information" == entity.attributes["icon"]
|
||||||
|
assert "Radarr Status" == entity.attributes["friendly_name"]
|
||||||
|
assert "4.8.13.1" == entity.attributes["osVersion"]
|
||||||
|
|
||||||
@pytest.mark.skip
|
|
||||||
@patch("requests.get", side_effect=mocked_requests_get)
|
async def test_ssl(hass):
|
||||||
def test_ssl(self, req_mock):
|
"""Test SSL being enabled."""
|
||||||
"""Test SSL being enabled."""
|
config = {
|
||||||
config = {
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "1",
|
"days": "1",
|
||||||
|
@ -376,23 +402,26 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"monitored_conditions": ["upcoming"],
|
"monitored_conditions": ["upcoming"],
|
||||||
"ssl": "true",
|
"ssl": "true",
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
with patch(
|
||||||
device.update()
|
"requests.get",
|
||||||
assert 1 == device.state
|
side_effect=mocked_requests_get,
|
||||||
assert "s" == device.ssl
|
):
|
||||||
assert "mdi:television" == device.icon
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
assert "Movies" == device.unit_of_measurement
|
await hass.async_block_till_done()
|
||||||
assert "Radarr Upcoming" == device.name
|
entity = hass.states.get("sensor.radarr_upcoming")
|
||||||
assert (
|
assert entity is not None
|
||||||
"2017-01-27T00:00:00Z"
|
assert 1 == int(entity.state)
|
||||||
== device.device_state_attributes["Resident Evil (2017)"]
|
assert "mdi:television" == entity.attributes["icon"]
|
||||||
)
|
assert "Movies" == entity.attributes["unit_of_measurement"]
|
||||||
|
assert "Radarr Upcoming" == entity.attributes["friendly_name"]
|
||||||
|
assert "2017-01-27T00:00:00Z" == entity.attributes["Resident Evil (2017)"]
|
||||||
|
|
||||||
@patch("requests.get", side_effect=mocked_exception)
|
|
||||||
def test_exception_handling(self, req_mock):
|
async def test_exception_handling(hass):
|
||||||
"""Test exception being handled."""
|
"""Test exception being handled."""
|
||||||
config = {
|
config = {
|
||||||
|
"sensor": {
|
||||||
"platform": "radarr",
|
"platform": "radarr",
|
||||||
"api_key": "foo",
|
"api_key": "foo",
|
||||||
"days": "1",
|
"days": "1",
|
||||||
|
@ -400,7 +429,13 @@ class TestRadarrSetup(unittest.TestCase):
|
||||||
"include_paths": ["/data"],
|
"include_paths": ["/data"],
|
||||||
"monitored_conditions": ["upcoming"],
|
"monitored_conditions": ["upcoming"],
|
||||||
}
|
}
|
||||||
radarr.setup_platform(self.hass, config, self.add_entities, None)
|
}
|
||||||
for device in self.DEVICES:
|
with patch(
|
||||||
device.update()
|
"requests.get",
|
||||||
assert device.state is None
|
side_effect=mocked_exception,
|
||||||
|
):
|
||||||
|
assert await async_setup_component(hass, "sensor", config)
|
||||||
|
await hass.async_block_till_done()
|
||||||
|
entity = hass.states.get("sensor.radarr_upcoming")
|
||||||
|
assert entity is not None
|
||||||
|
assert "unavailable" == entity.state
|
||||||
|
|
Loading…
Add table
Reference in a new issue