test_prompts.py 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. from test.util.abstract_integration_test import AbstractPostgresTest
  2. from test.util.mock_user import mock_webui_user
  3. class TestPrompts(AbstractPostgresTest):
  4. BASE_PATH = "/api/v1/prompts"
  5. def test_prompts(self):
  6. # Get all prompts
  7. with mock_webui_user(id="2"):
  8. response = self.fast_api_client.get(self.create_url("/"))
  9. assert response.status_code == 200
  10. assert len(response.json()) == 0
  11. # Create a two new prompts
  12. with mock_webui_user(id="2"):
  13. response = self.fast_api_client.post(
  14. self.create_url("/create"),
  15. json={
  16. "command": "/my-command",
  17. "title": "Hello World",
  18. "content": "description",
  19. },
  20. )
  21. assert response.status_code == 200
  22. with mock_webui_user(id="3"):
  23. response = self.fast_api_client.post(
  24. self.create_url("/create"),
  25. json={
  26. "command": "/my-command2",
  27. "title": "Hello World 2",
  28. "content": "description 2",
  29. },
  30. )
  31. assert response.status_code == 200
  32. # Get all prompts
  33. with mock_webui_user(id="2"):
  34. response = self.fast_api_client.get(self.create_url("/"))
  35. assert response.status_code == 200
  36. assert len(response.json()) == 2
  37. # Get prompt by command
  38. with mock_webui_user(id="2"):
  39. response = self.fast_api_client.get(self.create_url("/command/my-command"))
  40. assert response.status_code == 200
  41. data = response.json()
  42. assert data["command"] == "/my-command"
  43. assert data["title"] == "Hello World"
  44. assert data["content"] == "description"
  45. assert data["user_id"] == "2"
  46. # Update prompt
  47. with mock_webui_user(id="2"):
  48. response = self.fast_api_client.post(
  49. self.create_url("/command/my-command2/update"),
  50. json={
  51. "command": "irrelevant for request",
  52. "title": "Hello World Updated",
  53. "content": "description Updated",
  54. },
  55. )
  56. assert response.status_code == 200
  57. data = response.json()
  58. assert data["command"] == "/my-command2"
  59. assert data["title"] == "Hello World Updated"
  60. assert data["content"] == "description Updated"
  61. assert data["user_id"] == "3"
  62. # Get prompt by command
  63. with mock_webui_user(id="2"):
  64. response = self.fast_api_client.get(self.create_url("/command/my-command2"))
  65. assert response.status_code == 200
  66. data = response.json()
  67. assert data["command"] == "/my-command2"
  68. assert data["title"] == "Hello World Updated"
  69. assert data["content"] == "description Updated"
  70. assert data["user_id"] == "3"
  71. # Delete prompt
  72. with mock_webui_user(id="2"):
  73. response = self.fast_api_client.delete(
  74. self.create_url("/command/my-command/delete")
  75. )
  76. assert response.status_code == 200
  77. # Get all prompts
  78. with mock_webui_user(id="2"):
  79. response = self.fast_api_client.get(self.create_url("/"))
  80. assert response.status_code == 200
  81. assert len(response.json()) == 1