mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 06:07:17 +00:00
Generic camera: Allow gif image type in still image checker (#68933)
This commit is contained in:
parent
f9aa0a7cd8
commit
7a5235dc0c
@ -57,7 +57,7 @@ DEFAULT_DATA = {
|
|||||||
CONF_VERIFY_SSL: True,
|
CONF_VERIFY_SSL: True,
|
||||||
}
|
}
|
||||||
|
|
||||||
SUPPORTED_IMAGE_TYPES = ["png", "jpeg", "svg+xml"]
|
SUPPORTED_IMAGE_TYPES = {"png", "jpeg", "gif", "svg+xml"}
|
||||||
|
|
||||||
|
|
||||||
def build_schema(
|
def build_schema(
|
||||||
|
@ -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
|
@pytest.fixture
|
||||||
def fakeimg_png(fakeimgbytes_png):
|
def fakeimg_png(fakeimgbytes_png):
|
||||||
"""Set up respx to respond to test url with fake image bytes."""
|
"""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)
|
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")
|
@pytest.fixture(scope="package")
|
||||||
def mock_av_open():
|
def mock_av_open():
|
||||||
"""Fake container object with .streams.video[0] != None."""
|
"""Fake container object with .streams.video[0] != None."""
|
||||||
|
@ -110,12 +110,24 @@ async def test_form_only_stillimage(hass, fakeimg_png, user_flow):
|
|||||||
assert respx.calls.call_count == 1
|
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
|
@respx.mock
|
||||||
async def test_form_only_svg_whitespace(hass, fakeimgbytes_svg, user_flow):
|
async def test_form_only_svg_whitespace(hass, fakeimgbytes_svg, user_flow):
|
||||||
"""Test we complete ok if svg starts with whitespace, issue #68889."""
|
"""Test we complete ok if svg starts with whitespace, issue #68889."""
|
||||||
fakeimgbytes_wspace_svg = bytes(" \n ", encoding="utf-8") + fakeimgbytes_svg
|
fakeimgbytes_wspace_svg = bytes(" \n ", encoding="utf-8") + fakeimgbytes_svg
|
||||||
respx.get("http://127.0.0.1/testurl/1").respond(stream=fakeimgbytes_wspace_svg)
|
respx.get("http://127.0.0.1/testurl/1").respond(stream=fakeimgbytes_wspace_svg)
|
||||||
|
|
||||||
data = TESTDATA.copy()
|
data = TESTDATA.copy()
|
||||||
data.pop(CONF_STREAM_SOURCE)
|
data.pop(CONF_STREAM_SOURCE)
|
||||||
result2 = await hass.config_entries.flow.async_configure(
|
result2 = await hass.config_entries.flow.async_configure(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user