test_03_staff.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. """§3 人员管理"""
  2. import pytest
  3. pytestmark = pytest.mark.integration
  4. def test_staff_crud(api, uid):
  5. phone = f"138{uid[:8]}"
  6. created = api.assert_success(
  7. api.post(
  8. "/staff",
  9. json={
  10. "name": f"测试员工{uid}",
  11. "role": "designer",
  12. "storeId": 1,
  13. "phone": phone,
  14. },
  15. ),
  16. status=201,
  17. )
  18. staff_id = created["id"]
  19. assert created["name"] == f"测试员工{uid}"
  20. listed = api.assert_success(api.get("/staff", params={"role": "designer"}))
  21. assert any(s["id"] == staff_id for s in listed)
  22. detail = api.assert_success(api.get(f"/staff/{staff_id}"))
  23. assert detail["phone"] == phone
  24. updated = api.assert_success(
  25. api.put(f"/staff/{staff_id}", json={"guid": f"guid-{uid}", "status": 1})
  26. )
  27. assert updated["guid"] == f"guid-{uid}"
  28. guids_data = api.assert_success(api.get("/staff/active-guids"))
  29. assert "guids" in guids_data
  30. assert isinstance(guids_data["guids"], list)
  31. api.assert_success(api.delete(f"/staff/{staff_id}"))
  32. def test_staff_validation(api):
  33. api.assert_error(
  34. api.post("/staff", json={"name": "x"}),
  35. 400,
  36. "VALIDATION_ERROR",
  37. )