dd2ebf863a
Security hardening: CORS lockdown, rate limiting middleware con sliding window e eviction IP stale, security headers (CSP, HSTS, X-Frame-Options), session cookie hardening, filename sanitization upload. i18n completion: internazionalizzati barcode.js e csv-export.js con bridge window.BARCODE_I18N/CSV_I18N, aggiornati .po IT/EN con 27 nuove stringhe. Tablet UX: touch target 44px per dispositivi coarse pointer. Test suite: 101 test totali (76 server + 25 client), copertura completa di tutti i router API, autenticazione, ruoli, CRUD, SPC, file upload, security integration. Infrastruttura SQLite async in-memory con fixtures. Fix critici: MissingGreenlet in recipe_service (selectinload eager), route ordering tasks.py, auth_service bcrypt diretto, Measurement.id Integer per SQLite. Documentazione: API.md (riferimento completo 40+ endpoint), DEPLOYMENT.md (guida produzione con Docker/Nginx/SSL), USER_GUIDE.md (manuale utente per ruolo). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
92 lines
3.1 KiB
Python
92 lines
3.1 KiB
Python
"""Tests for measure blueprint (client/blueprints/measure.py).
|
|
|
|
Covers recipe selection, task list, login requirement, and measurement submission.
|
|
"""
|
|
import pytest
|
|
|
|
|
|
class TestSelectRecipe:
|
|
"""GET /measure/select tests."""
|
|
|
|
def test_select_recipe_renders(self, logged_in_client, mock_api_client):
|
|
"""Recipe selection page renders for MeasurementTec role."""
|
|
mock_api_client.get.return_value = {
|
|
"items": [
|
|
{"id": 1, "code": "REC-001", "name": "Test Recipe"},
|
|
],
|
|
"total": 1,
|
|
"pages": 1,
|
|
}
|
|
|
|
resp = logged_in_client.get("/measure/select")
|
|
assert resp.status_code == 200
|
|
|
|
def test_select_recipe_requires_login(self, client):
|
|
"""Unauthenticated user is redirected to login."""
|
|
resp = client.get("/measure/select", follow_redirects=False)
|
|
assert resp.status_code == 302
|
|
assert "/auth/login" in resp.headers["Location"]
|
|
|
|
|
|
class TestTaskList:
|
|
"""GET /measure/tasks/<recipe_id> tests."""
|
|
|
|
def test_task_list_renders(self, logged_in_client, mock_api_client):
|
|
"""Task list page renders with recipe and task data."""
|
|
# First call: recipe details (dict), second call: tasks list.
|
|
# The route calls tasks_resp.get("error") so the mock must return
|
|
# a dict (not a bare list) to avoid AttributeError.
|
|
mock_api_client.get.side_effect = [
|
|
{"id": 1, "code": "REC-001", "name": "Test Recipe"},
|
|
{
|
|
"items": [
|
|
{"id": 1, "title": "Task 1", "order_index": 0},
|
|
{"id": 2, "title": "Task 2", "order_index": 1},
|
|
],
|
|
},
|
|
]
|
|
|
|
resp = logged_in_client.get("/measure/tasks/1")
|
|
assert resp.status_code == 200
|
|
|
|
|
|
class TestSaveMeasurement:
|
|
"""POST /measure/save-measurement tests."""
|
|
|
|
def test_save_measurement_proxy(self, logged_in_client, mock_api_client):
|
|
"""Save measurement forwards data to API and returns 201."""
|
|
mock_api_client.post.return_value = {
|
|
"id": 1,
|
|
"subtask_id": 10,
|
|
"task_id": 5,
|
|
"value": 9.95,
|
|
"pass_fail": "pass",
|
|
}
|
|
|
|
resp = logged_in_client.post(
|
|
"/measure/save-measurement",
|
|
json={
|
|
"subtask_id": 10,
|
|
"task_id": 5,
|
|
"value": 9.95,
|
|
"pass_fail": "pass",
|
|
"deviation": 0.05,
|
|
},
|
|
content_type="application/json",
|
|
)
|
|
assert resp.status_code == 201
|
|
data = resp.get_json()
|
|
assert data["id"] == 1
|
|
assert data["pass_fail"] == "pass"
|
|
|
|
def test_save_measurement_missing_fields(self, logged_in_client, mock_api_client):
|
|
"""Missing required fields return 400."""
|
|
resp = logged_in_client.post(
|
|
"/measure/save-measurement",
|
|
json={"subtask_id": 10}, # missing task_id and value
|
|
content_type="application/json",
|
|
)
|
|
assert resp.status_code == 400
|
|
data = resp.get_json()
|
|
assert data["error"] is True
|