feat(client): add STATION_CODE env var and config attribute
Reads STATION_CODE from the environment and exposes it as Config.STATION_CODE (None when unset or empty). Adds the variable to .env.example with a per-station deployment note, and covers both read and missing-key paths with new pytest tests. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -20,6 +20,10 @@ CLIENT_HOST=0.0.0.0
|
|||||||
CLIENT_PORT=5000
|
CLIENT_PORT=5000
|
||||||
CLIENT_SECRET_KEY=change-this-to-another-random-secret-key
|
CLIENT_SECRET_KEY=change-this-to-another-random-secret-key
|
||||||
API_SERVER_URL=http://localhost:8000
|
API_SERVER_URL=http://localhost:8000
|
||||||
|
# Station code this client container belongs to (e.g. ST-001).
|
||||||
|
# Each physical tablet/PC deployment must set this unique per-station value.
|
||||||
|
# Leave empty only for a single-station all-in-one demo using ST-DEFAULT.
|
||||||
|
STATION_CODE=ST-DEFAULT
|
||||||
|
|
||||||
# --- File Storage ---
|
# --- File Storage ---
|
||||||
UPLOAD_DIR=server/uploads
|
UPLOAD_DIR=server/uploads
|
||||||
|
|||||||
@@ -22,6 +22,10 @@ class Config:
|
|||||||
PERMANENT_SESSION_LIFETIME = 28800 # 8 hours
|
PERMANENT_SESSION_LIFETIME = 28800 # 8 hours
|
||||||
WTF_CSRF_TIME_LIMIT = 3600 # 1 hour
|
WTF_CSRF_TIME_LIMIT = 3600 # 1 hour
|
||||||
|
|
||||||
|
# Station identity: each deployed client container sets this to the station
|
||||||
|
# code it belongs to. Empty/None means "not configured".
|
||||||
|
STATION_CODE: str | None = os.getenv("STATION_CODE") or None
|
||||||
|
|
||||||
# Babel i18n
|
# Babel i18n
|
||||||
BABEL_DEFAULT_LOCALE = "it"
|
BABEL_DEFAULT_LOCALE = "it"
|
||||||
BABEL_DEFAULT_TIMEZONE = "Europe/Rome"
|
BABEL_DEFAULT_TIMEZONE = "Europe/Rome"
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
"""Tests that STATION_CODE is loaded from env and exposed on the client Config class."""
|
||||||
|
import importlib
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def test_station_code_read_from_env(monkeypatch):
|
||||||
|
monkeypatch.setenv("STATION_CODE", "ST-TEST")
|
||||||
|
import config
|
||||||
|
importlib.reload(config)
|
||||||
|
assert config.Config.STATION_CODE == "ST-TEST"
|
||||||
|
|
||||||
|
|
||||||
|
def test_station_code_defaults_to_none_when_missing(monkeypatch):
|
||||||
|
monkeypatch.delenv("STATION_CODE", raising=False)
|
||||||
|
import config
|
||||||
|
importlib.reload(config)
|
||||||
|
assert config.Config.STATION_CODE is None
|
||||||
Reference in New Issue
Block a user