chore: establish project baseline
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import importlib.util
|
||||
import json
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import pytest
|
||||
|
||||
ROOT = Path(__file__).parents[1]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
spec = importlib.util.spec_from_file_location("import_fiscal_context", ROOT / "scripts" / "import_fiscal_context.py")
|
||||
mod = importlib.util.module_from_spec(spec); sys.modules[spec.name] = mod; spec.loader.exec_module(mod)
|
||||
|
||||
HEADER = "company_key,scope,scope_key,key,value,reason\n"
|
||||
|
||||
|
||||
def test_csv_answers_are_validated_and_unanswered_rows_skipped(tmp_path, capsys):
|
||||
f = tmp_path / "a.csv"
|
||||
f.write_text(HEADER + "abc,GROUP,000019,product_role,RESALE,revenda\nabc,COMPANY,,entry_scope,INTRA,\nabc,GROUP,000020,product_role,,\n", encoding="utf-8")
|
||||
mod.main([str(f), "--token", "t", "--dry-run"])
|
||||
assert "validated 2 entries (1 unanswered rows skipped)" in capsys.readouterr().out
|
||||
|
||||
|
||||
def test_invalid_rows_block_the_whole_import(tmp_path):
|
||||
f = tmp_path / "b.csv"
|
||||
f.write_text(HEADER + "abc,GROUP,000019,product_role,RESALE,\nabc,COMPANY,,rounding,Z,\n", encoding="utf-8")
|
||||
with pytest.raises(SystemExit, match="invalid"):
|
||||
mod.main([str(f), "--token", "t", "--dry-run"])
|
||||
|
||||
|
||||
def test_json_format_and_questionnaire_csv_columns(tmp_path, capsys):
|
||||
f = tmp_path / "c.json"
|
||||
f.write_text(json.dumps({"company_key": "abc", "entries": [{"scope": "NCM", "scope_key": "22030000", "key": "cest", "value": "03.021.03"}]}), encoding="utf-8")
|
||||
mod.main([str(f), "--token", "t", "--dry-run"])
|
||||
assert "validated 1 entries" in capsys.readouterr().out
|
||||
Reference in New Issue
Block a user