From b39f7d6a71aaf2480a34a5fea9124a3071c60bfe Mon Sep 17 00:00:00 2001 From: Joost Lekkerkerker Date: Fri, 21 Jul 2023 09:54:06 +0200 Subject: [PATCH] Add snapshot testing to YouTube (#96974) --- .../youtube/snapshots/test_sensor.ambr | 31 +++++++++++++++++++ tests/components/youtube/test_sensor.py | 22 ++++--------- 2 files changed, 37 insertions(+), 16 deletions(-) create mode 100644 tests/components/youtube/snapshots/test_sensor.ambr diff --git a/tests/components/youtube/snapshots/test_sensor.ambr b/tests/components/youtube/snapshots/test_sensor.ambr new file mode 100644 index 00000000000..c5aac39156d --- /dev/null +++ b/tests/components/youtube/snapshots/test_sensor.ambr @@ -0,0 +1,31 @@ +# serializer version: 1 +# name: test_sensor + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'entity_picture': 'https://i.ytimg.com/vi/wysukDrMdqU/sddefault.jpg', + 'friendly_name': 'Google for Developers Latest upload', + 'icon': 'mdi:youtube', + 'video_id': 'wysukDrMdqU', + }), + 'context': , + 'entity_id': 'sensor.google_for_developers_latest_upload', + 'last_changed': , + 'last_updated': , + 'state': "What's new in Google Home in less than 1 minute", + }) +# --- +# name: test_sensor.1 + StateSnapshot({ + 'attributes': ReadOnlyDict({ + 'entity_picture': 'https://yt3.ggpht.com/fca_HuJ99xUxflWdex0XViC3NfctBFreIl8y4i9z411asnGTWY-Ql3MeH_ybA4kNaOjY7kyA=s800-c-k-c0x00ffffff-no-rj', + 'friendly_name': 'Google for Developers Subscribers', + 'icon': 'mdi:youtube-subscription', + 'unit_of_measurement': 'subscribers', + }), + 'context': , + 'entity_id': 'sensor.google_for_developers_subscribers', + 'last_changed': , + 'last_updated': , + 'state': '2290000', + }) +# --- diff --git a/tests/components/youtube/test_sensor.py b/tests/components/youtube/test_sensor.py index 6bd99399952..f2c5274c4a7 100644 --- a/tests/components/youtube/test_sensor.py +++ b/tests/components/youtube/test_sensor.py @@ -4,6 +4,7 @@ from unittest.mock import patch from google.auth.exceptions import RefreshError import pytest +from syrupy import SnapshotAssertion from homeassistant import config_entries from homeassistant.components.youtube import DOMAIN @@ -16,28 +17,17 @@ from .conftest import TOKEN, ComponentSetup from tests.common import async_fire_time_changed -async def test_sensor(hass: HomeAssistant, setup_integration: ComponentSetup) -> None: +async def test_sensor( + hass: HomeAssistant, snapshot: SnapshotAssertion, setup_integration: ComponentSetup +) -> None: """Test sensor.""" await setup_integration() state = hass.states.get("sensor.google_for_developers_latest_upload") - assert state - assert state.name == "Google for Developers Latest upload" - assert state.state == "What's new in Google Home in less than 1 minute" - assert ( - state.attributes["entity_picture"] - == "https://i.ytimg.com/vi/wysukDrMdqU/sddefault.jpg" - ) - assert state.attributes["video_id"] == "wysukDrMdqU" + assert state == snapshot state = hass.states.get("sensor.google_for_developers_subscribers") - assert state - assert state.name == "Google for Developers Subscribers" - assert state.state == "2290000" - assert ( - state.attributes["entity_picture"] - == "https://yt3.ggpht.com/fca_HuJ99xUxflWdex0XViC3NfctBFreIl8y4i9z411asnGTWY-Ql3MeH_ybA4kNaOjY7kyA=s800-c-k-c0x00ffffff-no-rj" - ) + assert state == snapshot async def test_sensor_updating(