feat(sector-radar): add weighted scores and rank-change views
This commit is contained in:
@@ -225,6 +225,35 @@ def test_no_data_is_a_stable_200_response() -> None:
|
||||
assert rankings.json()["rows"] == []
|
||||
|
||||
|
||||
def test_weighted_score_and_all_rank_changes_cross_the_http_boundary() -> None:
|
||||
reader = FakeReader()
|
||||
ranking = _ranking()
|
||||
reader.page = replace(
|
||||
reader.page,
|
||||
rows=(
|
||||
replace(
|
||||
ranking,
|
||||
observation=replace(
|
||||
ranking.observation, weighted_score=Decimal("712.345678901234")
|
||||
),
|
||||
),
|
||||
),
|
||||
comparison_trade_date=date(2026, 8, 21),
|
||||
rank_change_values={
|
||||
"BK0001.DC": {MetricKind.AMOUNT: 3, MetricKind.RATIO: 0, MetricKind.SWING: None}
|
||||
},
|
||||
)
|
||||
response = _client(reader).get("/api/v1/sector-radar/rankings", params={"view": "rank_change"})
|
||||
assert response.status_code == 200
|
||||
assert (
|
||||
reader.last_query is not None and reader.last_query.rank_change_metric is MetricKind.SWING
|
||||
)
|
||||
payload = response.json()
|
||||
assert payload["comparison_trade_date"] == "2026-08-21"
|
||||
assert payload["rows"][0]["weighted_score"] == "712.345678901234"
|
||||
assert payload["rows"][0]["rank_change_values"] == {"amount": 3, "ratio": 0, "swing": None}
|
||||
|
||||
|
||||
def test_http_contract_rejects_zero_rank_percentile() -> None:
|
||||
payload = _client(FakeReader()).get("/api/v1/sector-radar/rankings").json()["rows"][0]
|
||||
payload["rank_percentile"] = "0"
|
||||
|
||||
Reference in New Issue
Block a user