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>
90 lines
3.0 KiB
Python
90 lines
3.0 KiB
Python
"""Tests for maker blueprint (client/blueprints/maker.py).
|
|
|
|
Covers recipe list, recipe creation page, role enforcement, and recipe edit.
|
|
"""
|
|
import pytest
|
|
|
|
|
|
class TestRecipeList:
|
|
"""GET /maker/recipes tests."""
|
|
|
|
def test_recipe_list_renders(self, logged_in_client, mock_api_client):
|
|
"""Recipe list page renders for Maker role."""
|
|
mock_api_client.get.return_value = {
|
|
"items": [
|
|
{"id": 1, "code": "REC-001", "name": "Recipe A"},
|
|
],
|
|
"total": 1,
|
|
"pages": 1,
|
|
}
|
|
|
|
resp = logged_in_client.get("/maker/recipes")
|
|
assert resp.status_code == 200
|
|
|
|
def test_recipe_list_requires_login(self, client):
|
|
"""Unauthenticated user is redirected to login."""
|
|
resp = client.get("/maker/recipes", follow_redirects=False)
|
|
assert resp.status_code == 302
|
|
assert "/auth/login" in resp.headers["Location"]
|
|
|
|
|
|
class TestRecipeNew:
|
|
"""GET /maker/recipes/new tests."""
|
|
|
|
def test_recipe_new_renders(self, logged_in_client, mock_api_client):
|
|
"""Recipe creation page renders for Maker role."""
|
|
resp = logged_in_client.get("/maker/recipes/new")
|
|
assert resp.status_code == 200
|
|
|
|
|
|
class TestRoleRequired:
|
|
"""Maker role enforcement tests."""
|
|
|
|
def test_requires_maker_role(self, flask_app):
|
|
"""User without Maker role gets 403 on maker endpoints."""
|
|
with flask_app.test_client() as c:
|
|
with c.session_transaction() as sess:
|
|
sess["api_key"] = "test-key"
|
|
sess["user"] = {
|
|
"id": 2,
|
|
"username": "tec_only",
|
|
"display_name": "Tec Only",
|
|
"roles": ["MeasurementTec"],
|
|
"is_admin": False,
|
|
"language_pref": "en",
|
|
"theme_pref": "light",
|
|
"active": True,
|
|
}
|
|
sess["user_id"] = 2
|
|
sess["language"] = "en"
|
|
sess["theme"] = "light"
|
|
|
|
resp = c.get("/maker/recipes")
|
|
assert resp.status_code == 403
|
|
|
|
|
|
class TestRecipeEdit:
|
|
"""GET /maker/recipes/<id>/edit tests."""
|
|
|
|
def test_recipe_edit_renders(self, logged_in_client, mock_api_client):
|
|
"""Recipe edit page renders with recipe data."""
|
|
# First call: recipe detail, second call: versions list
|
|
mock_api_client.get.side_effect = [
|
|
{"id": 1, "code": "REC-001", "name": "Recipe A"},
|
|
[{"version_number": 1, "is_current": True}],
|
|
]
|
|
|
|
resp = logged_in_client.get("/maker/recipes/1/edit")
|
|
assert resp.status_code == 200
|
|
|
|
def test_recipe_edit_not_found(self, logged_in_client, mock_api_client):
|
|
"""Recipe edit with API error redirects to recipe list."""
|
|
mock_api_client.get.return_value = {
|
|
"error": True,
|
|
"detail": "Not found",
|
|
}
|
|
|
|
resp = logged_in_client.get("/maker/recipes/999/edit", follow_redirects=False)
|
|
assert resp.status_code == 302
|
|
assert "/maker/recipes" in resp.headers["Location"]
|