mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-10-28 19:06:36 +08:00
66 lines
1.9 KiB
Python
66 lines
1.9 KiB
Python
"""
|
||
验证 Plex 子条目图片发现与本地图片回退。
|
||
"""
|
||
|
||
from unittest.mock import Mock
|
||
|
||
from app.modules.plex.plex import Plex
|
||
|
||
|
||
def _build_plex():
|
||
"""
|
||
构造绕过真实连接的Plex实例,便于单测直接注入plexapi mock。
|
||
"""
|
||
plex = Plex.__new__(Plex)
|
||
plex._host = "http://192.168.8.254:32400/"
|
||
plex._playhost = None
|
||
plex._token = "plex-token"
|
||
plex._plex = Mock()
|
||
return plex
|
||
|
||
|
||
def test_get_remote_image_by_id_uses_item_arts_for_children_key() -> None:
|
||
"""
|
||
子条目路径通过条目对象的图片接口取得远端背景图。
|
||
"""
|
||
plex = _build_plex()
|
||
plex._plex.fetchItems.side_effect = AssertionError("should not use raw fetchItems with /children key")
|
||
|
||
item = Mock()
|
||
item.TYPE = "show"
|
||
item.art = "/library/metadata/29242/art/1"
|
||
item.parentKey = None
|
||
item.arts.return_value = [Mock(key="https://image.tmdb.org/t/p/original/test.jpg")]
|
||
plex._plex.fetchItem.return_value = item
|
||
|
||
image_url = plex.get_remote_image_by_id(
|
||
item_id="/library/metadata/29242/children",
|
||
image_type="Backdrop",
|
||
plex_url=False,
|
||
)
|
||
|
||
assert image_url == "https://image.tmdb.org/t/p/original/test.jpg"
|
||
item.arts.assert_called_once_with()
|
||
plex._plex.fetchItem.assert_called_once_with(ekey="/library/metadata/29242/children")
|
||
|
||
|
||
def test_get_remote_image_by_id_falls_back_to_local_art_url() -> None:
|
||
"""
|
||
没有远端图片时回退到带访问令牌的本地背景图 URL。
|
||
"""
|
||
plex = _build_plex()
|
||
|
||
item = Mock()
|
||
item.TYPE = "show"
|
||
item.art = "/library/metadata/29242/art/1"
|
||
item.parentKey = None
|
||
item.arts.return_value = []
|
||
plex._plex.fetchItem.return_value = item
|
||
|
||
image_url = plex.get_remote_image_by_id(
|
||
item_id="/library/metadata/29242/children",
|
||
image_type="Backdrop",
|
||
)
|
||
|
||
assert image_url == "http://192.168.8.254:32400/library/metadata/29242/art/1?X-Plex-Token=plex-token"
|