feat(csv-templates): Introduce CSV template analysis and validation features
- Added a new endpoint for analyzing uploaded CSV files, providing suggestions for field mappings and type conversions. - Implemented validation for required field targets to ensure all mandatory fields are mapped correctly. - Enhanced the admin CSV templates interface with new routes and navigation options in the frontend. - Updated API utility functions to support the new CSV analysis functionality. - Improved error handling for CSV uploads, including file size and row count checks.
This commit is contained in:
1 parent
338163ac0b
commit
c10da55ec6
9 files changed
+1017
-4
No files matched your search
@@ -0,0 +1,42 @@
|
||||
"""Tests für CSV mapping_suggest (Issue #21)."""
|
||||
|
||||
from csv_parser.mapping_suggest import (
|
||||
build_type_conversions_for_mapping,
|
||||
suggest_field_mappings,
|
||||
)
|
||||
|
||||
|
||||
def test_suggest_from_fddb_seed():
|
||||
headers = ["Datum Tag Monat Jahr Stunde Minute", "kJ", "Fett (g)", "KH (g)", "Protein (g)"]
|
||||
seed = {
|
||||
"datum_tag_monat_jahr_stunde_minute": "date",
|
||||
"kj": "kcal",
|
||||
"fett_g": "fat_g",
|
||||
"kh_g": "carbs_g",
|
||||
"protein_g": "protein_g",
|
||||
}
|
||||
fm = suggest_field_mappings(headers, "nutrition", seed)
|
||||
assert fm["Datum Tag Monat Jahr Stunde Minute"] == "date"
|
||||
assert fm["kJ"] == "kcal"
|
||||
|
||||
|
||||
def test_suggest_aliases_without_seed():
|
||||
fm = suggest_field_mappings(
|
||||
["Date", "Calories", "Protein (g)", "Fat (g)", "Carbs"],
|
||||
"nutrition",
|
||||
None,
|
||||
)
|
||||
assert fm["Date"] == "date"
|
||||
assert fm["Calories"] == "kcal"
|
||||
assert fm["Protein (g)"] == "protein_g"
|
||||
|
||||
|
||||
def test_type_conversions_merge():
|
||||
fm = {"Col A": "date", "Col B": "kcal"}
|
||||
seed_tc = {
|
||||
"kcal": {"type": "float", "conversion_factor": 0.239, "decimal_separator": "auto"},
|
||||
}
|
||||
tc = build_type_conversions_for_mapping("nutrition", fm, seed_tc)
|
||||
assert "kcal" in tc
|
||||
assert tc["kcal"].get("conversion_factor") == 0.239
|
||||
assert "date" in tc
|
||||
Reference in new issue
Block a user