File size: 1,245 Bytes
2edb151
 
 
 
 
 
676f5d4
2edb151
 
 
 
 
 
 
 
 
 
 
 
 
 
676f5d4
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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)