- 添加缺失的认证参数:appId, appSecretCode, role - 修复 analysisType 和 departmentCode 参数 - 将所有接口改为使用 Form 参数(form-data 格式) - 更新服务层支持字典参数 - 更新所有测试代码 - 所有测试通过(7/7)
51 lines
1.4 KiB
Python
51 lines
1.4 KiB
Python
"""
|
|
API 端点测试
|
|
"""
|
|
|
|
|
|
def test_root_endpoint(client):
|
|
"""测试根路径"""
|
|
response = client.get("/")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "running"
|
|
assert "swagger_docs" in data
|
|
|
|
|
|
def test_health_check(client):
|
|
"""测试健康检查端点"""
|
|
response = client.get("/health")
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["status"] == "healthy"
|
|
|
|
|
|
def test_get_token_success(client, sample_token_request):
|
|
"""测试获取 Token - 成功场景"""
|
|
response = client.post("/account/common/getToken", data=sample_token_request)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["code"] == "200"
|
|
assert "token" in data["data"]
|
|
assert "projectId" in data["data"]
|
|
|
|
|
|
def test_get_token_error_40101(client):
|
|
"""测试获取 Token - 错误场景 40101"""
|
|
request_data = {
|
|
"projectNo": "test_error_40101",
|
|
"entityName": "测试企业",
|
|
"userId": "902001",
|
|
"userName": "902001",
|
|
"appId": "remote_app",
|
|
"appSecretCode": "test_secret_code_12345",
|
|
"role": "VIEWER",
|
|
"orgCode": "902000",
|
|
"departmentCode": "902000",
|
|
}
|
|
response = client.post("/account/common/getToken", data=request_data)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["code"] == "40101"
|
|
assert data["successResponse"] == False
|