92 lines
4.6 KiB
Python
92 lines
4.6 KiB
Python
"""只读接口全量冒烟:每个模块的核心列表/统计/看板都必须返回 200。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import pytest
|
|
|
|
ADMIN_PATHS = [
|
|
# 工作台
|
|
"/api/v1/dashboard/overview", "/api/v1/dashboard/trends", "/api/v1/dashboard/payroll",
|
|
"/api/v1/dashboard/activities", "/api/v1/dashboard/recruitment", "/api/v1/dashboard/announcements",
|
|
# 人事档案
|
|
"/api/v1/employees", "/api/v1/employees/stats", "/api/v1/employees/options",
|
|
"/api/v1/employees/1/dossier", "/api/v1/employee-contracts", "/api/v1/employee-contracts/expiring",
|
|
"/api/v1/employee-changes", "/api/v1/employee-educations", "/api/v1/employee-work-histories",
|
|
"/api/v1/employee-families", "/api/v1/employee-certificates", "/api/v1/salary-adjustments",
|
|
# 招聘
|
|
"/api/v1/recruitment/board", "/api/v1/recruitment/stages", "/api/v1/recruitment/analytics",
|
|
"/api/v1/recruitment/todos", "/api/v1/recruitment/jobs", "/api/v1/recruitment/candidates",
|
|
"/api/v1/recruitment/applications", "/api/v1/recruitment/interviews", "/api/v1/recruitment/offers",
|
|
# 薪资
|
|
"/api/v1/payroll/items", "/api/v1/payroll/plans", "/api/v1/payroll/standards",
|
|
"/api/v1/payroll/periods", "/api/v1/payroll/batches", "/api/v1/payroll/payslips",
|
|
"/api/v1/payroll/payslips/summary", "/api/v1/payroll/payslips/tax-summary",
|
|
"/api/v1/payroll/batches/1/preview",
|
|
# 福利保险
|
|
"/api/v1/benefits/insurance-plans", "/api/v1/benefits/enrollments", "/api/v1/benefits/insurance/stats",
|
|
"/api/v1/benefits/items", "/api/v1/benefits/records", "/api/v1/benefits/records/summary",
|
|
"/api/v1/benefits/leave-types", "/api/v1/benefits/leave-balances",
|
|
"/api/v1/benefits/leave-balances/matrix", "/api/v1/benefits/leave-requests",
|
|
"/api/v1/benefits/leave-requests/statistics",
|
|
# 组织 / 系统
|
|
"/api/v1/org/departments/tree", "/api/v1/org/departments/options", "/api/v1/org/positions",
|
|
"/api/v1/org/job-levels", "/api/v1/system/users", "/api/v1/system/roles",
|
|
"/api/v1/system/permissions", "/api/v1/system/menus", "/api/v1/system/menus/tree",
|
|
"/api/v1/system/announcements", "/api/v1/system/notifications", "/api/v1/system/logs",
|
|
"/api/v1/system/dict-types", "/api/v1/system/dict-items", "/api/v1/system/dicts/gender/items",
|
|
# 通用
|
|
"/api/v1/common/options", "/api/v1/common/summary-labels", "/api/v1/common/health",
|
|
"/api/v1/common/dict", "/api/v1/common/files",
|
|
]
|
|
|
|
EMPLOYEE_PATHS = [
|
|
"/api/v1/self/home", "/api/v1/self/profile", "/api/v1/self/payslips", "/api/v1/self/insurance",
|
|
"/api/v1/self/benefits", "/api/v1/self/leave/options", "/api/v1/self/approvals",
|
|
"/api/v1/self/tasks", "/api/v1/self/notifications", "/api/v1/self/announcements",
|
|
"/api/v1/self/documents", "/api/v1/self/salary-standard",
|
|
]
|
|
|
|
|
|
@pytest.mark.parametrize("path", ADMIN_PATHS)
|
|
def test_admin_read_ok(client, admin, path):
|
|
resp = client.get(path, headers=admin, params={"page_size": 3})
|
|
assert resp.status_code == 200, f"{path} -> {resp.status_code} {resp.text[:300]}"
|
|
|
|
|
|
@pytest.mark.parametrize("path", EMPLOYEE_PATHS)
|
|
def test_employee_self_service_ok(client, employee, path):
|
|
resp = client.get(path, headers=employee, params={"page_size": 3})
|
|
assert resp.status_code == 200, f"{path} -> {resp.status_code} {resp.text[:300]}"
|
|
|
|
|
|
def test_page_envelope_contract(client, admin):
|
|
body = client.get("/api/v1/employees", headers=admin, params={"page": 2, "page_size": 5}).json()
|
|
assert set(body) >= {"items", "total", "page", "page_size", "pages"}
|
|
assert body["page"] == 2 and body["page_size"] == 5
|
|
assert len(body["items"]) <= 5
|
|
assert body["total"] >= 60
|
|
|
|
|
|
def test_list_filters_and_search(client, admin):
|
|
rows = client.get("/api/v1/employees", headers=admin, params={"keyword": "张", "page_size": 50}).json()
|
|
assert rows["items"], rows
|
|
assert all("张" in (i["name"] or "") for i in rows["items"])
|
|
|
|
dept = client.get("/api/v1/org/departments/options", headers=admin).json()[0]
|
|
filtered = client.get("/api/v1/employees", headers=admin,
|
|
params={"department_id": dept["id"], "page_size": 50}).json()
|
|
assert filtered["items"], filtered
|
|
assert {i["department_id"] for i in filtered["items"]} == {dept["id"]}
|
|
|
|
|
|
def test_openapi_documents_the_namespaced_surface(client, admin):
|
|
paths = client.get("/openapi.json").json()["paths"]
|
|
for probe in ("/api/v1/system/users", "/api/v1/org/departments/tree", "/api/v1/self/home",
|
|
"/api/v1/payroll/batches/{item_id}/calculate", "/api/v1/recruitment/board"):
|
|
assert probe in paths, probe
|
|
assert len(paths) > 190
|
|
|
|
|
|
def test_health_and_static_mount(client):
|
|
assert client.get("/health").status_code == 200
|