Merge lavoro/daitarn-trafilo-settings
This commit is contained in:
@@ -176,6 +176,50 @@ class TestUpdateSettingsValidation:
|
||||
)
|
||||
assert resp.status_code == 200
|
||||
|
||||
# --- #47/#48/#49: chiavi Impostazioni di Tràfilo ---
|
||||
|
||||
@pytest.mark.parametrize("key,value", [
|
||||
("default_measurement_interval_minutes", "1"),
|
||||
("default_measurement_interval_minutes", "1440"),
|
||||
("default_measurement_interval_minutes", ""),
|
||||
("general_tolerance_plus", "0"),
|
||||
("general_tolerance_plus", "0.05"),
|
||||
("general_tolerance_minus", ""),
|
||||
("list_measurement_types", '["Lunghezza", "Diametro"]'),
|
||||
("list_units", "[]"),
|
||||
("list_units", ""),
|
||||
])
|
||||
async def test_new_keys_valid_accepted(
|
||||
self, client: AsyncClient, admin_user: User, key: str, value: str
|
||||
):
|
||||
resp = await client.put(
|
||||
"/api/settings/", headers=auth_headers(admin_user), json={key: value}
|
||||
)
|
||||
assert resp.status_code == 200, resp.text
|
||||
|
||||
@pytest.mark.parametrize("key,value", [
|
||||
("default_measurement_interval_minutes", "0"),
|
||||
("default_measurement_interval_minutes", "1441"),
|
||||
("default_measurement_interval_minutes", "abc"),
|
||||
("general_tolerance_plus", "-0.1"),
|
||||
("general_tolerance_plus", "0,05"),
|
||||
("general_tolerance_minus", "NaN"),
|
||||
("general_tolerance_minus", "abc"),
|
||||
("list_measurement_types", "not json"),
|
||||
("list_measurement_types", '{"a": 1}'),
|
||||
("list_units", '["mm", ""]'),
|
||||
("list_units", '["mm", 3]'),
|
||||
("list_units", "[" + ",".join(f'"v{i}"' for i in range(51)) + "]"),
|
||||
])
|
||||
async def test_new_keys_invalid_rejected(
|
||||
self, client: AsyncClient, admin_user: User, key: str, value: str
|
||||
):
|
||||
resp = await client.put(
|
||||
"/api/settings/", headers=auth_headers(admin_user), json={key: value}
|
||||
)
|
||||
assert resp.status_code == 422, resp.text
|
||||
assert key in resp.json()["detail"]
|
||||
|
||||
async def test_unknown_key_not_validated(
|
||||
self, client: AsyncClient, admin_user: User
|
||||
):
|
||||
|
||||
Reference in New Issue
Block a user