45 lines
1.5 KiB
Python
45 lines
1.5 KiB
Python
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
from datetime import datetime
|
||
|
|
from decimal import Decimal
|
||
|
|
from pathlib import Path
|
||
|
|
|
||
|
|
from broker_sync.models import AccountType, ActivityType
|
||
|
|
from broker_sync.providers.parsers.invest_engine import parse_invest_engine_email
|
||
|
|
|
||
|
|
_FIXTURES = Path(__file__).parent.parent.parent / "fixtures" / "invest_engine"
|
||
|
|
|
||
|
|
|
||
|
|
def _load(name: str) -> bytes:
|
||
|
|
return (_FIXTURES / name).read_bytes()
|
||
|
|
|
||
|
|
|
||
|
|
# -- RFC 2822 body (v2-style, single BUY) --
|
||
|
|
|
||
|
|
|
||
|
|
def test_rfc2822_single_buy_parses_to_one_activity() -> None:
|
||
|
|
activities = parse_invest_engine_email(_load("rfc2822_v2_single_buy.eml"))
|
||
|
|
assert len(activities) == 1
|
||
|
|
a = activities[0]
|
||
|
|
assert a.activity_type is ActivityType.BUY
|
||
|
|
assert a.symbol == "VUAG"
|
||
|
|
assert a.quantity == Decimal("59.539562")
|
||
|
|
assert a.unit_price == Decimal("60.46")
|
||
|
|
assert a.currency == "GBP"
|
||
|
|
assert a.date == datetime(2023, 1, 17)
|
||
|
|
assert a.account_id == "invest-engine-primary"
|
||
|
|
assert a.account_type is AccountType.ISA
|
||
|
|
|
||
|
|
|
||
|
|
def test_rfc2822_external_id_is_deterministic() -> None:
|
||
|
|
a1 = parse_invest_engine_email(_load("rfc2822_v2_single_buy.eml"))[0]
|
||
|
|
a2 = parse_invest_engine_email(_load("rfc2822_v2_single_buy.eml"))[0]
|
||
|
|
assert a1.external_id == a2.external_id
|
||
|
|
assert a1.external_id.startswith("invest-engine:")
|
||
|
|
|
||
|
|
|
||
|
|
def test_rfc2822_notes_record_parse_strategy() -> None:
|
||
|
|
a = parse_invest_engine_email(_load("rfc2822_v2_single_buy.eml"))[0]
|
||
|
|
assert a.notes is not None
|
||
|
|
assert "rfc2822" in a.notes
|