Files
Nexus/tests/test_validation_errors_zh.py
T
Nexus Agent a401ea5a4d fix(servers): server_ids 批量上限 2000 并修复列表 422 中文
全选 101 台批量操作不再因 max_length=50 被拒;Pydantic 列表 too_long 错误显示完整中文。

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-08 15:08:03 +08:00

48 lines
1.6 KiB
Python

"""Tests for Chinese validation error translation."""
import pytest
from server.api.schemas import SettingUpdatePayload
from server.utils.validation_errors_zh import translate_validation_msg, translate_validation_errors
def test_translate_exact_string_type():
assert translate_validation_msg("Input should be a valid string") == "必须是字符串"
def test_translate_missing_type():
assert translate_validation_msg("", "missing") == "必填"
def test_translate_min_length_pattern():
msg = "String should have at least 1 character"
assert translate_validation_msg(msg) == "至少需要 1 个字符"
def test_translate_validation_errors_list():
errors = [{"type": "string_type", "loc": ["body", "value"], "msg": "Input should be a valid string", "input": 1}]
out = translate_validation_errors(errors)
assert out[0]["msg"] == "必须是字符串"
assert out[0]["loc"] == ["body", "value"]
def test_setting_update_payload_coerces_int():
payload = SettingUpdatePayload.model_validate({"value": 160})
assert payload.value == "160"
def test_translate_list_too_long_ctx():
msg = translate_validation_msg(
"List should have at most 50 items after validation, not 101",
"too_long",
{"field_type": "List", "max_length": 50, "actual_length": 101},
)
assert msg == "最多 50 项,当前 101 项"
def test_batch_agent_accepts_101_ids():
from server.api.schemas import BatchAgentAction
payload = BatchAgentAction.model_validate({"server_ids": list(range(1, 102))})
assert len(payload.server_ids) == 101