test(cma): clear 10 pre-existing baseline failures (cma-baseline-tests-cleanup-20260915)
No production code changed. Root causes were all test-side staleness: - test_cash TestVoucherImport: fixture filename contained 'test' -> rejected by the intentional import guard (d71c7fe); renamed, and missing-columns case now asserts the column check is what returns 400 - test_budget_tech_improve TestP1ValueCollect: seeded voucher_details source rows; collector deliberately skips empty aggregates sinced71c7fe(no more implicit 0), and preview call now passes an explicit period - test_roadmap_r2r5 / test_budget / test_ai_suggestions: seeds hardcoded 2026-08 (authoring month) while detectors/rule engine use the current month -> replaced with current-period seeds pytest tests/ -q -rf: 1094 passed, 1 xfailed, 0 failed (baseline was 10 failed, 1084 passed, 1 xfailed)
This commit is contained in:
@@ -11,17 +11,36 @@
|
||||
import pytest
|
||||
from fastapi.testclient import TestClient
|
||||
from sqlalchemy.orm import Session
|
||||
import datetime
|
||||
|
||||
from tests.conftest import create_test_user, get_token_for_user, auth_header, create_test_kpi
|
||||
from app.models import (
|
||||
BudgetPlan, KPIValue, BudgetDeviationAlert, KPIAlert,
|
||||
KPIValueSource, KPIValueCollectLog,
|
||||
KPIValueSource, KPIValueCollectLog, VoucherDetail,
|
||||
BudgetZeroBasedItem, BudgetDerivationRule,
|
||||
CashPlanClassifyRule, CashPlanUnclassified, CashPlan,
|
||||
ScenarioSuggestion, KPIDefinition,
|
||||
)
|
||||
|
||||
|
||||
def _seed_vouchers(db, period="2026-06", entity_id=1, credit=1500.0):
|
||||
"""给自动归集造源数据(voucher_details 贷方发生额)。
|
||||
|
||||
采集器口径(d71c7fe「自动归集空汇总不写0」):源表无记录 → 返回 None 并记 skipped,
|
||||
不落 0 值 KPIValue。故本类用例必须先造源数据,否则 collected 恒为 0。
|
||||
"""
|
||||
y, m = int(period[:4]), int(period[5:7])
|
||||
db.add(VoucherDetail(
|
||||
entity_id=entity_id, voucher_no="COLLECT-001",
|
||||
voucher_date=datetime.datetime(y, m, 15),
|
||||
subject_code="6001", subject_name="主营业务收入",
|
||||
debit_amount=0.0, credit_amount=credit,
|
||||
summary="自动归集单测", carry_forward=0, period=period,
|
||||
))
|
||||
db.flush()
|
||||
|
||||
|
||||
|
||||
class TestP1AlertAttribution:
|
||||
"""P1-③ 告警归因: 告警从'差多少'到'差在哪+怎么办'"""
|
||||
|
||||
@@ -114,6 +133,7 @@ class TestP1ValueCollect:
|
||||
create_test_user(db)
|
||||
token = get_token_for_user(client)
|
||||
kpi = create_test_kpi(db, kpi_code="COLLECT_KPI")
|
||||
_seed_vouchers(db) # 源数据(无源数据采集器按设计跳过)
|
||||
|
||||
# 建映射
|
||||
resp = client.post(f"{self.BASE}/value-sources", headers=auth_header(token), json={
|
||||
@@ -135,9 +155,11 @@ class TestP1ValueCollect:
|
||||
"aggregate": "sum",
|
||||
"filter_rule": {"direction": "credit"},
|
||||
"period_field": "period",
|
||||
"period": "2026-06", # 显式期间(不传则默认当月,与造数期间错配 → value=None)
|
||||
})
|
||||
assert test_resp.status_code == 200
|
||||
assert test_resp.json()["value"] is not None
|
||||
assert test_resp.json()["value"] == 1500.0 # 贷方发生额合计(unit_conversion=1)
|
||||
|
||||
# 手动触发采集
|
||||
run_resp = client.post(f"{self.BASE}/value-collect/run", headers=auth_header(token),
|
||||
@@ -169,6 +191,7 @@ class TestP1ValueCollect:
|
||||
create_test_user(db)
|
||||
token = get_token_for_user(client)
|
||||
kpi = create_test_kpi(db, kpi_code="COLLECT_IDEMP")
|
||||
_seed_vouchers(db)
|
||||
client.post(f"{self.BASE}/value-sources", headers=auth_header(token), json={
|
||||
"kpi_id": kpi.id, "source_table": "voucher_details",
|
||||
"source_field": "credit_amount", "aggregate": "sum",
|
||||
@@ -188,6 +211,7 @@ class TestP1ValueCollect:
|
||||
create_test_user(db)
|
||||
token = get_token_for_user(client)
|
||||
kpi = create_test_kpi(db, kpi_code="COLLECT_LOG")
|
||||
_seed_vouchers(db)
|
||||
client.post(f"{self.BASE}/value-sources", headers=auth_header(token), json={
|
||||
"kpi_id": kpi.id, "source_table": "voucher_details",
|
||||
"source_field": "credit_amount", "aggregate": "sum",
|
||||
|
||||
Reference in New Issue
Block a user