72 lines
2.2 KiB
Python
72 lines
2.2 KiB
Python
from __future__ import annotations
|
||
|
||
from app.pipeline.mapping import FIXED_REPORT_COLUMNS, build_fixed_row
|
||
|
||
|
||
def _column_with(prefix: str) -> str:
|
||
for column in FIXED_REPORT_COLUMNS:
|
||
if column.startswith(prefix):
|
||
return column
|
||
raise AssertionError(f"Колонка с префиксом '{prefix}' не найдена")
|
||
|
||
|
||
def test_build_fixed_row_maps_known_fields() -> None:
|
||
row = build_fixed_row(
|
||
file_name="f.xml",
|
||
record_id="R1",
|
||
operation_index=2,
|
||
operation_fields={
|
||
"ИдФайл": "FILE_01",
|
||
"КодОперации": "5007",
|
||
"СумОперации": "100.55",
|
||
},
|
||
participant_fields={
|
||
"ИННФЛ": "123456789012",
|
||
"Тип": "01",
|
||
},
|
||
)
|
||
|
||
assert row["Имя XML файла"] == "f.xml"
|
||
assert row["Идентификатор записи"] == "R1"
|
||
assert row["Уникальный номер операции"] == "2"
|
||
assert row["Код вида операции"] == "5007"
|
||
assert row["Сумма в валюте проведения"] == "100.55"
|
||
assert row[_column_with("ИНН ")] == "123456789012"
|
||
assert row["Тип участника"] == "01"
|
||
|
||
|
||
def test_build_fixed_row_keeps_missing_values_empty() -> None:
|
||
row = build_fixed_row(
|
||
file_name="f.xml",
|
||
record_id="R1",
|
||
operation_index=1,
|
||
operation_fields={},
|
||
participant_fields={},
|
||
)
|
||
for column in FIXED_REPORT_COLUMNS:
|
||
assert column in row
|
||
assert row["Код вида операции"] == ""
|
||
assert row[_column_with("ИНН ")] == ""
|
||
|
||
|
||
def test_build_fixed_row_does_not_take_operation_inn_for_participant() -> None:
|
||
row = build_fixed_row(
|
||
file_name="f.xml",
|
||
record_id="R1",
|
||
operation_index=1,
|
||
operation_fields={
|
||
"ИНН": "0000000000",
|
||
"Тип": "99",
|
||
},
|
||
participant_fields={
|
||
"ИННФЛ": "111111111111",
|
||
"Тип": "01",
|
||
},
|
||
)
|
||
assert row[_column_with("ИНН ")] == "111111111111"
|
||
assert row["Тип участника"] == "01"
|
||
|
||
|
||
def test_fixed_report_columns_over_200() -> None:
|
||
assert len(FIXED_REPORT_COLUMNS) == 203
|