fix(measure): filtro stazione anche su barcode, avvio sequenza e task_execute (#24)

_recipe_allowed_at_station() riusa get_station_recipes() (stessa fonte di
/measure/select) per lookup_barcode, start_sequence e task_execute: prima
solo l'elenco filtrava, il barcode e i link diretti lasciavano misurare
ricette non assegnate alla stazione. Ricetta non assegnata -> abort(403)
con messaggio "ricetta non assegnata a questa stazione" (pagine, come già
fa role_required) o JSON 403 (lookup-barcode). Aggiornati i test esistenti
che ora richiedono get_station_recipes/STATION_CODE mockati.
Backend (ruoli sui run, StationRecipeAssignment su open_run) resta al
lotto A1.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-09-21 22:47:30 +02:00
parent f739f963c7
commit befdce5e6a
6 changed files with 163 additions and 20 deletions
@@ -71,7 +71,11 @@ TASK = {
}
def _execute_page(client, mock_api_client, allow_manual):
def _execute_page(client, mock_api_client, monkeypatch, allow_manual):
# task_execute() only renders a recipe assigned to this station (#24).
# STATION_CODE defaults to unset in the test env, so it has to be forced.
monkeypatch.setattr("blueprints.measure.Config.STATION_CODE", "ST-TEST")
mock_api_client.get_station_recipes.return_value = [{"id": 3}]
mock_api_client.get.side_effect = [
TASK,
[{"id": 11, "order_index": 0}],
@@ -86,9 +90,9 @@ def _execute_page(client, mock_api_client, allow_manual):
def test_keypad_digits_are_absent_when_typing_is_forbidden(
logged_in_client, mock_api_client,
logged_in_client, mock_api_client, monkeypatch,
):
html = _execute_page(logged_in_client, mock_api_client, allow_manual=False)
html = _execute_page(logged_in_client, mock_api_client, monkeypatch, allow_manual=False)
assert "allowManual: false" in html
assert "addDigit('7')" not in html, "i tasti numerici non devono essere in pagina"
# The corrections and the confirm stay: a wrong caliper reading has to be
@@ -98,17 +102,19 @@ def test_keypad_digits_are_absent_when_typing_is_forbidden(
def test_keypad_is_there_when_the_recipe_allows_typing(
logged_in_client, mock_api_client,
logged_in_client, mock_api_client, monkeypatch,
):
html = _execute_page(logged_in_client, mock_api_client, allow_manual=True)
html = _execute_page(logged_in_client, mock_api_client, monkeypatch, allow_manual=True)
assert "allowManual: true" in html
assert "addDigit('7')" in html
def test_keypad_stays_when_the_recipe_cannot_be_read(
logged_in_client, mock_api_client,
logged_in_client, mock_api_client, monkeypatch,
):
"""A recipe that failed to load must not silently take the keypad away."""
monkeypatch.setattr("blueprints.measure.Config.STATION_CODE", "ST-TEST")
mock_api_client.get_station_recipes.return_value = [{"id": 3}]
mock_api_client.get.side_effect = [
TASK,
[{"id": 11, "order_index": 0}],
@@ -125,10 +131,10 @@ def test_keypad_stays_when_the_recipe_cannot_be_read(
def test_the_operator_sees_the_description_formatted(
logged_in_client, mock_api_client,
logged_in_client, mock_api_client, monkeypatch,
):
"""It was written for the operator, and until now only the maker saw it."""
html = _execute_page(logged_in_client, mock_api_client, allow_manual=True)
html = _execute_page(logged_in_client, mock_api_client, monkeypatch, allow_manual=True)
assert "prima riga<br><strong>grassetto</strong>" in html