test_forum_creation.py 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import pytest
  2. # client is provided by conftest.py
  3. @pytest.fixture
  4. def auth_header(client):
  5. client.post("/api/v1/users/", json={"username": "testuser", "password": "password"})
  6. response = client.post("/api/v1/auth/login", data={"username": "testuser", "password": "password"})
  7. token = response.json()["access_token"]
  8. return {"Authorization": f"Bearer {token}"}
  9. def test_create_forum_with_moderator(client, auth_header):
  10. # 1. Create a moderator
  11. mod_res = client.post(
  12. "/api/v1/moderators/",
  13. json={"name": "Custom Host"},
  14. headers=auth_header
  15. )
  16. mod_id = mod_res.json()["id"]
  17. # 2. Create a persona (needed for participant)
  18. per_res = client.post(
  19. "/api/v1/personas/",
  20. json={"name": "Participant 1", "bio": "Bio"},
  21. headers=auth_header
  22. )
  23. per_id = per_res.json()["id"]
  24. # 3. Create forum with moderator_id
  25. forum_res = client.post(
  26. "/api/v1/forums/",
  27. json={
  28. "topic": "Test Topic",
  29. "participant_ids": [per_id],
  30. "moderator_id": mod_id,
  31. "duration_minutes": 30
  32. },
  33. headers=auth_header
  34. )
  35. assert forum_res.status_code == 200
  36. data = forum_res.json()
  37. assert data["topic"] == "Test Topic"
  38. assert data["moderator_id"] == mod_id
  39. assert data["moderator"]["name"] == "Custom Host"
  40. assert data["duration_minutes"] == 30
  41. assert data["start_time"] is None
  42. def test_create_forum_default_moderator(client, auth_header):
  43. # Create a persona
  44. per_res = client.post(
  45. "/api/v1/personas/",
  46. json={"name": "Participant 1", "bio": "Bio"},
  47. headers=auth_header
  48. )
  49. per_id = per_res.json()["id"]
  50. # Create forum without moderator_id
  51. forum_res = client.post(
  52. "/api/v1/forums/",
  53. json={
  54. "topic": "Default Topic",
  55. "participant_ids": [per_id],
  56. "duration_minutes": 30
  57. },
  58. headers=auth_header
  59. )
  60. assert forum_res.status_code == 200
  61. data = forum_res.json()
  62. assert data["moderator_id"] is None
  63. assert data["duration_minutes"] == 30
  64. assert data["start_time"] is None