diff --git a/homeassistant/components/generic/config_flow.py b/homeassistant/components/generic/config_flow.py index 5c61966808d..c5c645264d6 100644 --- a/homeassistant/components/generic/config_flow.py +++ b/homeassistant/components/generic/config_flow.py @@ -57,7 +57,7 @@ DEFAULT_DATA = { CONF_VERIFY_SSL: True, } -SUPPORTED_IMAGE_TYPES = ["png", "jpeg", "svg+xml"] +SUPPORTED_IMAGE_TYPES = {"png", "jpeg", "gif", "svg+xml"} def build_schema( diff --git a/tests/components/generic/conftest.py b/tests/components/generic/conftest.py index 63f7a87cba0..9daa3574e6e 100644 --- a/tests/components/generic/conftest.py +++ b/tests/components/generic/conftest.py @@ -36,12 +36,26 @@ def fakeimgbytes_svg(): ) +@pytest.fixture(scope="package") +def fakeimgbytes_gif(): + """Fake image in RAM for testing.""" + buf = BytesIO() # fake image in ram for testing. + Image.new("RGB", (1, 1)).save(buf, format="gif") + yield bytes(buf.getbuffer()) + + @pytest.fixture def fakeimg_png(fakeimgbytes_png): """Set up respx to respond to test url with fake image bytes.""" respx.get("http://127.0.0.1/testurl/1").respond(stream=fakeimgbytes_png) +@pytest.fixture +def fakeimg_gif(fakeimgbytes_gif): + """Set up respx to respond to test url with fake image bytes.""" + respx.get("http://127.0.0.1/testurl/1").respond(stream=fakeimgbytes_gif) + + @pytest.fixture(scope="package") def mock_av_open(): """Fake container object with .streams.video[0] != None.""" diff --git a/tests/components/generic/test_config_flow.py b/tests/components/generic/test_config_flow.py index b3811f61acc..7849e54c747 100644 --- a/tests/components/generic/test_config_flow.py +++ b/tests/components/generic/test_config_flow.py @@ -110,12 +110,24 @@ async def test_form_only_stillimage(hass, fakeimg_png, user_flow): assert respx.calls.call_count == 1 +@respx.mock +async def test_form_only_stillimage_gif(hass, fakeimg_gif, user_flow): + """Test we complete ok if the user wants a gif.""" + data = TESTDATA.copy() + data.pop(CONF_STREAM_SOURCE) + result2 = await hass.config_entries.flow.async_configure( + user_flow["flow_id"], + data, + ) + assert result2["type"] == data_entry_flow.RESULT_TYPE_CREATE_ENTRY + assert result2["options"][CONF_CONTENT_TYPE] == "image/gif" + + @respx.mock async def test_form_only_svg_whitespace(hass, fakeimgbytes_svg, user_flow): """Test we complete ok if svg starts with whitespace, issue #68889.""" fakeimgbytes_wspace_svg = bytes(" \n ", encoding="utf-8") + fakeimgbytes_svg respx.get("http://127.0.0.1/testurl/1").respond(stream=fakeimgbytes_wspace_svg) - data = TESTDATA.copy() data.pop(CONF_STREAM_SOURCE) result2 = await hass.config_entries.flow.async_configure(