Add tests for browse media image proxy (#43076)

* add tests for browse media image proxy

* Update test_init.py

* Update __init__.py

* Update __init__.py

* Update __init__.py

* Update __init__.py
pull/43272/head
Chris Talkington 2020-11-16 00:49:41 -06:00 committed by GitHub
parent 7dcfc8f1fa
commit 467d79c7fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 38 additions and 5 deletions

View File

@ -7,7 +7,7 @@ import functools as ft
import hashlib
import logging
import secrets
from typing import List, Optional
from typing import List, Optional, Tuple
from urllib.parse import urlparse
from aiohttp import web
@ -434,8 +434,11 @@ class MediaPlayerEntity(Entity):
return await self._async_fetch_image_from_cache(url)
async def async_get_browse_image(
self, media_content_type, media_content_id, media_image_id=None
):
self,
media_content_type: str,
media_content_id: str,
media_image_id: Optional[str] = None,
) -> Tuple[Optional[str], Optional[str]]:
"""
Optionally fetch internally accessible image for media browser.
@ -906,8 +909,11 @@ class MediaPlayerEntity(Entity):
return content, content_type
def get_browse_image_url(
self, media_content_type, media_content_id, media_image_id=None
):
self,
media_content_type: str,
media_content_id: str,
media_image_id: Optional[str] = None,
) -> str:
"""Generate an url for a media browser image."""
url_path = (
f"/api/media_player_proxy/{self.entity_id}/browse_media"

View File

@ -92,6 +92,33 @@ async def test_get_image_http_remote(hass, aiohttp_client):
assert content == b"image"
async def test_get_async_get_browse_image(hass, aiohttp_client, hass_ws_client):
"""Test get browse image."""
await async_setup_component(
hass, "media_player", {"media_player": {"platform": "demo"}}
)
await hass.async_block_till_done()
entity_comp = hass.data.get("entity_components", {}).get("media_player")
assert entity_comp
player = entity_comp.get_entity("media_player.bedroom")
assert player
client = await aiohttp_client(hass.http.app)
with patch(
"homeassistant.components.media_player.MediaPlayerEntity."
"async_get_browse_image",
return_value=(b"image", "image/jpeg"),
):
url = player.get_browse_image_url("album", "abcd")
resp = await client.get(url)
content = await resp.read()
assert content == b"image"
def test_deprecated_base_class(caplog):
"""Test deprecated base class."""