45 lines
1.2 KiB
Python
45 lines
1.2 KiB
Python
"""客户列头 customerNoIn / customerNameIn / shortNameIn 单测。"""
|
|
from __future__ import annotations
|
|
|
|
from sqlalchemy.dialects import mysql
|
|
|
|
from app.services.crm.customer_list_filters import build_customer_column_filters
|
|
|
|
|
|
def _compile(clause) -> str:
|
|
return str(
|
|
clause.compile(dialect=mysql.dialect(), compile_kwargs={"literal_binds": True})
|
|
).lower()
|
|
|
|
|
|
def test_customer_no_in():
|
|
filters = build_customer_column_filters(customer_no_in="C001,C002")
|
|
assert len(filters) == 1
|
|
sql = _compile(filters[0])
|
|
assert "customer_no" in sql
|
|
assert "in (" in sql
|
|
|
|
|
|
def test_customer_name_in_skips_fuzzy():
|
|
filters = build_customer_column_filters(customer_name_in="甲", customer_name="ignored")
|
|
assert len(filters) == 1
|
|
sql = _compile(filters[0])
|
|
assert "in (" in sql
|
|
assert "like" not in sql
|
|
|
|
|
|
def test_short_name_in():
|
|
filters = build_customer_column_filters(short_name_in="简称A")
|
|
assert len(filters) == 1
|
|
assert "short_name" in _compile(filters[0])
|
|
|
|
|
|
def test_customer_facet_field_whitelist():
|
|
from app.crud.crm.customer import _CUSTOMER_COLUMN_FACET_FIELDS
|
|
|
|
assert set(_CUSTOMER_COLUMN_FACET_FIELDS.keys()) == {
|
|
"customerNo",
|
|
"customerName",
|
|
"shortName",
|
|
}
|