1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 12:59:34 +00:00

Add validation of content_type to image entity (#95248)

This commit is contained in:
Jan Bouwhuis
2023-06-27 11:46:31 +02:00
committed by GitHub
parent af7b25d748
commit 22f29e8c84
3 changed files with 68 additions and 9 deletions

View File

@@ -36,6 +36,21 @@ class MockImageEntity(image.ImageEntity):
return b"Test"
class MockImageEntityInvalidContentType(image.ImageEntity):
"""Mock image entity."""
_attr_name = "Test"
async def async_added_to_hass(self):
"""Set the update time and assign and incorrect content type."""
self._attr_content_type = "text/json"
self._attr_image_last_updated = dt_util.utcnow()
async def async_image(self) -> bytes | None:
"""Return bytes of image."""
return b"Test"
class MockURLImageEntity(image.ImageEntity):
"""Mock image entity."""
@@ -125,7 +140,9 @@ def config_flow_fixture(hass: HomeAssistant) -> Generator[None, None, None]:
@pytest.fixture(name="mock_image_config_entry")
async def mock_image_config_entry_fixture(hass: HomeAssistant, config_flow: None):
async def mock_image_config_entry_fixture(
hass: HomeAssistant, config_flow: None
) -> ConfigEntry:
"""Initialize a mock image config_entry."""
async def async_setup_entry_init(
@@ -166,7 +183,7 @@ async def mock_image_config_entry_fixture(hass: HomeAssistant, config_flow: None
@pytest.fixture(name="mock_image_platform")
async def mock_image_platform_fixture(hass: HomeAssistant):
async def mock_image_platform_fixture(hass: HomeAssistant) -> None:
"""Initialize a mock image platform."""
mock_integration(hass, MockModule(domain="test"))
mock_platform(hass, "test.image", MockImagePlatform([MockImageEntity(hass)]))