mitai-jinkendo/backend/tests/test_template_validator.py

46 lines
1.3 KiB
Python
Raw Normal View History

"""Formatprüfung CSV-Vorlagen (template_validator)."""
from __future__ import annotations
from csv_parser.template_validator import validate_csv_template
def test_validate_kj_column_warns_without_source_unit():
r = validate_csv_template(
"activity",
{"Aktive Energie (kJ)": "kcal_active", "Start": "start_time", "Trainingsart": "activity_type"},
{"start_time": {"type": "datetime", "format": "yyyy-mm-dd HH:MM:SS", "flexible": True}},
None,
None,
)
assert r["valid"] is True
codes = {w["code"] for w in r["warnings"]}
assert "energy_kj_without_source_unit" in codes
def test_validate_invalid_target_error():
r = validate_csv_template(
"activity",
{"X": "not_a_field"},
{},
None,
None,
)
assert r["valid"] is False
assert any(e["code"] == "invalid_field_mapping" for e in r["errors"])
def test_validate_duplicate_target_warning():
r = validate_csv_template(
"weight",
{"A": "weight", "B": "weight", "Tag": "date"},
{
"weight": {"type": "float", "decimal_separator": "."},
"date": {"type": "date", "format": "yyyy-mm-dd", "flexible": True},
},
None,
None,
)
assert r["valid"] is True
assert any(w["code"] == "duplicate_target_columns" for w in r["warnings"])