test_08_content.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. """§8 内容运营"""
  2. import pytest
  3. pytestmark = pytest.mark.integration
  4. def test_content_materials_and_plans(api, uid):
  5. mat = api.assert_success(
  6. api.post(
  7. "/content/materials",
  8. json={
  9. "title": f"话术{uid}",
  10. "type": "script",
  11. "content": "测试内容",
  12. "tags": ["pytest"],
  13. "creatorId": 1,
  14. },
  15. ),
  16. status=201,
  17. )
  18. mat_id = mat["id"]
  19. mats = api.assert_success(api.get("/content/materials"))
  20. assert any(m["id"] == mat_id for m in mats)
  21. plan = api.assert_success(
  22. api.post(
  23. "/content/plans",
  24. json={
  25. "name": f"计划{uid}",
  26. "startDate": "2026-05-25",
  27. "endDate": "2026-05-31",
  28. "ownerId": 1,
  29. },
  30. ),
  31. status=201,
  32. )
  33. plan_id = plan["id"]
  34. item = api.assert_success(
  35. api.post(
  36. f"/content/plans/{plan_id}/items",
  37. json={
  38. "planId": plan_id,
  39. "content": "发送预告",
  40. "scheduledDate": "2026-05-30",
  41. "targetRoomIds": ["room-1"],
  42. "materialId": mat_id,
  43. },
  44. ),
  45. status=201,
  46. )
  47. assert item["planId"] == plan_id
  48. items = api.assert_success(api.get(f"/content/plans/{plan_id}/items"))
  49. assert len(items) >= 1
  50. execution = api.assert_success(api.get(f"/content/plans/{plan_id}/execution"))
  51. assert isinstance(execution, dict)
  52. api.assert_success(api.delete(f"/content/materials/{mat_id}"))