Shared helpers enforce empty/over-limit export rules and allow clients to request visible columns by field key. Co-authored-by: Cursor <cursoragent@cursor.com>
44 lines
1.2 KiB
Python
44 lines
1.2 KiB
Python
import pytest
|
|
|
|
from app.utils.excel_export import (
|
|
EXPORT_MAX_ROWS,
|
|
ExportColumn,
|
|
ExportValidationError,
|
|
filter_export_columns,
|
|
assert_export_row_count,
|
|
)
|
|
|
|
|
|
COLS = [
|
|
ExportColumn(title="账号", field="userNo"),
|
|
ExportColumn(title="姓名", field="nickName"),
|
|
ExportColumn(title="状态", field="status", dict_type="sys_status"),
|
|
]
|
|
|
|
|
|
def test_filter_export_columns_keeps_order_and_ignores_unknown():
|
|
out = filter_export_columns(COLS, ["status", "unknown", "userNo"])
|
|
assert [c.field for c in out] == ["status", "userNo"]
|
|
|
|
|
|
def test_filter_export_columns_none_returns_all():
|
|
out = filter_export_columns(COLS, None)
|
|
assert [c.field for c in out] == ["userNo", "nickName", "status"]
|
|
|
|
|
|
def test_assert_export_row_count_empty():
|
|
with pytest.raises(ExportValidationError) as ei:
|
|
assert_export_row_count(0)
|
|
assert "没有可导出的数据" in str(ei.value)
|
|
|
|
|
|
def test_assert_export_row_count_over_limit():
|
|
with pytest.raises(ExportValidationError) as ei:
|
|
assert_export_row_count(EXPORT_MAX_ROWS + 1)
|
|
assert "50000" in str(ei.value)
|
|
|
|
|
|
def test_assert_export_row_count_ok():
|
|
assert_export_row_count(1)
|
|
assert_export_row_count(EXPORT_MAX_ROWS)
|