Files
article-data-manager/tests/integration/test_erp_enrichment_dry_run.py
2026-07-29 14:32:15 +02:00

78 lines
2.5 KiB
Python

import csv
import json
from pathlib import Path
from article_data_manager.enrichment.erp import (
enrich_rollcalc_articles_from_erp,
write_enrichment_outputs,
)
def test_enrichment_dry_run_writes_json_and_csv_outputs(tmp_path: Path) -> None:
rollcalc_path = tmp_path / "article-data.json"
erp_path = tmp_path / "erp.csv"
json_path = tmp_path / "generated" / "article-data.erp-enriched-dry-run.json"
report_path = tmp_path / "reports" / "erp-enrichment-report.csv"
rollcalc_path.write_text(
json.dumps(
[
{
"nr": "214700",
"name": "RollCalc A",
"thickness": 6.722,
"area_weight": 750.0,
"core_type": 0.0,
},
{
"nr": "999999",
"name": "RollCalc Only",
"thickness": 1.0,
"area_weight": 0.0,
"core_type": 0.0,
},
],
ensure_ascii=False,
indent=2,
)
+ "\n",
encoding="utf-8",
)
erp_path.write_text(
"\n".join(
[
"SL_ITEM_NO,ROP_PRODUCT_WIDTH,ROP_RATE_OF_PRODUCTION,"
"SL_MINIMUM_PRODUCTION_QUANTITY,WPL_WORKPLACE_TEXT,kg_qm,SL_PRODUCTION_SPEED",
"214700,\"6,00\",\"18,5\",5000,Anlage 3,999,999",
"ERPONLY,9.99,1.0,1,Anlage X,1,1",
]
),
encoding="utf-8",
)
result = enrich_rollcalc_articles_from_erp(rollcalc_path, erp_path)
write_enrichment_outputs(result, json_path, report_path)
output_articles = json.loads(json_path.read_text(encoding="utf-8"))
assert [article["nr"] for article in output_articles] == ["214700", "999999"]
assert output_articles[0]["area_weight"] == 750.0
assert output_articles[0]["erp"] == {
"product_width_m": 6.0,
"line_speed_m_min": 18.5,
"minimum_production_quantity": 5000.0,
"workplace": "Anlage 3",
}
assert output_articles[1]["erp"] == {
"product_width_m": None,
"line_speed_m_min": None,
"minimum_production_quantity": None,
"workplace": None,
}
with report_path.open("r", encoding="utf-8-sig", newline="") as report_file:
rows = list(csv.DictReader(report_file, delimiter=";"))
assert [row["nr"] for row in rows] == ["214700", "999999"]
assert rows[0]["status"] == "complete"
assert rows[1]["status"] == "no_erp_match"