From a5e4f57fcf3f2ba3b9be69e7c743eb9a0cae8dd4 Mon Sep 17 00:00:00 2001 From: Shawn Date: Mon, 8 Jun 2026 13:07:43 -0400 Subject: [PATCH] Add tests for 4CM routing endpoints (GET/POST /api/routing) - TestAPIRouting: 7 tests covering get/set routing mode and breakpoint - mock_pipeline now has a real set_routing side_effect that updates properties - Covers connected/disconnected states, mode toggle, breakpoint change, both --- tests/test_web.py | 65 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/tests/test_web.py b/tests/test_web.py index 79b39c8..3bb5292 100644 --- a/tests/test_web.py +++ b/tests/test_web.py @@ -44,6 +44,11 @@ def mock_pipeline(): pl._master_volume = 0.8 pl.routing_mode = "mono" pl.routing_breakpoint = 7 + + def _set_routing(mode, breakpoint=7): + pl.routing_mode = mode + pl.routing_breakpoint = breakpoint + pl.set_routing = MagicMock(side_effect=_set_routing) return pl @@ -375,4 +380,62 @@ class TestErrors: def test_empty_model_load_path(self, client): res = client.post("/api/models/load", json={"path": ""}) - assert res.status_code == 400 \ No newline at end of file + assert res.status_code == 400 + + +class TestAPIRouting: + """4CM routing mode and breakpoint endpoints.""" + + def test_get_routing_default(self, client, mock_pipeline): + """GET /api/routing returns current routing config.""" + res = client.get("/api/routing") + assert res.status_code == 200 + data = res.json() + assert data["routing_mode"] == "mono" + assert data["routing_breakpoint"] == 7 + + def test_get_routing_no_deps(self, client_no_deps): + """GET /api/routing returns 503 when pipeline not connected.""" + res = client_no_deps.get("/api/routing") + assert res.status_code == 503 + + def test_set_routing_mode_4cm(self, client, mock_pipeline): + """POST /api/routing switches to 4CM mode.""" + res = client.post("/api/routing", json={"routing_mode": "4cm"}) + assert res.status_code == 200 + data = res.json() + assert data["routing_mode"] == "4cm" + mock_pipeline.set_routing.assert_called_with("4cm", 7) + + def test_set_routing_mode_mono(self, client, mock_pipeline): + """POST /api/routing switches back to mono.""" + res = client.post("/api/routing", json={"routing_mode": "mono"}) + assert res.status_code == 200 + data = res.json() + assert data["routing_mode"] == "mono" + mock_pipeline.set_routing.assert_called_with("mono", 7) + + def test_set_routing_breakpoint(self, client, mock_pipeline): + """POST /api/routing sets breakpoint position.""" + res = client.post("/api/routing", json={"routing_breakpoint": 3}) + assert res.status_code == 200 + data = res.json() + assert data["routing_breakpoint"] == 3 + mock_pipeline.set_routing.assert_called_with("mono", 3) + + def test_set_routing_both(self, client, mock_pipeline): + """POST /api/routing sets both mode and breakpoint.""" + res = client.post("/api/routing", json={ + "routing_mode": "4cm", + "routing_breakpoint": 5, + }) + assert res.status_code == 200 + data = res.json() + assert data["routing_mode"] == "4cm" + assert data["routing_breakpoint"] == 5 + mock_pipeline.set_routing.assert_called_with("4cm", 5) + + def test_set_routing_no_deps(self, client_no_deps): + """POST /api/routing returns 503 when pipeline not connected.""" + res = client_no_deps.post("/api/routing", json={"routing_mode": "4cm"}) + assert res.status_code == 503 \ No newline at end of file