PayrollManagementSystem/backend/tests/unit/test_tplus_error_classes.py

16 lines
726 B
Python
Raw Normal View History

"""只接受明确驱动状态,不把含密码的未知异常当作可重试错误。"""
import pytest
from app.services.tplus.errors import classify_source_error
@pytest.mark.parametrize("state,expected", [("08S01", "SOURCE_CONNECTION_LOST"), ("HYT00", "SOURCE_TIMEOUT"), ("28000", "SOURCE_AUTH_ERROR"), ("42S22", "SOURCE_SCHEMA_ERROR"), ("42000", "READ_ERROR")])
def test_源错误分类只依赖固定状态(state, expected):
assert classify_source_error(Exception(state, "password=不可回显")) == expected
def test_未知异常不宽泛自动重试():
assert classify_source_error(RuntimeError("secret=不可回显")) == "READ_ERROR"
assert classify_source_error(TimeoutError()) == "SOURCE_TIMEOUT"