- 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.
43 lines
1.3 KiB
Python
43 lines
1.3 KiB
Python
"""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
|