Generic camera: Allow gif image type in still image checker (#68933)

This commit is contained in:
Dave T 2022-03-31 08:02:43 +01:00 committed by GitHub
parent f9aa0a7cd8
commit 7a5235dc0c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 2 deletions

View File

@ -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(

View File

@ -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."""

View File

@ -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(