Use snapshot assertion for Co2signal diagnostics test (#98905)
This commit is contained in:
parent
a1307e117d
commit
faa4489f4c
2 changed files with 42 additions and 10 deletions
33
tests/components/co2signal/snapshots/test_diagnostics.ambr
Normal file
33
tests/components/co2signal/snapshots/test_diagnostics.ambr
Normal file
|
@ -0,0 +1,33 @@
|
|||
# serializer version: 1
|
||||
# name: test_entry_diagnostics
|
||||
dict({
|
||||
'config_entry': dict({
|
||||
'data': dict({
|
||||
'api_key': '**REDACTED**',
|
||||
'location': '',
|
||||
}),
|
||||
'disabled_by': None,
|
||||
'domain': 'co2signal',
|
||||
'entry_id': '904a74160aa6f335526706bee85dfb83',
|
||||
'options': dict({
|
||||
}),
|
||||
'pref_disable_new_entities': False,
|
||||
'pref_disable_polling': False,
|
||||
'source': 'user',
|
||||
'title': 'Mock Title',
|
||||
'unique_id': None,
|
||||
'version': 1,
|
||||
}),
|
||||
'data': dict({
|
||||
'countryCode': 'FR',
|
||||
'data': dict({
|
||||
'carbonIntensity': 45.98623190095805,
|
||||
'fossilFuelPercentage': 5.461182741937103,
|
||||
}),
|
||||
'status': 'ok',
|
||||
'units': dict({
|
||||
'carbonIntensity': 'gCO2eq/kWh',
|
||||
}),
|
||||
}),
|
||||
})
|
||||
# ---
|
|
@ -1,8 +1,9 @@
|
|||
"""Test the CO2Signal diagnostics."""
|
||||
from unittest.mock import patch
|
||||
|
||||
from syrupy import SnapshotAssertion
|
||||
|
||||
from homeassistant.components.co2signal import DOMAIN
|
||||
from homeassistant.components.diagnostics import REDACTED
|
||||
from homeassistant.const import CONF_API_KEY
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.setup import async_setup_component
|
||||
|
@ -15,11 +16,15 @@ from tests.typing import ClientSessionGenerator
|
|||
|
||||
|
||||
async def test_entry_diagnostics(
|
||||
hass: HomeAssistant, hass_client: ClientSessionGenerator
|
||||
hass: HomeAssistant,
|
||||
hass_client: ClientSessionGenerator,
|
||||
snapshot: SnapshotAssertion,
|
||||
) -> None:
|
||||
"""Test config entry diagnostics."""
|
||||
config_entry = MockConfigEntry(
|
||||
domain=DOMAIN, data={CONF_API_KEY: "api_key", "location": ""}
|
||||
domain=DOMAIN,
|
||||
data={CONF_API_KEY: "api_key", "location": ""},
|
||||
entry_id="904a74160aa6f335526706bee85dfb83",
|
||||
)
|
||||
config_entry.add_to_hass(hass)
|
||||
with patch("CO2Signal.get_latest", return_value=VALID_PAYLOAD):
|
||||
|
@ -27,10 +32,4 @@ async def test_entry_diagnostics(
|
|||
|
||||
result = await get_diagnostics_for_config_entry(hass, hass_client, config_entry)
|
||||
|
||||
config_entry_dict = config_entry.as_dict()
|
||||
config_entry_dict["data"][CONF_API_KEY] = REDACTED
|
||||
|
||||
assert result == {
|
||||
"config_entry": config_entry_dict,
|
||||
"data": VALID_PAYLOAD,
|
||||
}
|
||||
assert result == snapshot
|
||||
|
|
Loading…
Add table
Reference in a new issue