43 lines
1.7 KiB
Python
43 lines
1.7 KiB
Python
"""
|
|
tests/test_equipment_acceptance_config.py
|
|
|
|
用途:锁定设备验收预警四档天数和第 4 轮开关的保存前校验。
|
|
依赖:config_service.validate_reminder_days、parse_round_4_enabled、ValidationError。
|
|
逻辑:不连数据库。默认 30/37/44/51 通过;相等、倒序、非整数和空岗位以外的天数形状被拒绝。第 4 轮缺省关闭。
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from app.core.errors import ValidationError
|
|
from app.services.equipment_acceptance.config_service import parse_round_4_enabled, validate_reminder_days
|
|
|
|
|
|
def test_default_reminder_days_pass():
|
|
"""冻结默认值可以保存。"""
|
|
assert validate_reminder_days([30, 37, 44, 51]) == (30, 37, 44, 51)
|
|
|
|
|
|
def test_days_must_increase():
|
|
"""后一档不大于前一档时拒绝,避免两档在同一天触发。"""
|
|
with pytest.raises(ValidationError) as caught:
|
|
validate_reminder_days([30, 30, 44, 51])
|
|
assert caught.value.code == "EQUIPMENT_ACCEPTANCE.SETTINGS_INVALID"
|
|
|
|
|
|
def test_days_reject_bool_and_wrong_length():
|
|
"""布尔值在 Python 里也是 int,不能当成 1 天;档数必须是四档。"""
|
|
with pytest.raises(ValidationError):
|
|
validate_reminder_days([True, 37, 44, 51])
|
|
with pytest.raises(ValidationError):
|
|
validate_reminder_days([30, 37, 44])
|
|
|
|
|
|
def test_round_4_defaults_off_and_rejects_non_bool():
|
|
"""未传开关时按关闭处理。数字 1 不能当成启用,避免误通知总经理。"""
|
|
assert parse_round_4_enabled(None) is False
|
|
assert parse_round_4_enabled(False) is False
|
|
assert parse_round_4_enabled(True) is True
|
|
with pytest.raises(ValidationError) as caught:
|
|
parse_round_4_enabled(1)
|
|
assert caught.value.code == "EQUIPMENT_ACCEPTANCE.SETTINGS_INVALID"
|