90 lines
3.2 KiB
Python
90 lines
3.2 KiB
Python
"""CFG-001 ~ CFG-007: 配置管理测试。
|
|
|
|
覆盖功能点:
|
|
- 配置查询
|
|
- 配置更新
|
|
- 配置即时生效
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
|
|
@pytest.mark.config
|
|
@pytest.mark.p1
|
|
class TestConfigQuery:
|
|
"""CFG-001: 配置查询测试。"""
|
|
|
|
def test_query_config(self, client, admin_headers, seed_data):
|
|
"""CFG-001: 查询指定配置成功。"""
|
|
resp = client.get("/api/configs/logistics_timeout_days", headers=admin_headers)
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["code"] == 0
|
|
|
|
def test_query_nonexistent_config(self, client, admin_headers, seed_data):
|
|
"""查询不存在的配置应返回 404。"""
|
|
resp = client.get("/api/configs/nonexistent_key", headers=admin_headers)
|
|
assert resp.status_code == 404
|
|
|
|
|
|
@pytest.mark.config
|
|
@pytest.mark.p1
|
|
class TestConfigUpdate:
|
|
"""CFG-002, CFG-004 ~ CFG-006: 配置更新测试。"""
|
|
|
|
def test_update_config(self, client, admin_headers, seed_data):
|
|
"""CFG-002: 更新配置成功。"""
|
|
resp = client.put("/api/configs/logistics_timeout_days", headers=admin_headers, json={
|
|
"config_value": "3",
|
|
})
|
|
assert resp.status_code == 200
|
|
|
|
def test_update_logistics_timeout(self, client, admin_headers, seed_data):
|
|
"""CFG-004: 物流超时天数配置更新。"""
|
|
resp = client.put("/api/configs/logistics_timeout_days", headers=admin_headers, json={
|
|
"config_value": "5",
|
|
})
|
|
assert resp.status_code == 200
|
|
|
|
def test_update_inactive_customer_days(self, client, admin_headers, seed_data):
|
|
"""CFG-005: 沉默客户周期配置更新。"""
|
|
resp = client.put("/api/configs/inactive_customer_days", headers=admin_headers, json={
|
|
"config_value": "60",
|
|
})
|
|
assert resp.status_code == 200
|
|
|
|
def test_update_amount_threshold(self, client, admin_headers, seed_data):
|
|
"""CFG-006: 金额阈值配置更新。"""
|
|
resp = client.put("/api/configs/inactive_order_amount_threshold", headers=admin_headers, json={
|
|
"config_value": "2000",
|
|
})
|
|
assert resp.status_code == 200
|
|
|
|
|
|
@pytest.mark.config
|
|
@pytest.mark.p1
|
|
class TestConfigPermission:
|
|
"""CFG-003: 配置权限控制测试。"""
|
|
|
|
def test_salesman_cannot_update_config(self, client, salesman_headers, seed_data):
|
|
"""CFG-003: 业务员不能更新配置。"""
|
|
resp = client.put("/api/configs/logistics_timeout_days", headers=salesman_headers, json={
|
|
"config_value": "99",
|
|
})
|
|
assert resp.status_code == 403
|
|
|
|
def test_driver_cannot_update_config(self, client, driver_headers, seed_data):
|
|
"""司机不能更新配置。"""
|
|
resp = client.put("/api/configs/logistics_timeout_days", headers=driver_headers, json={
|
|
"config_value": "99",
|
|
})
|
|
assert resp.status_code == 403
|
|
|
|
def test_admin_can_update_config(self, client, admin_headers, seed_data):
|
|
"""管理员可以更新配置。"""
|
|
resp = client.put("/api/configs/logistics_timeout_days", headers=admin_headers, json={
|
|
"config_value": "2",
|
|
})
|
|
assert resp.status_code == 200
|