44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
"""Integration test del router /api/pose_3d/*."""
|
|
from __future__ import annotations
|
|
|
|
from unittest.mock import patch, MagicMock
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from presa_mano.main import app
|
|
|
|
client = TestClient(app)
|
|
|
|
|
|
def _fake_wrist_pair():
|
|
return {
|
|
"left_wrist": {"position": [0.10, 0.20, 0.30], "quaternion": [0, 0, 0, 1]},
|
|
"right_wrist": {"position": [0.30, -0.20, 0.30], "quaternion": [0, 0, 0, 1]},
|
|
}
|
|
|
|
|
|
def test_state_returns_both_wrists():
|
|
with patch("presa_mano.api.pose_3d_routes._deps.g1") as g1_factory:
|
|
g1 = MagicMock()
|
|
g1.wrist.return_value = _fake_wrist_pair()
|
|
g1_factory.return_value = g1
|
|
r = client.get("/api/pose_3d/state")
|
|
assert r.status_code == 200
|
|
body = r.json()
|
|
assert "wrist" in body
|
|
assert body["wrist"]["left"]["position"] == [0.10, 0.20, 0.30]
|
|
assert body["wrist"]["right"]["position"] == [0.30, -0.20, 0.30]
|
|
assert "poses" in body
|
|
assert "live_max_step_m" in body
|
|
assert body["robot_active"] in ("g1", "h1")
|
|
|
|
|
|
def test_state_502_when_g1_unavailable():
|
|
from presa_mano.clients import G1Unavailable
|
|
with patch("presa_mano.api.pose_3d_routes._deps.g1") as g1_factory:
|
|
g1 = MagicMock()
|
|
g1.wrist.side_effect = G1Unavailable("connection refused")
|
|
g1_factory.return_value = g1
|
|
r = client.get("/api/pose_3d/state")
|
|
assert r.status_code == 502
|