Ripristino delle quote già misurate nel ciclo in corso dopo un reload (#40)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -248,6 +248,67 @@ class TestApiTaskProgress:
|
||||
assert resp.status_code in (302, 401)
|
||||
|
||||
|
||||
class TestApiCurrentCycle:
|
||||
"""GET /measure/api/current-cycle/<task_id> (gitea#40)."""
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _station_configured(self, monkeypatch):
|
||||
monkeypatch.setattr("blueprints.measure.Config.STATION_CODE", "ST-TEST")
|
||||
|
||||
def test_forwards_run_and_task(self, logged_in_client, mock_api_client):
|
||||
mock_api_client.get_station_recipes.return_value = [{"id": 1}]
|
||||
payload = {"measurements": [
|
||||
{"subtask_id": 3, "value": 10.1, "pass_fail": "pass",
|
||||
"measured_at": "2026-10-01T08:01:00"},
|
||||
]}
|
||||
mock_api_client.get.side_effect = api_get_router({
|
||||
"/api/tasks/7": {"id": 7, "recipe_id": 1, "version_id": 42},
|
||||
"/api/production-runs/current": {"id": 5},
|
||||
"/api/measurements/current-cycle": payload,
|
||||
})
|
||||
|
||||
resp = logged_in_client.get("/measure/api/current-cycle/7")
|
||||
|
||||
assert resp.status_code == 200
|
||||
assert resp.get_json() == payload
|
||||
call = next(
|
||||
c for c in mock_api_client.get.call_args_list
|
||||
if c.args[0] == "/api/measurements/current-cycle"
|
||||
)
|
||||
assert call.kwargs["params"] == {"production_run_id": 5, "task_id": 7}
|
||||
|
||||
def test_no_run_means_empty_and_no_backend_call(
|
||||
self, logged_in_client, mock_api_client,
|
||||
):
|
||||
mock_api_client.get_station_recipes.return_value = [{"id": 1}]
|
||||
mock_api_client.get.side_effect = api_get_router({
|
||||
"/api/tasks/7": {"id": 7, "recipe_id": 1, "version_id": 42},
|
||||
"/api/production-runs/current": None,
|
||||
})
|
||||
|
||||
resp = logged_in_client.get("/measure/api/current-cycle/7")
|
||||
|
||||
assert resp.get_json() == {"measurements": []}
|
||||
assert not any(
|
||||
c.args[0] == "/api/measurements/current-cycle"
|
||||
for c in mock_api_client.get.call_args_list
|
||||
)
|
||||
|
||||
def test_refuses_a_recipe_not_assigned_to_this_station(
|
||||
self, logged_in_client, mock_api_client,
|
||||
):
|
||||
mock_api_client.get_station_recipes.return_value = [{"id": 99}]
|
||||
mock_api_client.get.side_effect = api_get_router({
|
||||
"/api/tasks/7": {"id": 7, "recipe_id": 1, "version_id": 42},
|
||||
})
|
||||
|
||||
assert logged_in_client.get("/measure/api/current-cycle/7").status_code == 403
|
||||
|
||||
def test_requires_login(self, client):
|
||||
resp = client.get("/measure/api/current-cycle/7")
|
||||
assert resp.status_code in (302, 401)
|
||||
|
||||
|
||||
class TestStartSequence:
|
||||
"""GET /measure/start/<recipe_id> — the operator's way in."""
|
||||
|
||||
|
||||
Reference in New Issue
Block a user