Added line editing
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,8 @@ def fake(cmd, timeout=3.0):
|
||||
raise AssertionError(cmd)
|
||||
|
||||
|
||||
LINES = {"door": {"floor": 1, "points": [[0, 1], [2, 1]], "type": "forbidden"},
|
||||
LINES = {"door": {"floor": 1, "points": [[0, 1], [2, 1]], "type": "forbidden", "date": "2026-10-08 16:35:09"},
|
||||
"new": {"floor": 1, "points": [[5, 5], [6, 5]], "date": "2026-11-17 15:00:00"},
|
||||
"up": {"floor": 2, "points": [[0, 0], [1, 0]]}, "dot": {"floor": 1, "points": [[3, 3]]}}
|
||||
|
||||
|
||||
@@ -36,7 +37,8 @@ agv.request = server.agv.request = fake
|
||||
server.rosbridge.call_service = fake_service
|
||||
names = lambda d: [m["name"] for m in d["markers"]]
|
||||
assert names(server.map_info()) == ["home_dock"]
|
||||
assert server.map_info()["lines"] == [{"name": "door", "points": [[0, 1], [2, 1]]}] # this floor, two points or more
|
||||
assert server.map_info()["lines"] == [{"name": "new", "points": [[5, 5], [6, 5]]}, # newest first
|
||||
{"name": "door", "points": [[0, 1], [2, 1]]}] # this floor, 2 points or more
|
||||
assert server.markers()["markers"] == ["home"] and agv.known_markers() == ["home"]
|
||||
|
||||
MARKS["p13"] = {"key": 0, "floor": 1, "pose": {"position": {"x": 1.0, "y": 2.0}, "orientation": {"z": 0, "w": 1}}}
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
"""Self-check of the no-go lines the Lumi app draws (2026-11-17): save one on this floor, delete one, refuse bad input,
|
||||
and a base that refuses. Fake base and rosbridge, no robot: python tests/test_map_lines.py"""
|
||||
import json
|
||||
|
||||
import no_robot # noqa: F401 any connection to the robot fails the test
|
||||
from fastapi import HTTPException
|
||||
|
||||
from api import server
|
||||
|
||||
calls = []
|
||||
reply = {"success": True, "message": ""}
|
||||
server.agv.request = lambda cmd, timeout=3.0: {"results": {"map_name": "office", "floor": 2}}
|
||||
server.rosbridge.call_service = lambda service, args, timeout=3.0: (calls.append((service, args["cmd"],
|
||||
json.loads(args["message"]))), reply)[1]
|
||||
|
||||
|
||||
def refused(fn, *a, code):
|
||||
try:
|
||||
fn(*a)
|
||||
except HTTPException as e:
|
||||
return e.status_code == code
|
||||
return False
|
||||
|
||||
|
||||
r = server.line_save(server.NoGoLineBody(name="door_1", points=[[0, 1.23456], [2, 1]]))
|
||||
assert calls == [("/forbidden_manager/action_service", "add_lines", {"data": [
|
||||
{"name": "door_1", "type": "forbidden", "floor": 2, "points": [[0, 1.235], [2, 1]], "comment": "",
|
||||
"properties": "{}"}]})], calls
|
||||
calls.clear()
|
||||
server.line_delete(server.MarkerName(name="door_1"))
|
||||
assert calls == [("/forbidden_manager/action_service", "delete_lines", {"names": ["door_1"]})], calls
|
||||
calls.clear()
|
||||
|
||||
assert refused(server.line_save, server.NoGoLineBody(name="a b", points=[[0, 0], [1, 1]]), code=422)
|
||||
assert refused(server.line_save, server.NoGoLineBody(name="x", points=[[0, 0], [1]]), code=422)
|
||||
try:
|
||||
server.NoGoLineBody(name="x", points=[[0, 0]]) # one point is not a line
|
||||
raise AssertionError("one point accepted")
|
||||
except ValueError:
|
||||
pass
|
||||
assert calls == [], calls
|
||||
|
||||
reply = {"success": False, "message": "busy"}
|
||||
assert refused(server.line_save, server.NoGoLineBody(name="x", points=[[0, 0], [1, 1]]), code=502)
|
||||
print("ok: map lines")
|
||||
Reference in New Issue
Block a user