Files
jarca-ledger-mcp/tests/test_toss_securities_pdf.py
T

55 lines
2.6 KiB
Python

from __future__ import annotations
from pathlib import Path
import pytest
from jarca_ledger_mcp import service
from jarca_ledger_mcp.toss_securities_pdf import parse_toss_securities_pdf
SAMPLE = Path("/root/.hermes/cache/documents/doc_f4cfe8e0221f_거래내역서_20250618_20260617_1.pdf")
@pytest.mark.skipif(not SAMPLE.exists(), reason="sample Toss Securities PDF is not available")
def test_parse_toss_securities_pdf_sample():
parsed = parse_toss_securities_pdf(str(SAMPLE))
assert parsed["metadata"]["holder_name"] == "고진환"
assert parsed["metadata"]["account_number_masked"] == "123-01-048829"
assert parsed["page_count"] == 15
assert len(parsed["transactions"]) == 207
assert any(tx.action == "구매" and tx.code == "A012510" for tx in parsed["transactions"])
assert any(tx.action == "이체입금(주식회사 케이뱅크)" for tx in parsed["transactions"])
assert any(tx.section == "USD" and tx.action == "외화증권배당금입금" for tx in parsed["transactions"])
@pytest.mark.skipif(not SAMPLE.exists(), reason="sample Toss Securities PDF is not available")
def test_preview_and_import_toss_securities_pdf_sample(tmp_path):
db_path = str(tmp_path / "ledger.sqlite3")
preview = service.preview_toss_securities_pdf_import(str(SAMPLE), db_path=db_path)
assert preview["success"] is True
assert preview["row_count"] == 207
assert preview["duplicate_count"] == 0
imported = service.import_toss_securities_pdf(str(SAMPLE), db_path=db_path)
assert imported["success"] is True
assert imported["inserted_count"] == 207
assert imported["skipped_duplicate_count"] == 0
imported_again = service.import_toss_securities_pdf(str(SAMPLE), db_path=db_path)
assert imported_again["success"] is True
assert imported_again["inserted_count"] == 0
assert imported_again["skipped_duplicate_count"] == 207
txs = service.list_ledger_transactions(account_id=imported["account_id"], limit=300, db_path=db_path)
assert txs["count"] == 207
assert any(t["category"] == "수입" and t["subcategory"] == "배당" for t in txs["transactions"])
assert any(t["category"] == "이체" and t["subcategory"] == "투자이동" for t in txs["transactions"])
assert any(
t["merchant"] == "토스증권 이체출금(국민은행) 조상문" and t["category"] == "이체" and t["subcategory"] == "확인필요"
for t in txs["transactions"]
)
assert any(
t["merchant"] == "토스증권 이체입금(국민은행) 고진환" and t["category"] == "이체" and t["subcategory"] == "투자이동"
for t in txs["transactions"]
)