Initial commit: add Gitea PyPI publish workflow
This commit is contained in:
93
tests/test_media_library.py
Normal file
93
tests/test_media_library.py
Normal file
@@ -0,0 +1,93 @@
|
||||
"""Tests for the Jellyfin media library client."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import json
|
||||
|
||||
import pytest
|
||||
import respx
|
||||
from httpx import Response
|
||||
|
||||
from conduit_client import AsyncConduitClient, ConduitClient
|
||||
from conduit_client.models.media_library import LibraryLoginRequest, LibrarySearchQuery
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_login(api_key: str) -> None:
|
||||
route = respx.post("https://api.example.com/media/library/auth/login").mock(
|
||||
return_value=Response(200, json={"access_token": "tok", "user_id": "u1"})
|
||||
)
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = client.media_library.login(LibraryLoginRequest(username="user", password="pw"))
|
||||
assert result.access_token == "tok"
|
||||
assert json.loads(route.calls[0].request.content) == {
|
||||
"username": "user",
|
||||
"password": "pw",
|
||||
}
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_search(api_key: str) -> None:
|
||||
route = respx.get("https://api.example.com/media/library/search").mock(
|
||||
return_value=Response(200, json={"Items": []})
|
||||
)
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = client.media_library.search(LibrarySearchQuery(term="cat"))
|
||||
assert result == {"Items": []}
|
||||
assert route.calls[0].request.url.params["term"] == "cat"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_get_item_and_playback(api_key: str) -> None:
|
||||
respx.get("https://api.example.com/media/library/items/i1").mock(
|
||||
return_value=Response(200, json={"Id": "i1", "Name": "Movie"})
|
||||
)
|
||||
respx.get("https://api.example.com/media/library/items/i1/playback").mock(
|
||||
return_value=Response(200, json={"MediaSources": []})
|
||||
)
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
item = client.media_library.get_item("i1")
|
||||
playback = client.media_library.get_playback_info("i1")
|
||||
assert item["Name"] == "Movie"
|
||||
assert playback == {"MediaSources": []}
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_refresh(api_key: str) -> None:
|
||||
respx.post("https://api.example.com/media/library/refresh").mock(return_value=Response(204))
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
client.media_library.refresh()
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_list_sessions(api_key: str) -> None:
|
||||
respx.get("https://api.example.com/media/library/sessions").mock(
|
||||
return_value=Response(200, json=[{"id": "s1", "device_name": "TV"}])
|
||||
)
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = client.media_library.list_sessions()
|
||||
assert result[0].device_name == "TV"
|
||||
|
||||
|
||||
@respx.mock
|
||||
def test_system_info(api_key: str) -> None:
|
||||
route = respx.get("https://api.example.com/media/library/system/info").mock(
|
||||
return_value=Response(200, json={"version": "10.0", "id": "abc"})
|
||||
)
|
||||
with ConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = client.media_library.system_info(public=True)
|
||||
assert result.version == "10.0"
|
||||
assert route.calls[0].request.url.params["public"] == "true"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
@respx.mock
|
||||
async def test_async_login(api_key: str) -> None:
|
||||
respx.post("https://api.example.com/media/library/auth/login").mock(
|
||||
return_value=Response(200, json={"access_token": "tok", "user_id": "u1"})
|
||||
)
|
||||
async with AsyncConduitClient(api_key, base_url="https://api.example.com") as client:
|
||||
result = await client.media_library.login(
|
||||
LibraryLoginRequest(username="user", password="pw")
|
||||
)
|
||||
assert result.access_token == "tok"
|
||||
Reference in New Issue
Block a user