Files
group_fqcd_jr/tests/unit/service/test_offsite_fund_rules.py
T
张胜宇 e239eb778b docs: 品牌全量口径统一为「南方基金」+ 作废文档清理
1) 客服 Agent 四份交付文档 + 构建脚手架:品牌由包装占位 XX科技 / 旧名 南方财富
   统一为南方基金(热线 400-889-8899 / 官网 nffund.com),系统名改为「智能服务系统」;
   同步追加 §0.4 修订记录行,工程记录行保留原占位字面以支撑硬编码扫描验收。
2) 开发文档:清理 28 份已作废/残留文档(14 份移出归档 + 14 份仓库副本),
   新增《文档规整方案与开发前待决事项-2026-09-17》。
3) 客服agent 四份交付文档首次纳入本分支。
2026-09-17 15:15:22 +08:00

76 lines
3.5 KiB
Python

from datetime import date
from decimal import Decimal
from app.service.offsite_fund_rules import (
OffsiteFundRuleEngine,
normalize_amount_yuan,
parse_application_date,
)
def test_subscription_minimum_amount_boundary() -> None:
engine = OffsiteFundRuleEngine()
below = engine.check_subscription(
amount_yuan=Decimal("0.99"), nav=None, total_fund_shares=None,
before_holding_shares=None)
equal = engine.check_subscription(
amount_yuan=Decimal("1.00"), nav=None, total_fund_shares=None,
before_holding_shares=None)
above = engine.check_subscription(
amount_yuan=Decimal("1.01"), nav=None, total_fund_shares=None,
before_holding_shares=None)
assert below[0].result == "异常"
assert equal[0].result == "异常"
assert above[0].result == "正常"
assert above[0].calculation["实际值"] == "1.01"
assert above[0].calculation["规则值"] == "> 1 元"
assert above[0].calculation["比较"] == "1.01 > 1 元"
def test_subscription_ratio_and_share_limit_boundary() -> None:
engine = OffsiteFundRuleEngine()
normal = engine.check_subscription(
amount_yuan=Decimal("100"), nav=Decimal("1"), total_fund_shares=Decimal("1000"),
before_holding_shares=Decimal("100"))
abnormal = engine.check_subscription(
amount_yuan=Decimal("101"), nav=Decimal("1"), total_fund_shares=Decimal("1000"),
before_holding_shares=Decimal("100"))
assert {item.rule_code: item.result for item in normal}["subscription_holding_ratio"] == "正常"
assert {item.rule_code: item.result for item in abnormal}[
"subscription_holding_ratio"] == "异常"
assert {item.rule_code: item.result for item in abnormal}[
"subscription_single_share_limit"] == "异常"
holding = {item.rule_code: item for item in normal}["subscription_holding_ratio"]
assert holding.calculation["实际值"] == "20%"
assert holding.calculation["规则值"] == "≤ 20%"
assert holding.calculation["比较"] == "20% ≤ 20%"
def test_redemption_ratio_and_available_quantity_boundary() -> None:
engine = OffsiteFundRuleEngine()
normal = engine.check_redemption(
redemption_shares=Decimal("200"), total_fund_shares=Decimal("1000"),
available_quantity=Decimal("200"))
abnormal = engine.check_redemption(
redemption_shares=Decimal("201"), total_fund_shares=Decimal("1000"),
available_quantity=Decimal("200"))
assert {item.rule_code: item.result for item in normal}["redemption_large_ratio"] == "正常"
assert {item.rule_code: item.result for item in normal}[
"redemption_available_quantity"] == "正常"
assert {item.rule_code: item.result for item in abnormal}["redemption_large_ratio"] == "异常"
assert {item.rule_code: item.result for item in abnormal}[
"redemption_available_quantity"] == "异常"
def test_normalize_amount_keeps_original_unit_semantics() -> None:
assert normalize_amount_yuan("2.50", "万元") == Decimal("25000.00")
assert normalize_amount_yuan("2.50", "元") == Decimal("2.50")
assert normalize_amount_yuan("20,000.00万元", "万元") == Decimal("200000000.00")
assert normalize_amount_yuan("人民币5,000.00元", "元") == Decimal("5000.00")
assert normalize_amount_yuan("CNY 5,000.00", "元") == Decimal("5000.00")
assert normalize_amount_yuan("2.50", "美元") is None
def test_parse_application_date_accepts_compact_calendar_date() -> None:
assert parse_application_date("20260908") == date(2026, 9, 8)