File size: 1,073 Bytes
51e5253
 
 
 
 
 
 
 
 
 
 
 
 
 
 
860c252
 
 
 
 
 
 
96d8d92
 
860c252
 
 
 
 
 
 
 
96d8d92
 
860c252
51e5253
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
from pathlib import Path

import pytest

from app.domain.csv_stream import iter_mapped_csv_rows
from app.schemas.article_import import ArticleImportMapping, ArticleImportOptions


@pytest.mark.unit
def test_csv_stream_mapped_rows(tmp_path: Path) -> None:
    p = tmp_path / "t.csv"
    p.write_text("Ref,Libelle FR\nR1,Article 1\nR2,Article 2\n", encoding="utf-8")
    mapping = ArticleImportMapping(reference_number="Ref", label_fr="Libelle FR")
    options = ArticleImportOptions()
    rows = list(iter_mapped_csv_rows(p, mapping, options))
    r1 = {
        "reference_number": "R1",
        "label_fr": "Article 1",
        "label_en": None,
        "category_id": None,
        "moq": None,
        "origin": None,
        "reference_old": None,
        "reference_new": None,
    }
    r2 = {
        "reference_number": "R2",
        "label_fr": "Article 2",
        "label_en": None,
        "category_id": None,
        "moq": None,
        "origin": None,
        "reference_old": None,
        "reference_new": None,
    }
    assert rows == [(2, r1), (3, r2)]