feat(trip-cluster): config, factory, CLI skeleton, health + thumb proxy
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
import os
|
||||
import pytest
|
||||
from app.config import load_config, ConfigError
|
||||
|
||||
|
||||
def test_missing_required_raises():
|
||||
with pytest.raises(ConfigError) as e:
|
||||
load_config({"IMMICH_URL": "http://x"})
|
||||
assert "IMMICH_API_KEY" in e.value.missing
|
||||
|
||||
|
||||
def test_anthropic_optional_and_paths(tmp_path):
|
||||
cfg = load_config({"IMMICH_URL": "http://x/", "IMMICH_API_KEY": "k",
|
||||
"DATA_DIR": str(tmp_path)})
|
||||
assert cfg.immich_url == "http://x" # trailing slash stripped
|
||||
assert cfg.anthropic_api_key == "" # optional in M1
|
||||
assert cfg.db_path == os.path.join(str(tmp_path), "trip-cluster.db")
|
||||
assert cfg.thumbs_dir == os.path.join(str(tmp_path), "thumbs")
|
||||
@@ -0,0 +1,26 @@
|
||||
import os
|
||||
from app import create_app
|
||||
from app.config import Config
|
||||
|
||||
|
||||
def _app(tmp_path):
|
||||
cfg = Config(immich_url="http://x", immich_api_key="k",
|
||||
anthropic_api_key="", data_dir=str(tmp_path))
|
||||
app = create_app(cfg)
|
||||
app.config.update(TESTING=True)
|
||||
return app
|
||||
|
||||
|
||||
def test_health(tmp_path):
|
||||
assert _app(tmp_path).test_client().get("/health").data == b"ok"
|
||||
|
||||
|
||||
def test_thumb_served(tmp_path):
|
||||
thumbs = os.path.join(str(tmp_path), "thumbs")
|
||||
os.makedirs(thumbs, exist_ok=True)
|
||||
with open(os.path.join(thumbs, "a.jpg"), "wb") as f:
|
||||
f.write(b"\xff\xd8\xffjpeg")
|
||||
client = _app(tmp_path).test_client()
|
||||
r = client.get("/thumb/a")
|
||||
assert r.status_code == 200 and r.mimetype == "image/jpeg"
|
||||
assert _app(tmp_path).test_client().get("/thumb/missing").status_code == 404
|
||||
Reference in New Issue
Block a user