Use fixtures in UniFi diagnostics tests (#118905)

This commit is contained in:
Robert Svensson 2024-06-06 20:22:41 +02:00 committed by GitHub
parent bca8958d4b
commit d695660164
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 170 additions and 146 deletions

View File

@ -0,0 +1,129 @@
# serializer version: 1
# name: test_entry_diagnostics[dpi_group_payload0-dpi_app_payload0-device_payload0-client_payload0-config_entry_options0]
dict({
'clients': dict({
'00:00:00:00:00:00': dict({
'blocked': False,
'hostname': 'client_1',
'ip': '10.0.0.1',
'is_wired': True,
'last_seen': 1562600145,
'mac': '00:00:00:00:00:00',
'name': 'POE Client 1',
'oui': 'Producer',
'sw_mac': '00:00:00:00:00:01',
'sw_port': 1,
'wired-rx_bytes': 1234000000,
'wired-tx_bytes': 5678000000,
}),
}),
'config': dict({
'data': dict({
'host': '**REDACTED**',
'password': '**REDACTED**',
'port': 1234,
'site': 'site_id',
'username': '**REDACTED**',
'verify_ssl': False,
}),
'disabled_by': None,
'domain': 'unifi',
'entry_id': '1',
'minor_version': 1,
'options': dict({
'allow_bandwidth_sensors': True,
'allow_uptime_sensors': True,
'block_client': list([
'00:00:00:00:00:00',
]),
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'user',
'title': 'Mock Title',
'unique_id': '1',
'version': 1,
}),
'devices': dict({
'00:00:00:00:00:01': dict({
'board_rev': '1.2.3',
'device_id': 'mock-id',
'ethernet_table': list([
dict({
'mac': '00:00:00:00:00:02',
'name': 'eth0',
'num_port': 2,
}),
]),
'ip': '10.0.1.1',
'last_seen': 1562600145,
'mac': '00:00:00:00:00:01',
'model': 'US16P150',
'name': 'mock-name',
'port_overrides': list([
]),
'port_table': list([
dict({
'mac_table': list([
dict({
'age': 1,
'mac': '00:00:00:00:00:00',
'static': False,
'uptime': 3971792,
'vlan': 1,
}),
dict({
'age': 1,
'mac': '**REDACTED**',
'static': True,
'uptime': 0,
'vlan': 0,
}),
]),
'media': 'GE',
'name': 'Port 1',
'poe_class': 'Class 4',
'poe_enable': True,
'poe_mode': 'auto',
'poe_power': '2.56',
'poe_voltage': '53.40',
'port_idx': 1,
'port_poe': True,
'portconf_id': '1a1',
'up': True,
}),
]),
'state': 1,
'type': 'usw',
'version': '4.0.42.10433',
}),
}),
'dpi_apps': dict({
'5f976f62e3c58f018ec7e17d': dict({
'_id': '5f976f62e3c58f018ec7e17d',
'apps': list([
]),
'blocked': True,
'cats': list([
'4',
]),
'enabled': True,
'log': True,
'site_id': 'name',
}),
}),
'dpi_groups': dict({
'5f976f4ae3c58f018ec7dff6': dict({
'_id': '5f976f4ae3c58f018ec7dff6',
'dpiapp_ids': list([
'5f976f62e3c58f018ec7e17d',
]),
'name': 'Block Media Streaming',
'site_id': 'name',
}),
}),
'role_is_admin': True,
'wlans': dict({
}),
})
# ---

View File

@ -1,27 +1,21 @@
"""Test UniFi Network diagnostics."""
from homeassistant.components.diagnostics import REDACTED
import pytest
from syrupy.assertion import SnapshotAssertion
from homeassistant.components.unifi.const import (
CONF_ALLOW_BANDWIDTH_SENSORS,
CONF_ALLOW_UPTIME_SENSORS,
CONF_BLOCK_CLIENT,
)
from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant
from .test_hub import setup_unifi_integration
from tests.components.diagnostics import get_diagnostics_for_config_entry
from tests.test_util.aiohttp import AiohttpClientMocker
from tests.typing import ClientSessionGenerator
async def test_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
aioclient_mock: AiohttpClientMocker,
) -> None:
"""Test config entry diagnostics."""
client = {
CLIENT_DATA = [
{
"blocked": False,
"hostname": "client_1",
"ip": "10.0.0.1",
@ -35,7 +29,9 @@ async def test_entry_diagnostics(
"wired-rx_bytes": 1234000000,
"wired-tx_bytes": 5678000000,
}
device = {
]
DEVICE_DATA = [
{
"board_rev": "1.2.3",
"ethernet_table": [
{
@ -86,7 +82,9 @@ async def test_entry_diagnostics(
"type": "usw",
"version": "4.0.42.10433",
}
dpi_app = {
]
DPI_APP_DATA = [
{
"_id": "5f976f62e3c58f018ec7e17d",
"apps": [],
"blocked": True,
@ -95,142 +93,39 @@ async def test_entry_diagnostics(
"log": True,
"site_id": "name",
}
dpi_group = {
]
DPI_GROUP_DATA = [
{
"_id": "5f976f4ae3c58f018ec7dff6",
"name": "Block Media Streaming",
"site_id": "name",
"dpiapp_ids": ["5f976f62e3c58f018ec7e17d"],
}
]
options = {
CONF_ALLOW_BANDWIDTH_SENSORS: True,
CONF_ALLOW_UPTIME_SENSORS: True,
CONF_BLOCK_CLIENT: ["00:00:00:00:00:01"],
}
config_entry = await setup_unifi_integration(
hass,
aioclient_mock,
options=options,
clients_response=[client],
devices_response=[device],
dpiapp_response=[dpi_app],
dpigroup_response=[dpi_group],
@pytest.mark.parametrize(
"config_entry_options",
[
{
CONF_ALLOW_BANDWIDTH_SENSORS: True,
CONF_ALLOW_UPTIME_SENSORS: True,
CONF_BLOCK_CLIENT: ["00:00:00:00:00:01"],
}
],
)
@pytest.mark.parametrize("client_payload", [CLIENT_DATA])
@pytest.mark.parametrize("device_payload", [DEVICE_DATA])
@pytest.mark.parametrize("dpi_app_payload", [DPI_APP_DATA])
@pytest.mark.parametrize("dpi_group_payload", [DPI_GROUP_DATA])
async def test_entry_diagnostics(
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
config_entry_setup: ConfigEntry,
snapshot: SnapshotAssertion,
) -> None:
"""Test config entry diagnostics."""
assert (
await get_diagnostics_for_config_entry(hass, hass_client, config_entry_setup)
== snapshot
)
assert await get_diagnostics_for_config_entry(hass, hass_client, config_entry) == {
"config": {
"data": {
"host": REDACTED,
"password": REDACTED,
"port": 1234,
"site": "site_id",
"username": REDACTED,
"verify_ssl": False,
},
"disabled_by": None,
"domain": "unifi",
"entry_id": "1",
"minor_version": 1,
"options": {
"allow_bandwidth_sensors": True,
"allow_uptime_sensors": True,
"block_client": ["00:00:00:00:00:00"],
},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "user",
"title": "Mock Title",
"unique_id": "1",
"version": 1,
},
"role_is_admin": True,
"clients": {
"00:00:00:00:00:00": {
"blocked": False,
"hostname": "client_1",
"ip": "10.0.0.1",
"is_wired": True,
"last_seen": 1562600145,
"mac": "00:00:00:00:00:00",
"name": "POE Client 1",
"oui": "Producer",
"sw_mac": "00:00:00:00:00:01",
"sw_port": 1,
"wired-rx_bytes": 1234000000,
"wired-tx_bytes": 5678000000,
}
},
"devices": {
"00:00:00:00:00:01": {
"board_rev": "1.2.3",
"ethernet_table": [
{
"mac": "00:00:00:00:00:02",
"num_port": 2,
"name": "eth0",
}
],
"device_id": "mock-id",
"ip": "10.0.1.1",
"mac": "00:00:00:00:00:01",
"last_seen": 1562600145,
"model": "US16P150",
"name": "mock-name",
"port_overrides": [],
"port_table": [
{
"mac_table": [
{
"age": 1,
"mac": "00:00:00:00:00:00",
"static": False,
"uptime": 3971792,
"vlan": 1,
},
{
"age": 1,
"mac": REDACTED,
"static": True,
"uptime": 0,
"vlan": 0,
},
],
"media": "GE",
"name": "Port 1",
"port_idx": 1,
"poe_class": "Class 4",
"poe_enable": True,
"poe_mode": "auto",
"poe_power": "2.56",
"poe_voltage": "53.40",
"portconf_id": "1a1",
"port_poe": True,
"up": True,
},
],
"state": 1,
"type": "usw",
"version": "4.0.42.10433",
}
},
"dpi_apps": {
"5f976f62e3c58f018ec7e17d": {
"_id": "5f976f62e3c58f018ec7e17d",
"apps": [],
"blocked": True,
"cats": ["4"],
"enabled": True,
"log": True,
"site_id": "name",
}
},
"dpi_groups": {
"5f976f4ae3c58f018ec7dff6": {
"_id": "5f976f4ae3c58f018ec7dff6",
"name": "Block Media Streaming",
"site_id": "name",
"dpiapp_ids": ["5f976f62e3c58f018ec7e17d"],
}
},
"wlans": {},
}