File size: 2,984 Bytes
f97338f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
"""Tests de l'ingestion CSV + mapping (core.csv_import)."""
import pandas as pd

from core.csv_import import parse_price, guess_col, csv_to_articles, GUESS, NONE_COL


# ── parse_price ───────────────────────────────────────────────────────────────

def test_parse_price_virgule():
    assert parse_price("70,92") == 70.92

def test_parse_price_euro_et_espace():
    assert parse_price("1 234,50 €") == 1234.50

def test_parse_price_entier():
    assert parse_price("45") == 45.0

def test_parse_price_vide():
    assert parse_price("") == 0.0
    assert parse_price(None) == 0.0

def test_parse_price_non_numerique():
    assert parse_price("sur devis") == 0.0


# ── guess_col ─────────────────────────────────────────────────────────────────

def test_guess_col_reference():
    cols = ["Code Article", "DΓ©signation", "Tarif"]
    assert guess_col(cols, GUESS["reference"]) == "Code Article"

def test_guess_col_libelle():
    cols = ["Ref", "DΓ©signation", "PU"]
    assert guess_col(cols, GUESS["libelle"]) == "DΓ©signation"

def test_guess_col_aucun():
    assert guess_col(["X", "Y"], GUESS["prix"]) is None


# ── csv_to_articles : unitΓ©s variables prΓ©servΓ©es ────────────────────────────

def _df():
    return pd.DataFrame({
        "Ref":        ["V1", "R1", "M1", "S1"],
        "Designation":["Velours bleu", "Voilage", "Mousse 35kg", "Simili cuir"],
        "Tarif":      ["70,92", "30,00", "12,50 €", "45"],
        "Cond":       ["ml", "M", "U", "mΒ²"],
    })

def test_csv_to_articles_basic():
    arts = csv_to_articles(_df(), "Ref", "Designation", "Tarif", "Cond")
    assert len(arts) == 4
    assert arts[0]["reference"] == "V1"
    assert arts[0]["nom_dessin"] == "Velours bleu"
    assert arts[0]["prix_conseille"] == 70.92

def test_csv_to_articles_unites_telles_quelles():
    arts = csv_to_articles(_df(), "Ref", "Designation", "Tarif", "Cond")
    unites = [a["unite"] for a in arts]
    # chaque ligne garde son unitΓ© propre, aucune uniformisation
    assert unites == ["ml", "M", "U", "mΒ²"]

def test_csv_to_articles_sans_colonne_unite():
    arts = csv_to_articles(_df(), "Ref", "Designation", "Tarif", NONE_COL)
    assert all(a["unite"] == "" for a in arts)  # vide, jamais une valeur imposΓ©e

def test_csv_to_articles_sans_prix():
    arts = csv_to_articles(_df(), "Ref", "Designation", NONE_COL, "Cond")
    assert all(a["prix_conseille"] == 0.0 for a in arts)

def test_csv_to_articles_ignore_lignes_vides():
    df = pd.DataFrame({"Ref": ["A", ""], "Designation": ["x", ""], "Tarif": ["1", ""], "Cond": ["ml", ""]})
    arts = csv_to_articles(df, "Ref", "Designation", "Tarif", "Cond")
    assert len(arts) == 1