Files
shanxia2.0/backend/tests/test_crm_facet_context.py
wuzilongandCursor 6a8cd90b98 feat: cascade column facet options by current list context
Make dynamic column-facet values respect other active filters (Excel-style), with backend facet context helpers, list-page wiring, slip print/sidebar fixes, and refreshed graphify graphs.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-10-11 22:04:20 +08:00

65 lines
1.9 KiB
Python

"""CRM 列头 facet 上下文:剥离本列键。"""
from typing import Optional
from pydantic import BaseModel, ConfigDict, Field
from app.services.crm.facet_context import (
clear_facet_field_kwargs,
facet_filter_kwargs_from_body,
)
def test_clear_facet_field_kwargs_customer_no():
kwargs = {
"customer_no": "C1",
"customer_no_in": "C1,C2",
"customer_name": "Acme",
"customer_name_in": None,
}
out = clear_facet_field_kwargs(kwargs, "customerNo")
assert out["customer_no"] is None
assert out["customer_no_in"] is None
assert out["customer_name"] == "Acme"
def test_clear_facet_field_kwargs_quote_no():
kwargs = {"quote_no_in": "Q1,Q2", "customer_name_in": "A,B"}
out = clear_facet_field_kwargs(kwargs, "quoteNo")
assert out["quote_no_in"] is None
assert out["customer_name_in"] == "A,B"
class _FacetBody(BaseModel):
model_config = ConfigDict(extra="allow")
field: str
keyword: Optional[str] = None
limit: Optional[int] = 500
customer_name_in: Optional[str] = Field(default=None, alias="customerNameIn")
product_name: Optional[str] = Field(default=None, alias="productName")
page: Optional[int] = None
pageSize: Optional[int] = None
def test_facet_filter_kwargs_from_body_strips_meta_and_self():
body = _FacetBody.model_validate(
{
"field": "customerName",
"keyword": "x",
"limit": 50,
"customerNameIn": "A,B",
"productName": "P1",
"page": 1,
"pageSize": 20,
"statusIn": "on",
}
)
out = facet_filter_kwargs_from_body(body, "customerName")
assert out.get("customer_name_in") is None
assert out.get("product_name") == "P1"
assert out.get("status_in") == "on"
assert "page" not in out
assert "pageSize" not in out
assert "field" not in out