feat(csv-templates): Add CSV template validation endpoint and enhance error handling
- Introduced a new endpoint for validating CSV templates without saving, allowing users to check field mappings and type conversions. - Updated the `create_system_template` and `update_system_template` functions to include validation reports in responses. - Enhanced error handling in CSV import processes by integrating `enrich_row_error` for more informative error messages. - Improved the AdminCsvTemplateEditorPage to support format checking and display validation results, enhancing user experience. - Incremented version numbers for `csv_import` and `admin_csv_templates` to reflect these updates.
This commit is contained in:
1 parent
6945b748cb
commit
0629f88b37
10 files changed
+486
-39
No files matched your search
@@ -0,0 +1,45 @@
|
||||
"""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"])
|
||||
Reference in new issue
Block a user