42 lines
1.4 KiB
Python
42 lines
1.4 KiB
Python
from datetime import date
|
|
from decimal import Decimal
|
|
|
|
import pytest
|
|
|
|
from app.core.contracts import RequestContext
|
|
from app.core.fund_contracts import FundQuote
|
|
from app.service import fund_quote_service
|
|
from app.service.fund_quote_service import query_fund_quote_tool
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_query_fund_quote_tool_returns_stable_payload(
|
|
monkeypatch: pytest.MonkeyPatch,
|
|
) -> None:
|
|
class StubService:
|
|
async def query(self, query: object) -> list[FundQuote]:
|
|
return [FundQuote(
|
|
fund_code="159511", fund_name="测试基金", fund_type="股票型",
|
|
nav=Decimal("1.20"), nav_date=date(2026, 9, 9),
|
|
quote_time="2026-09-09T10:00:00+08:00",
|
|
quote_source="eastmoney", is_intraday=True,
|
|
)]
|
|
|
|
class Factory:
|
|
@staticmethod
|
|
def create() -> object:
|
|
return object()
|
|
|
|
monkeypatch.setattr(fund_quote_service.HqAdapterFactory, "create", Factory.create)
|
|
monkeypatch.setattr(
|
|
fund_quote_service,
|
|
"FundQuoteService",
|
|
lambda _adapter, **_kwargs: StubService(),
|
|
)
|
|
result = await query_fund_quote_tool(
|
|
fund_quote_service.FundQuoteQuery(fund_codes=("159511",)),
|
|
RequestContext(user_id="1", trace_id="quote"),
|
|
)
|
|
assert result[0]["fund_code"] == "159511"
|
|
assert result[0]["nav"] == "1.20"
|