feat(pose_3d): router skeleton + GET /state
This commit is contained in:
1 parent
19fba42876
commit
71f2ef596e
4 files changed
+108
-1
No files matched your search
@@ -0,0 +1,43 @@
|
||||
"""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
|
||||
Reference in new issue
Block a user