init home-assistant
This commit is contained in:
1
home-assistant/tests/components/webmin/__init__.py
Normal file
1
home-assistant/tests/components/webmin/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
"""Tests for the Webmin integration."""
|
||||
58
home-assistant/tests/components/webmin/conftest.py
Normal file
58
home-assistant/tests/components/webmin/conftest.py
Normal file
@@ -0,0 +1,58 @@
|
||||
"""Fixtures for Webmin integration tests."""
|
||||
|
||||
from collections.abc import Generator
|
||||
from unittest.mock import AsyncMock, patch
|
||||
|
||||
import pytest
|
||||
|
||||
from homeassistant.components.webmin.const import DEFAULT_PORT, DOMAIN
|
||||
from homeassistant.const import (
|
||||
CONF_HOST,
|
||||
CONF_PASSWORD,
|
||||
CONF_PORT,
|
||||
CONF_SSL,
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from tests.common import MockConfigEntry, load_json_object_fixture
|
||||
|
||||
TEST_USER_INPUT = {
|
||||
CONF_HOST: "192.168.1.1",
|
||||
CONF_USERNAME: "user",
|
||||
CONF_PASSWORD: "pass",
|
||||
CONF_PORT: DEFAULT_PORT,
|
||||
CONF_SSL: True,
|
||||
CONF_VERIFY_SSL: False,
|
||||
}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mock_setup_entry() -> Generator[AsyncMock]:
|
||||
"""Mock setting up a config entry."""
|
||||
with patch(
|
||||
"homeassistant.components.webmin.async_setup_entry", return_value=True
|
||||
) as mock_setup:
|
||||
yield mock_setup
|
||||
|
||||
|
||||
async def async_init_integration(
|
||||
hass: HomeAssistant, with_mac_address: bool = True
|
||||
) -> MockConfigEntry:
|
||||
"""Set up the Webmin integration in Home Assistant."""
|
||||
entry = MockConfigEntry(domain=DOMAIN, options=TEST_USER_INPUT, title="name")
|
||||
entry.add_to_hass(hass)
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.webmin.helpers.WebminInstance.update",
|
||||
return_value=load_json_object_fixture(
|
||||
"webmin_update.json"
|
||||
if with_mac_address
|
||||
else "webmin_update_without_mac.json",
|
||||
DOMAIN,
|
||||
),
|
||||
):
|
||||
await hass.config_entries.async_setup(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
return entry
|
||||
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"active_interfaces": [
|
||||
{
|
||||
"fullname": "lo",
|
||||
"up": 1,
|
||||
"index": 0,
|
||||
"scope6": ["host"],
|
||||
"netmask": "255.0.0.0",
|
||||
"netmask6": [128],
|
||||
"edit": 1,
|
||||
"broadcast": 0,
|
||||
"mtu": 65536,
|
||||
"name": "lo",
|
||||
"address": "127.0.0.1",
|
||||
"address6": ["::1"]
|
||||
},
|
||||
{
|
||||
"mtu": 1500,
|
||||
"fullname": "enp6s0",
|
||||
"up": 1,
|
||||
"index": 1,
|
||||
"ether": "12:34:56:78:9a:bc",
|
||||
"address6": [],
|
||||
"netmask6": [],
|
||||
"edit": 1,
|
||||
"scope6": [],
|
||||
"name": "enp6s0"
|
||||
},
|
||||
{
|
||||
"edit": 1,
|
||||
"netmask6": [64],
|
||||
"netmask": "255.255.255.0",
|
||||
"scope6": ["link"],
|
||||
"up": 1,
|
||||
"index": 2,
|
||||
"fullname": "eno1",
|
||||
"address6": ["fe80::2:3:4"],
|
||||
"address": "192.168.1.4",
|
||||
"name": "eno1",
|
||||
"mtu": 1500,
|
||||
"broadcast": "192.168.1.255",
|
||||
"ether": "12:34:56:78:9a:bd"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,135 @@
|
||||
{
|
||||
"disk_total": 18104905818112,
|
||||
"io": [0, 4],
|
||||
"load": [
|
||||
1.29,
|
||||
1.36,
|
||||
1.37,
|
||||
3589,
|
||||
"Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz",
|
||||
"GenuineIntel",
|
||||
15728640,
|
||||
12
|
||||
],
|
||||
"disk_free": 7749321486336,
|
||||
"kernel": { "os": "Linux", "arch": "x86_64", "version": "6.6.18-1-lts" },
|
||||
"disk_fs": [
|
||||
{
|
||||
"device": "UUID=00000000-80b6-0000-8a06-000000000000",
|
||||
"dir": "/",
|
||||
"ifree": 14927206,
|
||||
"total": 248431161344,
|
||||
"used_percent": 80,
|
||||
"type": "ext4",
|
||||
"itotal": 15482880,
|
||||
"iused": 555674,
|
||||
"free": 49060442112,
|
||||
"used": 186676502528,
|
||||
"iused_percent": 4
|
||||
},
|
||||
{
|
||||
"total": 11903838912512,
|
||||
"used_percent": 38,
|
||||
"iused": 3542318,
|
||||
"type": "ext4",
|
||||
"itotal": 366198784,
|
||||
"device": "/dev/md127",
|
||||
"ifree": 362656466,
|
||||
"dir": "/media/disk2",
|
||||
"iused_percent": 1,
|
||||
"free": 7028764823552,
|
||||
"used": 4275077644288
|
||||
},
|
||||
{
|
||||
"dir": "/media/disk1",
|
||||
"ifree": 183130757,
|
||||
"device": "UUID=00000000-2bb2-0000-896c-000000000000",
|
||||
"type": "ext4",
|
||||
"itotal": 183140352,
|
||||
"iused": 9595,
|
||||
"used_percent": 89,
|
||||
"total": 5952635744256,
|
||||
"used": 4981066997760,
|
||||
"free": 671496220672,
|
||||
"iused_percent": 1
|
||||
}
|
||||
],
|
||||
"drivetemps": [
|
||||
{ "temp": 49, "device": "/dev/sda", "failed": "", "errors": "" },
|
||||
{ "failed": "", "errors": "", "device": "/dev/sdb", "temp": 49 },
|
||||
{ "device": "/dev/sdc", "temp": 51, "failed": "", "errors": "" },
|
||||
{ "failed": "", "errors": "", "device": "/dev/sdd", "temp": 51 },
|
||||
{ "errors": "", "failed": "", "temp": 43, "device": "/dev/sde" },
|
||||
{ "device": "/dev/sdf", "temp": 40, "errors": "", "failed": "" }
|
||||
],
|
||||
"mem": [32766344, 28530480, 1953088, 1944384, 27845756, ""],
|
||||
"disk_used": 9442821144576,
|
||||
"cputemps": [
|
||||
{ "temp": 51, "core": 0 },
|
||||
{ "temp": 49, "core": 1 },
|
||||
{ "core": 2, "temp": 59 },
|
||||
{ "temp": 51, "core": 3 },
|
||||
{ "temp": 50, "core": 4 },
|
||||
{ "temp": 49, "core": 5 }
|
||||
],
|
||||
"procs": 310,
|
||||
"cpu": [0, 8, 92, 0, 0],
|
||||
"cpufans": [
|
||||
{ "rpm": 0, "fan": 1 },
|
||||
{ "fan": 2, "rpm": 1371 },
|
||||
{ "rpm": 0, "fan": 3 },
|
||||
{ "rpm": 927, "fan": 4 },
|
||||
{ "rpm": 801, "fan": 5 }
|
||||
],
|
||||
"load_1m": 1.29,
|
||||
"load_5m": 1.36,
|
||||
"load_15m": 1.37,
|
||||
"mem_total": 32766344,
|
||||
"mem_free": 28530480,
|
||||
"swap_total": 1953088,
|
||||
"swap_free": 1944384,
|
||||
"uptime": { "days": 11, "minutes": 1, "seconds": 28 },
|
||||
"active_interfaces": [
|
||||
{
|
||||
"scope6": ["host"],
|
||||
"address": "127.0.0.1",
|
||||
"address6": ["::1"],
|
||||
"name": "lo",
|
||||
"broadcast": 0,
|
||||
"up": 1,
|
||||
"index": 0,
|
||||
"fullname": "lo",
|
||||
"netmask6": [128],
|
||||
"netmask": "255.0.0.0",
|
||||
"mtu": 65536,
|
||||
"edit": 1
|
||||
},
|
||||
{
|
||||
"scope6": [],
|
||||
"address6": [],
|
||||
"name": "enp6s0",
|
||||
"up": 1,
|
||||
"index": 1,
|
||||
"netmask6": [],
|
||||
"fullname": "enp6s0",
|
||||
"mtu": 1500,
|
||||
"edit": 1,
|
||||
"ether": "12:34:56:78:9a:bc"
|
||||
},
|
||||
{
|
||||
"ether": "12:34:56:78:9a:bd",
|
||||
"edit": 1,
|
||||
"netmask": "255.255.255.0",
|
||||
"netmask6": [64],
|
||||
"fullname": "eno1",
|
||||
"mtu": 1500,
|
||||
"index": 2,
|
||||
"broadcast": "192.168.1.255",
|
||||
"up": 1,
|
||||
"address6": ["fe80::2:3:4"],
|
||||
"scope6": ["link"],
|
||||
"name": "eno1",
|
||||
"address": "192.168.1.4"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,108 @@
|
||||
{
|
||||
"disk_total": 18104905818112,
|
||||
"io": [0, 4],
|
||||
"load": [
|
||||
1.29,
|
||||
1.36,
|
||||
1.37,
|
||||
3589,
|
||||
"Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz",
|
||||
"GenuineIntel",
|
||||
15728640,
|
||||
12
|
||||
],
|
||||
"disk_free": 7749321486336,
|
||||
"kernel": { "os": "Linux", "arch": "x86_64", "version": "6.6.18-1-lts" },
|
||||
"disk_fs": [
|
||||
{
|
||||
"device": "UUID=00000000-80b6-0000-8a06-000000000000",
|
||||
"dir": "/",
|
||||
"ifree": 14927206,
|
||||
"total": 248431161344,
|
||||
"used_percent": 80,
|
||||
"type": "ext4",
|
||||
"itotal": 15482880,
|
||||
"iused": 555674,
|
||||
"free": 49060442112,
|
||||
"used": 186676502528,
|
||||
"iused_percent": 4
|
||||
},
|
||||
{
|
||||
"total": 11903838912512,
|
||||
"used_percent": 38,
|
||||
"iused": 3542318,
|
||||
"type": "ext4",
|
||||
"itotal": 366198784,
|
||||
"device": "/dev/md127",
|
||||
"ifree": 362656466,
|
||||
"dir": "/media/disk2",
|
||||
"iused_percent": 1,
|
||||
"free": 7028764823552,
|
||||
"used": 4275077644288
|
||||
},
|
||||
{
|
||||
"dir": "/media/disk1",
|
||||
"ifree": 183130757,
|
||||
"device": "UUID=00000000-2bb2-0000-896c-000000000000",
|
||||
"type": "ext4",
|
||||
"itotal": 183140352,
|
||||
"iused": 9595,
|
||||
"used_percent": 89,
|
||||
"total": 5952635744256,
|
||||
"used": 4981066997760,
|
||||
"free": 671496220672,
|
||||
"iused_percent": 1
|
||||
}
|
||||
],
|
||||
"drivetemps": [
|
||||
{ "temp": 49, "device": "/dev/sda", "failed": "", "errors": "" },
|
||||
{ "failed": "", "errors": "", "device": "/dev/sdb", "temp": 49 },
|
||||
{ "device": "/dev/sdc", "temp": 51, "failed": "", "errors": "" },
|
||||
{ "failed": "", "errors": "", "device": "/dev/sdd", "temp": 51 },
|
||||
{ "errors": "", "failed": "", "temp": 43, "device": "/dev/sde" },
|
||||
{ "device": "/dev/sdf", "temp": 40, "errors": "", "failed": "" }
|
||||
],
|
||||
"mem": [32766344, 28530480, 1953088, 1944384, 27845756, ""],
|
||||
"disk_used": 9442821144576,
|
||||
"cputemps": [
|
||||
{ "temp": 51, "core": 0 },
|
||||
{ "temp": 49, "core": 1 },
|
||||
{ "core": 2, "temp": 59 },
|
||||
{ "temp": 51, "core": 3 },
|
||||
{ "temp": 50, "core": 4 },
|
||||
{ "temp": 49, "core": 5 }
|
||||
],
|
||||
"procs": 310,
|
||||
"cpu": [0, 8, 92, 0, 0],
|
||||
"cpufans": [
|
||||
{ "rpm": 0, "fan": 1 },
|
||||
{ "fan": 2, "rpm": 1371 },
|
||||
{ "rpm": 0, "fan": 3 },
|
||||
{ "rpm": 927, "fan": 4 },
|
||||
{ "rpm": 801, "fan": 5 }
|
||||
],
|
||||
"load_1m": 1.29,
|
||||
"load_5m": 1.36,
|
||||
"load_15m": 1.37,
|
||||
"mem_total": 32766344,
|
||||
"mem_free": 28530480,
|
||||
"swap_total": 1953088,
|
||||
"swap_free": 1944384,
|
||||
"uptime": { "days": 11, "minutes": 1, "seconds": 28 },
|
||||
"active_interfaces": [
|
||||
{
|
||||
"scope6": ["host"],
|
||||
"address": "127.0.0.1",
|
||||
"address6": ["::1"],
|
||||
"name": "lo",
|
||||
"broadcast": 0,
|
||||
"up": 1,
|
||||
"index": 0,
|
||||
"fullname": "lo",
|
||||
"netmask6": [128],
|
||||
"netmask": "255.0.0.0",
|
||||
"mtu": 65536,
|
||||
"edit": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,261 @@
|
||||
# serializer version: 1
|
||||
# name: test_diagnostics
|
||||
dict({
|
||||
'data': dict({
|
||||
'active_interfaces': list([
|
||||
dict({
|
||||
'address': '**REDACTED**',
|
||||
'address6': '**REDACTED**',
|
||||
'broadcast': '**REDACTED**',
|
||||
'edit': 1,
|
||||
'fullname': 'lo',
|
||||
'index': 0,
|
||||
'mtu': 65536,
|
||||
'name': 'lo',
|
||||
'netmask': '255.0.0.0',
|
||||
'netmask6': list([
|
||||
128,
|
||||
]),
|
||||
'scope6': list([
|
||||
'host',
|
||||
]),
|
||||
'up': 1,
|
||||
}),
|
||||
dict({
|
||||
'address6': '**REDACTED**',
|
||||
'edit': 1,
|
||||
'ether': '**REDACTED**',
|
||||
'fullname': 'enp6s0',
|
||||
'index': 1,
|
||||
'mtu': 1500,
|
||||
'name': 'enp6s0',
|
||||
'netmask6': list([
|
||||
]),
|
||||
'scope6': list([
|
||||
]),
|
||||
'up': 1,
|
||||
}),
|
||||
dict({
|
||||
'address': '**REDACTED**',
|
||||
'address6': '**REDACTED**',
|
||||
'broadcast': '**REDACTED**',
|
||||
'edit': 1,
|
||||
'ether': '**REDACTED**',
|
||||
'fullname': 'eno1',
|
||||
'index': 2,
|
||||
'mtu': 1500,
|
||||
'name': 'eno1',
|
||||
'netmask': '255.255.255.0',
|
||||
'netmask6': list([
|
||||
64,
|
||||
]),
|
||||
'scope6': list([
|
||||
'link',
|
||||
]),
|
||||
'up': 1,
|
||||
}),
|
||||
]),
|
||||
'cpu': list([
|
||||
0,
|
||||
8,
|
||||
92,
|
||||
0,
|
||||
0,
|
||||
]),
|
||||
'cpufans': list([
|
||||
dict({
|
||||
'fan': 1,
|
||||
'rpm': 0,
|
||||
}),
|
||||
dict({
|
||||
'fan': 2,
|
||||
'rpm': 1371,
|
||||
}),
|
||||
dict({
|
||||
'fan': 3,
|
||||
'rpm': 0,
|
||||
}),
|
||||
dict({
|
||||
'fan': 4,
|
||||
'rpm': 927,
|
||||
}),
|
||||
dict({
|
||||
'fan': 5,
|
||||
'rpm': 801,
|
||||
}),
|
||||
]),
|
||||
'cputemps': list([
|
||||
dict({
|
||||
'core': 0,
|
||||
'temp': 51,
|
||||
}),
|
||||
dict({
|
||||
'core': 1,
|
||||
'temp': 49,
|
||||
}),
|
||||
dict({
|
||||
'core': 2,
|
||||
'temp': 59,
|
||||
}),
|
||||
dict({
|
||||
'core': 3,
|
||||
'temp': 51,
|
||||
}),
|
||||
dict({
|
||||
'core': 4,
|
||||
'temp': 50,
|
||||
}),
|
||||
dict({
|
||||
'core': 5,
|
||||
'temp': 49,
|
||||
}),
|
||||
]),
|
||||
'disk_free': 7749321486336,
|
||||
'disk_fs': dict({
|
||||
'/': dict({
|
||||
'device': '**REDACTED**',
|
||||
'dir': '**REDACTED**',
|
||||
'free': 49060442112,
|
||||
'ifree': 14927206,
|
||||
'itotal': 15482880,
|
||||
'iused': 555674,
|
||||
'iused_percent': 4,
|
||||
'total': 248431161344,
|
||||
'type': 'ext4',
|
||||
'used': 186676502528,
|
||||
'used_percent': 80,
|
||||
}),
|
||||
'/media/disk1': dict({
|
||||
'device': '**REDACTED**',
|
||||
'dir': '**REDACTED**',
|
||||
'free': 671496220672,
|
||||
'ifree': 183130757,
|
||||
'itotal': 183140352,
|
||||
'iused': 9595,
|
||||
'iused_percent': 1,
|
||||
'total': 5952635744256,
|
||||
'type': 'ext4',
|
||||
'used': 4981066997760,
|
||||
'used_percent': 89,
|
||||
}),
|
||||
'/media/disk2': dict({
|
||||
'device': '**REDACTED**',
|
||||
'dir': '**REDACTED**',
|
||||
'free': 7028764823552,
|
||||
'ifree': 362656466,
|
||||
'itotal': 366198784,
|
||||
'iused': 3542318,
|
||||
'iused_percent': 1,
|
||||
'total': 11903838912512,
|
||||
'type': 'ext4',
|
||||
'used': 4275077644288,
|
||||
'used_percent': 38,
|
||||
}),
|
||||
}),
|
||||
'disk_total': 18104905818112,
|
||||
'disk_used': 9442821144576,
|
||||
'drivetemps': list([
|
||||
dict({
|
||||
'device': '**REDACTED**',
|
||||
'errors': '',
|
||||
'failed': '',
|
||||
'temp': 49,
|
||||
}),
|
||||
dict({
|
||||
'device': '**REDACTED**',
|
||||
'errors': '',
|
||||
'failed': '',
|
||||
'temp': 49,
|
||||
}),
|
||||
dict({
|
||||
'device': '**REDACTED**',
|
||||
'errors': '',
|
||||
'failed': '',
|
||||
'temp': 51,
|
||||
}),
|
||||
dict({
|
||||
'device': '**REDACTED**',
|
||||
'errors': '',
|
||||
'failed': '',
|
||||
'temp': 51,
|
||||
}),
|
||||
dict({
|
||||
'device': '**REDACTED**',
|
||||
'errors': '',
|
||||
'failed': '',
|
||||
'temp': 43,
|
||||
}),
|
||||
dict({
|
||||
'device': '**REDACTED**',
|
||||
'errors': '',
|
||||
'failed': '',
|
||||
'temp': 40,
|
||||
}),
|
||||
]),
|
||||
'io': list([
|
||||
0,
|
||||
4,
|
||||
]),
|
||||
'kernel': dict({
|
||||
'arch': 'x86_64',
|
||||
'os': 'Linux',
|
||||
'version': '6.6.18-1-lts',
|
||||
}),
|
||||
'load': list([
|
||||
1.29,
|
||||
1.36,
|
||||
1.37,
|
||||
3589,
|
||||
'Intel(R) Core(TM) i7-5820K CPU @ 3.30GHz',
|
||||
'GenuineIntel',
|
||||
15728640,
|
||||
12,
|
||||
]),
|
||||
'load_15m': 1.37,
|
||||
'load_1m': 1.29,
|
||||
'load_5m': 1.36,
|
||||
'mem': list([
|
||||
32766344,
|
||||
28530480,
|
||||
1953088,
|
||||
1944384,
|
||||
27845756,
|
||||
'',
|
||||
]),
|
||||
'mem_free': 28530480,
|
||||
'mem_total': 32766344,
|
||||
'procs': 310,
|
||||
'swap_free': 1944384,
|
||||
'swap_total': 1953088,
|
||||
'uptime': dict({
|
||||
'days': 11,
|
||||
'minutes': 1,
|
||||
'seconds': 28,
|
||||
}),
|
||||
}),
|
||||
'entry': dict({
|
||||
'data': dict({
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'discovery_keys': dict({
|
||||
}),
|
||||
'domain': 'webmin',
|
||||
'entry_id': '**REDACTED**',
|
||||
'minor_version': 1,
|
||||
'options': dict({
|
||||
'host': '**REDACTED**',
|
||||
'password': '**REDACTED**',
|
||||
'port': 10000,
|
||||
'ssl': True,
|
||||
'username': '**REDACTED**',
|
||||
'verify_ssl': False,
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': '**REDACTED**',
|
||||
'unique_id': None,
|
||||
'version': 1,
|
||||
}),
|
||||
})
|
||||
# ---
|
||||
1801
home-assistant/tests/components/webmin/snapshots/test_sensor.ambr
Normal file
1801
home-assistant/tests/components/webmin/snapshots/test_sensor.ambr
Normal file
File diff suppressed because it is too large
Load Diff
142
home-assistant/tests/components/webmin/test_config_flow.py
Normal file
142
home-assistant/tests/components/webmin/test_config_flow.py
Normal file
@@ -0,0 +1,142 @@
|
||||
"""Test the Webmin config flow."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from http import HTTPStatus
|
||||
from unittest.mock import AsyncMock, patch
|
||||
from xmlrpc.client import Fault
|
||||
|
||||
from aiohttp.client_exceptions import ClientConnectionError, ClientResponseError
|
||||
import pytest
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.components.webmin.const import DOMAIN
|
||||
from homeassistant.const import CONF_HOST
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .conftest import TEST_USER_INPUT
|
||||
|
||||
from tests.common import load_json_object_fixture
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
async def user_flow(hass: HomeAssistant) -> str:
|
||||
"""Return a user-initiated flow after filling in host info."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["errors"] is None
|
||||
return result["flow_id"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"fixture", ["webmin_update_without_mac.json", "webmin_update.json"]
|
||||
)
|
||||
async def test_form_user(
|
||||
hass: HomeAssistant, user_flow: str, mock_setup_entry: AsyncMock, fixture: str
|
||||
) -> None:
|
||||
"""Test a successful user initiated flow."""
|
||||
with patch(
|
||||
"homeassistant.components.webmin.helpers.WebminInstance.update",
|
||||
return_value=load_json_object_fixture(fixture, DOMAIN),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
user_flow, TEST_USER_INPUT
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == TEST_USER_INPUT[CONF_HOST]
|
||||
assert result["options"] == TEST_USER_INPUT
|
||||
|
||||
assert len(mock_setup_entry.mock_calls) == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
("exception", "error_type"),
|
||||
[
|
||||
(
|
||||
ClientResponseError(
|
||||
request_info=None, history=None, status=HTTPStatus.UNAUTHORIZED
|
||||
),
|
||||
"invalid_auth",
|
||||
),
|
||||
(
|
||||
ClientResponseError(
|
||||
request_info=None, history=None, status=HTTPStatus.BAD_REQUEST
|
||||
),
|
||||
"cannot_connect",
|
||||
),
|
||||
(ClientConnectionError, "cannot_connect"),
|
||||
(Exception, "unknown"),
|
||||
(
|
||||
Fault("5", "Webmin module net does not exist"),
|
||||
"unknown",
|
||||
),
|
||||
],
|
||||
)
|
||||
async def test_form_user_errors(
|
||||
hass: HomeAssistant, user_flow: str, exception: Exception, error_type: str
|
||||
) -> None:
|
||||
"""Test we handle errors."""
|
||||
with patch(
|
||||
"homeassistant.components.webmin.helpers.WebminInstance.update",
|
||||
side_effect=exception,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
user_flow, TEST_USER_INPUT
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "user"
|
||||
assert result["errors"] == {"base": error_type}
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.webmin.helpers.WebminInstance.update",
|
||||
return_value=load_json_object_fixture("webmin_update.json", DOMAIN),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], TEST_USER_INPUT
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == TEST_USER_INPUT[CONF_HOST]
|
||||
assert result["options"] == TEST_USER_INPUT
|
||||
|
||||
|
||||
async def test_duplicate_entry(
|
||||
hass: HomeAssistant,
|
||||
user_flow: str,
|
||||
mock_setup_entry: AsyncMock,
|
||||
) -> None:
|
||||
"""Test a successful user initiated flow."""
|
||||
with patch(
|
||||
"homeassistant.components.webmin.helpers.WebminInstance.update",
|
||||
return_value=load_json_object_fixture("webmin_update.json", DOMAIN),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
user_flow, TEST_USER_INPUT
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.CREATE_ENTRY
|
||||
assert result["title"] == TEST_USER_INPUT[CONF_HOST]
|
||||
assert result["options"] == TEST_USER_INPUT
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.webmin.helpers.WebminInstance.update",
|
||||
return_value=load_json_object_fixture("webmin_update.json", DOMAIN),
|
||||
):
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_USER}
|
||||
)
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"], TEST_USER_INPUT
|
||||
)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
22
home-assistant/tests/components/webmin/test_diagnostics.py
Normal file
22
home-assistant/tests/components/webmin/test_diagnostics.py
Normal file
@@ -0,0 +1,22 @@
|
||||
"""Tests for the diagnostics data provided by the Webmin integration."""
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import async_init_integration
|
||||
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
async def test_diagnostics(
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test diagnostics."""
|
||||
assert await get_diagnostics_for_config_entry(
|
||||
hass, hass_client, await async_init_integration(hass)
|
||||
) == snapshot(exclude=props("created_at", "modified_at"))
|
||||
29
home-assistant/tests/components/webmin/test_init.py
Normal file
29
home-assistant/tests/components/webmin/test_init.py
Normal file
@@ -0,0 +1,29 @@
|
||||
"""Tests for the Webmin integration."""
|
||||
|
||||
from homeassistant.components.webmin.const import DOMAIN
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from .conftest import async_init_integration
|
||||
|
||||
|
||||
async def test_unload_entry(hass: HomeAssistant) -> None:
|
||||
"""Test successful unload of entry."""
|
||||
|
||||
entry = await async_init_integration(hass)
|
||||
|
||||
assert entry.state is ConfigEntryState.LOADED
|
||||
|
||||
assert await hass.config_entries.async_unload(entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert entry.state is ConfigEntryState.NOT_LOADED
|
||||
assert not hass.data.get(DOMAIN)
|
||||
|
||||
|
||||
async def test_entry_without_mac_address(hass: HomeAssistant) -> None:
|
||||
"""Test an entry without MAC address."""
|
||||
|
||||
entry = await async_init_integration(hass, False)
|
||||
|
||||
assert entry.runtime_data.unique_id == entry.entry_id
|
||||
24
home-assistant/tests/components/webmin/test_sensor.py
Normal file
24
home-assistant/tests/components/webmin/test_sensor.py
Normal file
@@ -0,0 +1,24 @@
|
||||
"""Test cases for the Webmin sensors."""
|
||||
|
||||
import pytest
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
|
||||
from .conftest import async_init_integration
|
||||
|
||||
from tests.common import snapshot_platform
|
||||
|
||||
|
||||
@pytest.mark.usefixtures("entity_registry_enabled_by_default")
|
||||
async def test_sensor(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test the sensor entities and states."""
|
||||
|
||||
entry = await async_init_integration(hass)
|
||||
|
||||
await snapshot_platform(hass, entity_registry, snapshot, entry.entry_id)
|
||||
Reference in New Issue
Block a user