Skip to content

Commit

Permalink
Use snapshot assertion for google assistant diagnostics test (#99167)
Browse files Browse the repository at this point in the history
  • Loading branch information
jpbede committed Aug 30, 2023
1 parent fb42042 commit 027ce55
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 83 deletions.
110 changes: 110 additions & 0 deletions tests/components/google_assistant/snapshots/test_diagnostics.ambr
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# serializer version: 1
# name: test_diagnostics
dict({
'config_entry': dict({
'data': dict({
'project_id': '1234',
}),
'disabled_by': None,
'domain': 'google_assistant',
'options': dict({
}),
'pref_disable_new_entities': False,
'pref_disable_polling': False,
'source': 'import',
'title': '1234',
'unique_id': '1234',
'version': 1,
}),
'query': dict({
'devices': dict({
'switch.ac': dict({
'on': False,
'online': True,
}),
'switch.decorative_lights': dict({
'on': True,
'online': True,
}),
}),
}),
'sync': dict({
'agentUserId': '**REDACTED**',
'devices': list([
dict({
'attributes': dict({
'commandOnlyOnOff': True,
}),
'customData': dict({
'httpPort': 8123,
'uuid': '**REDACTED**',
'webhookId': None,
}),
'id': 'switch.decorative_lights',
'name': dict({
'name': 'Decorative Lights',
}),
'otherDeviceIds': list([
dict({
'deviceId': 'switch.decorative_lights',
}),
]),
'traits': list([
'action.devices.traits.OnOff',
]),
'type': 'action.devices.types.SWITCH',
'willReportState': False,
}),
dict({
'attributes': dict({
}),
'customData': dict({
'httpPort': 8123,
'uuid': '**REDACTED**',
'webhookId': None,
}),
'id': 'switch.ac',
'name': dict({
'name': 'AC',
}),
'otherDeviceIds': list([
dict({
'deviceId': 'switch.ac',
}),
]),
'traits': list([
'action.devices.traits.OnOff',
]),
'type': 'action.devices.types.OUTLET',
'willReportState': False,
}),
]),
}),
'yaml_config': dict({
'expose_by_default': True,
'exposed_domains': list([
'alarm_control_panel',
'binary_sensor',
'climate',
'cover',
'fan',
'group',
'humidifier',
'input_boolean',
'input_select',
'light',
'lock',
'media_player',
'scene',
'script',
'select',
'sensor',
'switch',
'vacuum',
]),
'project_id': '1234',
'report_state': False,
'service_account': '**REDACTED**',
}),
})
# ---
92 changes: 9 additions & 83 deletions tests/components/google_assistant/test_diagnostics.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
"""Test diagnostics."""
from unittest.mock import ANY, patch
from unittest.mock import patch

import pytest
from syrupy import SnapshotAssertion
from syrupy.filters import props

from homeassistant import setup
from homeassistant.components import google_assistant as ga, switch
Expand All @@ -26,7 +28,9 @@ async def switch_only() -> None:


async def test_diagnostics(
hass: HomeAssistant, hass_client: ClientSessionGenerator
hass: HomeAssistant,
hass_client: ClientSessionGenerator,
snapshot: SnapshotAssertion,
) -> None:
"""Test diagnostics v1."""

Expand All @@ -42,84 +46,6 @@ async def test_diagnostics(
)

config_entry = hass.config_entries.async_entries("google_assistant")[0]
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
assert result == {
"config_entry": {
"data": {"project_id": "1234"},
"disabled_by": None,
"domain": "google_assistant",
"entry_id": ANY,
"options": {},
"pref_disable_new_entities": False,
"pref_disable_polling": False,
"source": "import",
"title": "1234",
"unique_id": "1234",
"version": 1,
},
"sync": {
"agentUserId": "**REDACTED**",
"devices": [
{
"attributes": {"commandOnlyOnOff": True},
"id": "switch.decorative_lights",
"otherDeviceIds": [{"deviceId": "switch.decorative_lights"}],
"name": {"name": "Decorative Lights"},
"traits": ["action.devices.traits.OnOff"],
"type": "action.devices.types.SWITCH",
"willReportState": False,
"customData": {
"httpPort": 8123,
"uuid": "**REDACTED**",
"webhookId": None,
},
},
{
"attributes": {},
"id": "switch.ac",
"otherDeviceIds": [{"deviceId": "switch.ac"}],
"name": {"name": "AC"},
"traits": ["action.devices.traits.OnOff"],
"type": "action.devices.types.OUTLET",
"willReportState": False,
"customData": {
"httpPort": 8123,
"uuid": "**REDACTED**",
"webhookId": None,
},
},
],
},
"query": {
"devices": {
"switch.ac": {"on": False, "online": True},
"switch.decorative_lights": {"on": True, "online": True},
}
},
"yaml_config": {
"expose_by_default": True,
"exposed_domains": [
"alarm_control_panel",
"binary_sensor",
"climate",
"cover",
"fan",
"group",
"humidifier",
"input_boolean",
"input_select",
"light",
"lock",
"media_player",
"scene",
"script",
"select",
"sensor",
"switch",
"vacuum",
],
"project_id": "1234",
"report_state": False,
"service_account": "**REDACTED**",
},
}
assert await get_diagnostics_for_config_entry(
hass, hass_client, config_entry
) == snapshot(exclude=props("entry_id"))

0 comments on commit 027ce55

Please sign in to comment.