55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""员工档案默认按工号升序排列。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
API = "/api/v1"
|
|
|
|
|
|
def test_employees_default_to_work_no_ascending(client, admin):
|
|
"""列表默认与显式点击工号升序都应按工号从小到大。"""
|
|
prefix = "__工号排序"
|
|
created: list[int] = []
|
|
try:
|
|
for suffix in ("10", "02", "01"):
|
|
resp = client.post(
|
|
f"{API}/employees",
|
|
headers=admin,
|
|
json={
|
|
"name": f"{prefix}{suffix}",
|
|
"work_no": f"SORT{suffix}",
|
|
"status": "active",
|
|
},
|
|
)
|
|
assert resp.status_code == 200, resp.text
|
|
created.append(resp.json()["id"])
|
|
|
|
default_rows = client.get(
|
|
f"{API}/employees",
|
|
headers=admin,
|
|
params={"keyword": prefix, "page_size": 20},
|
|
).json()
|
|
assert [row["work_no"] for row in default_rows["items"]] == [
|
|
"SORT01",
|
|
"SORT02",
|
|
"SORT10",
|
|
]
|
|
|
|
explicit_rows = client.get(
|
|
f"{API}/employees",
|
|
headers=admin,
|
|
params={
|
|
"keyword": prefix,
|
|
"page_size": 20,
|
|
"order_by": "work_no",
|
|
"order": "asc",
|
|
},
|
|
).json()
|
|
assert [row["work_no"] for row in explicit_rows["items"]] == [
|
|
"SORT01",
|
|
"SORT02",
|
|
"SORT10",
|
|
]
|
|
finally:
|
|
for employee_id in created:
|
|
client.delete(f"{API}/employees/{employee_id}", headers=admin)
|