from __future__ import annotations from pathlib import Path import httpx from app.camera import aim, snapshot from app.config import Settings def test_snapshot_reads_path(settings: Settings, tmp_path: Path) -> None: saved = tmp_path / "snap.jpg" saved.write_bytes(b"x") def handler(request: httpx.Request) -> httpx.Response: assert "width=1280" in str(request.url) return httpx.Response(200, json={"path": str(saved)}) client = httpx.Client(transport=httpx.MockTransport(handler), base_url="http://hal.test") settings = settings.model_copy(update={"camera_url": "http://hal.test"}) assert snapshot(settings, client=client) == saved def test_aim_posts_direction(settings: Settings) -> None: seen: list[str] = [] def handler(request: httpx.Request) -> httpx.Response: seen.append(request.method + " " + str(request.url)) assert b"down" in request.content return httpx.Response(200, json={"ok": True}) client = httpx.Client(transport=httpx.MockTransport(handler), base_url="http://hal.test") settings = settings.model_copy(update={"camera_url": "http://hal.test"}) aim(settings, "down", client=client) assert any("servo/aim" in url for url in seen)