feat: add Immich API client and photo proxy routes
Implements ImmichClient with list_albums, get_album, get_thumbnail, get_original methods; wraps connection errors as ConnectionError. Adds /proxy/thumb/<asset_id> and /proxy/original/<asset_id> Flask routes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import pytest
|
||||
from app.immich import ImmichClient
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def client(mock_immich):
|
||||
return ImmichClient(
|
||||
base_url=f"http://127.0.0.1:8099",
|
||||
api_key="test-key",
|
||||
)
|
||||
|
||||
|
||||
def test_list_albums(client):
|
||||
albums = client.list_albums()
|
||||
assert len(albums) == 1
|
||||
assert albums[0]["albumName"] == "Central Asia 2023"
|
||||
|
||||
|
||||
def test_get_album(client):
|
||||
album = client.get_album("album-1")
|
||||
assert len(album["assets"]) == 3
|
||||
|
||||
|
||||
def test_get_thumbnail_returns_bytes(client):
|
||||
data = client.get_thumbnail("asset-1")
|
||||
assert isinstance(data, bytes)
|
||||
assert len(data) > 0
|
||||
|
||||
|
||||
def test_get_original_returns_bytes(client):
|
||||
data = client.get_original("asset-1")
|
||||
assert isinstance(data, bytes)
|
||||
|
||||
|
||||
def test_list_albums_connection_error_raises(monkeypatch):
|
||||
client = ImmichClient(base_url="http://127.0.0.1:1", api_key="x")
|
||||
with pytest.raises(ConnectionError):
|
||||
client.list_albums()
|
||||
|
||||
|
||||
def test_proxy_thumb_route(base_url, page, seed_state):
|
||||
seed_state("phase2_state")
|
||||
page.goto(f"{base_url}/proxy/thumb/asset-1")
|
||||
assert page.evaluate("document.contentType").startswith("image/")
|
||||
|
||||
|
||||
def test_proxy_original_route(base_url, page, seed_state):
|
||||
seed_state("phase2_state")
|
||||
page.goto(f"{base_url}/proxy/original/asset-1")
|
||||
assert page.evaluate("document.contentType").startswith("image/")
|
||||
Reference in New Issue
Block a user