mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 12:17:07 +00:00
Split redact set; add tests
This commit is contained in:
parent
aa69272297
commit
138a1c5112
@ -10,12 +10,12 @@ from homeassistant.core import HomeAssistant
|
||||
|
||||
from .const import DOMAIN
|
||||
|
||||
TO_REDACT = {
|
||||
# Entry fields
|
||||
ENTRY_FIELDS_DATA_TO_REDACT = {
|
||||
"mac",
|
||||
"username",
|
||||
"password",
|
||||
# device_information
|
||||
}
|
||||
DEVICE_INFORMATION_DATA_TO_REDACT = {
|
||||
"SerialNumber",
|
||||
"Imei",
|
||||
"Imsi",
|
||||
@ -30,7 +30,8 @@ TO_REDACT = {
|
||||
"Mccmnc",
|
||||
"WifiMacAddrWl0",
|
||||
"WifiMacAddrWl1",
|
||||
# device_signal
|
||||
}
|
||||
DEVICE_SIGNAL_DATA_TO_REDACT = {
|
||||
"pci",
|
||||
"cell_id",
|
||||
"rac",
|
||||
@ -39,21 +40,36 @@ TO_REDACT = {
|
||||
"nei_cellid",
|
||||
"plmn",
|
||||
"bsic",
|
||||
# monitoring_status
|
||||
}
|
||||
MONITORING_STATUS_DATA_TO_REDACT = {
|
||||
"PrimaryDns",
|
||||
"SecondaryDns",
|
||||
"PrimaryIPv6Dns",
|
||||
"SecondaryIPv6Dns",
|
||||
# net_current_plmn
|
||||
}
|
||||
NET_CURRENT_PLMN_DATA_TO_REDACT = {
|
||||
"net_current_plmn",
|
||||
# lan_host_info
|
||||
}
|
||||
LAN_HOST_INFO_DATA_TO_REDACT = {
|
||||
"lan_host_info",
|
||||
# wlan_wifi_guest_network_switch
|
||||
}
|
||||
WLAN_WIFI_GUEST_NETWORK_SWITCH_DATA_TO_REDACT = {
|
||||
"Ssid",
|
||||
"WifiSsid",
|
||||
# wlan.multi_basic_settings
|
||||
}
|
||||
WLAN_MULTI_BASIC_SETTINGS_DATA_TO_REDACT = {
|
||||
"WifiMac",
|
||||
}
|
||||
TO_REDACT = {
|
||||
*ENTRY_FIELDS_DATA_TO_REDACT,
|
||||
*DEVICE_INFORMATION_DATA_TO_REDACT,
|
||||
*DEVICE_SIGNAL_DATA_TO_REDACT,
|
||||
*MONITORING_STATUS_DATA_TO_REDACT,
|
||||
*NET_CURRENT_PLMN_DATA_TO_REDACT,
|
||||
*LAN_HOST_INFO_DATA_TO_REDACT,
|
||||
*WLAN_WIFI_GUEST_NETWORK_SWITCH_DATA_TO_REDACT,
|
||||
*WLAN_MULTI_BASIC_SETTINGS_DATA_TO_REDACT,
|
||||
}
|
||||
|
||||
|
||||
async def async_get_config_entry_diagnostics(
|
||||
|
@ -21,3 +21,140 @@ def magic_client(multi_basic_settings_value: dict) -> MagicMock:
|
||||
wifi_feature_switch=wifi_feature_switch,
|
||||
)
|
||||
return MagicMock(device=device, monitoring=monitoring, wlan=wlan)
|
||||
|
||||
|
||||
def magic_client_full() -> MagicMock:
|
||||
"""Extended mock for huawei_lte.Client with all API methods."""
|
||||
information = MagicMock(
|
||||
return_value={
|
||||
"SerialNumber": "test-serial-number",
|
||||
"DeviceName": "Test Router",
|
||||
"HardwareVersion": "1.0.0",
|
||||
"SoftwareVersion": "2.0.0",
|
||||
}
|
||||
)
|
||||
basic_information = MagicMock(
|
||||
return_value={"devicename": "Test Router", "SoftwareVersion": "2.0.0"}
|
||||
)
|
||||
signal = MagicMock(
|
||||
return_value={"rssi": "-70", "rsrp": "-100", "rsrq": "-10", "sinr": "10"}
|
||||
)
|
||||
|
||||
check_notifications = MagicMock(return_value={"SmsStorageFull": 0})
|
||||
status = MagicMock(return_value={"ConnectionStatus": "901"})
|
||||
month_statistics = MagicMock(
|
||||
return_value={
|
||||
"CurrentMonthDownload": "1000000000",
|
||||
"CurrentMonthUpload": "500000000",
|
||||
"MonthDuration": "720000",
|
||||
}
|
||||
)
|
||||
traffic_statistics = MagicMock(
|
||||
return_value={
|
||||
"CurrentDownload": "5000000000",
|
||||
"CurrentUpload": "2000000000",
|
||||
"TotalDownload": "50000000000",
|
||||
"TotalUpload": "20000000000",
|
||||
}
|
||||
)
|
||||
|
||||
current_plmn = MagicMock(
|
||||
return_value={
|
||||
"State": "1",
|
||||
"FullName": "Test Network",
|
||||
"ShortName": "Test",
|
||||
"Numeric": "12345",
|
||||
}
|
||||
)
|
||||
net_mode = MagicMock(
|
||||
return_value={
|
||||
"NetworkMode": "03",
|
||||
"NetworkBand": "3FFFFFFF",
|
||||
"LTEBand": "7FFFFFFFFFFFFFFF",
|
||||
}
|
||||
)
|
||||
|
||||
sms_count = MagicMock(
|
||||
return_value={
|
||||
"LocalUnread": "0",
|
||||
"LocalInbox": "5",
|
||||
"LocalOutbox": "2",
|
||||
"LocalDraft": "1",
|
||||
"SimUnread": "0",
|
||||
"SimInbox": "0",
|
||||
"SimOutbox": "0",
|
||||
"SimDraft": "0",
|
||||
}
|
||||
)
|
||||
|
||||
mobile_dataswitch = MagicMock(return_value={"dataswitch": "1"})
|
||||
|
||||
lan_host_info = MagicMock(
|
||||
return_value={
|
||||
"Hosts": {
|
||||
"Host": [
|
||||
{
|
||||
"ID": "1",
|
||||
"MacAddress": "AA:BB:CC:DD:EE:FF",
|
||||
"IpAddress": "192.168.1.100",
|
||||
"HostName": "TestDevice1",
|
||||
"AssociatedSsid": "TestSSID",
|
||||
},
|
||||
{
|
||||
"ID": "2",
|
||||
"MacAddress": "11:22:33:44:55:66",
|
||||
"IpAddress": "192.168.1.101",
|
||||
"HostName": "TestDevice2",
|
||||
"AssociatedSsid": "TestSSID",
|
||||
},
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
wlan_host_list = MagicMock(
|
||||
return_value={
|
||||
"Hosts": {
|
||||
"Host": [
|
||||
{
|
||||
"ID": "1",
|
||||
"MacAddress": "AA:BB:CC:DD:EE:FF",
|
||||
"IpAddress": "192.168.1.100",
|
||||
"HostName": "TestDevice1",
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
)
|
||||
multi_basic_settings = MagicMock(
|
||||
return_value={"Ssid": [{"wifiisguestnetwork": "1", "WifiEnable": "0"}]}
|
||||
)
|
||||
wifi_feature_switch = MagicMock(return_value={"wifi24g_switch_enable": 1})
|
||||
|
||||
device = MagicMock(
|
||||
information=information, basic_information=basic_information, signal=signal
|
||||
)
|
||||
monitoring = MagicMock(
|
||||
check_notifications=check_notifications,
|
||||
status=status,
|
||||
month_statistics=month_statistics,
|
||||
traffic_statistics=traffic_statistics,
|
||||
)
|
||||
net = MagicMock(current_plmn=current_plmn, net_mode=net_mode)
|
||||
sms = MagicMock(sms_count=sms_count)
|
||||
dial_up = MagicMock(mobile_dataswitch=mobile_dataswitch)
|
||||
lan = MagicMock(host_info=lan_host_info)
|
||||
wlan = MagicMock(
|
||||
multi_basic_settings=multi_basic_settings,
|
||||
wifi_feature_switch=wifi_feature_switch,
|
||||
host_list=wlan_host_list,
|
||||
)
|
||||
|
||||
return MagicMock(
|
||||
device=device,
|
||||
monitoring=monitoring,
|
||||
net=net,
|
||||
sms=sms,
|
||||
dial_up=dial_up,
|
||||
lan=lan,
|
||||
wlan=wlan,
|
||||
)
|
||||
|
65
tests/components/huawei_lte/snapshots/test_diagnostics.ambr
Normal file
65
tests/components/huawei_lte/snapshots/test_diagnostics.ambr
Normal file
@ -0,0 +1,65 @@
|
||||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'entry': dict({
|
||||
'mac': '**REDACTED**',
|
||||
'url': 'http://huawei-lte.example.com',
|
||||
}),
|
||||
'router': dict({
|
||||
'device_information': dict({
|
||||
'DeviceName': 'Test Router',
|
||||
'HardwareVersion': '1.0.0',
|
||||
'SerialNumber': '**REDACTED**',
|
||||
'SoftwareVersion': '2.0.0',
|
||||
}),
|
||||
'device_signal': dict({
|
||||
'rsrp': '-100',
|
||||
'rsrq': '-10',
|
||||
'rssi': '-70',
|
||||
'sinr': '10',
|
||||
}),
|
||||
'dialup_mobile_dataswitch': dict({
|
||||
'dataswitch': '1',
|
||||
}),
|
||||
'lan_host_info': '**REDACTED**',
|
||||
'monitoring_check_notifications': dict({
|
||||
'SmsStorageFull': 0,
|
||||
}),
|
||||
'monitoring_month_statistics': dict({
|
||||
'CurrentMonthDownload': '1000000000',
|
||||
'CurrentMonthUpload': '500000000',
|
||||
'MonthDuration': '720000',
|
||||
}),
|
||||
'monitoring_status': dict({
|
||||
'ConnectionStatus': '901',
|
||||
}),
|
||||
'monitoring_traffic_statistics': dict({
|
||||
'CurrentDownload': '5000000000',
|
||||
'CurrentUpload': '2000000000',
|
||||
'TotalDownload': '50000000000',
|
||||
'TotalUpload': '20000000000',
|
||||
}),
|
||||
'net_current_plmn': '**REDACTED**',
|
||||
'net_net_mode': dict({
|
||||
'LTEBand': '7FFFFFFFFFFFFFFF',
|
||||
'NetworkBand': '3FFFFFFF',
|
||||
'NetworkMode': '03',
|
||||
}),
|
||||
'sms_sms_count': dict({
|
||||
'LocalDraft': '1',
|
||||
'LocalInbox': '5',
|
||||
'LocalOutbox': '2',
|
||||
'LocalUnread': '0',
|
||||
'SimDraft': '0',
|
||||
'SimInbox': '0',
|
||||
'SimOutbox': '0',
|
||||
'SimUnread': '0',
|
||||
}),
|
||||
'wlan_wifi_feature_switch': dict({
|
||||
'wifi24g_switch_enable': 1,
|
||||
}),
|
||||
'wlan_wifi_guest_network_switch': dict({
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
38
tests/components/huawei_lte/test_diagnostics.py
Normal file
38
tests/components/huawei_lte/test_diagnostics.py
Normal file
@ -0,0 +1,38 @@
|
||||
"""Test huawei_lte diagnostics."""
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from syrupy.assertion import SnapshotAssertion
|
||||
from syrupy.filters import props
|
||||
|
||||
from homeassistant.components.huawei_lte.const import DOMAIN
|
||||
from homeassistant.const import CONF_URL
|
||||
from homeassistant.core import HomeAssistant
|
||||
|
||||
from . import magic_client_full
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.diagnostics import get_diagnostics_for_config_entry
|
||||
from tests.typing import ClientSessionGenerator
|
||||
|
||||
|
||||
@patch("homeassistant.components.huawei_lte.Connection", MagicMock())
|
||||
@patch("homeassistant.components.huawei_lte.Client")
|
||||
async def test_entry_diagnostics(
|
||||
client,
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
client.return_value = magic_client_full()
|
||||
huawei_lte = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_URL: "http://huawei-lte.example.com"}
|
||||
)
|
||||
huawei_lte.add_to_hass(hass)
|
||||
await hass.config_entries.async_setup(huawei_lte.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, huawei_lte)
|
||||
|
||||
assert result == snapshot(exclude=props("entry_id", "created_at", "modified_at"))
|
Loading…
x
Reference in New Issue
Block a user