diff options
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/worker/test_data.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/worker/test_data.py b/tests/worker/test_data.py index d6eeae1..e5c30a3 100644 --- a/tests/worker/test_data.py +++ b/tests/worker/test_data.py @@ -334,3 +334,55 @@ def test_fetch_columns_subset_requested(): assert endpoint == "stock_zh_a_hist" assert all(c in df.columns for c in ("date", "symbol", "open", "close", "volume")) monkeypatch.undo() + + +# ---- identity contract: the server persists instruments with the user-facing +# market field (SH/SZ/BJ) exactly as the frontend manual-entry form sends them +# (159399 QA regression 2026-09-17: market:"SZ" used to fail with +# unsupported_market before any network attempt). Canonical "SH#600000" and +# market:"cn" bare-code inference remain the primary, unchanged contracts. ---- + +def test_split_identity_accepts_bare_code_with_market_sz_matches_device_inference(): + exch, code = data.split_identity({"symbol": "159399", "market": "SZ"}) + assert (exch, code) == ("SZ", "159399") + + +def test_split_identity_accepts_bare_code_with_market_sh(): + exch, code = data.split_identity({"symbol": "600000", "market": "SH"}) + assert (exch, code) == ("SH", "600000") + + +def test_split_identity_accepts_bare_code_with_market_cn_inference_unchanged(): + exch, code = data.split_identity({"symbol": "159399", "market": "cn"}) + assert (exch, code) == ("SZ", "159399") + + +def test_etf_fetch_passes_market_sz_instrument_to_provider(monkeypatch): + """Full fetch_source identity path: market:"SZ" (as stored by the server + from the frontend manual-entry form) must reach the sina provider.""" + captured = {} + real_frame = _sina_synth_frame() + + def fake_em(inst, s, e, f, adj): + raise data.DataError("source_unavailable", "eastmoney down (test)") + + def fake_sina(inst, s, e, f, adj): + captured["instrument"] = inst + return data.FetchResult(real_frame.copy(), "fund_etf_hist_sina", + {"symbol": "sz159399"}, real_frame.copy(), "sina") + + monkeypatch.setattr(data, "_fetch_eastmoney", fake_em) + monkeypatch.setattr(data, "_fetch_sina", fake_sina) + inst = {"symbol": "159399", "market": "SZ", "asset_type": "etf", "name": "国泰自由现金流"} + res, warns = data.fetch_source_with_warnings(inst, "2025-12-31", "2026-09-17", + "daily", "none", + ["open", "high", "low", "close", "volume"], + source="auto") + assert captured["instrument"] is inst + assert res.provider == "sina" + assert any(w.startswith("provider_fallback") for w in warns) + + +def test_split_identity_rejects_unknown_market_prefixes(): + with pytest.raises(data.DataError): + data.split_identity({"symbol": "1", "market": "adlhkj"}) |
