From 70f0fdca47ff6a92b4f1823f0e33a3ddf9d1a4f9 Mon Sep 17 00:00:00 2001 From: Stan Girard Date: Tue, 6 Feb 2024 19:37:47 -0800 Subject: [PATCH] Add tests for deleting prompts by ID --- backend/modules/prompt/tests/test_prompt.py | 35 +++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/backend/modules/prompt/tests/test_prompt.py b/backend/modules/prompt/tests/test_prompt.py index 59ac7ab106a7..384e9098eeda 100644 --- a/backend/modules/prompt/tests/test_prompt.py +++ b/backend/modules/prompt/tests/test_prompt.py @@ -1,3 +1,11 @@ +import uuid + +import pytest +from fastapi import HTTPException +from modules.prompt.repository.prompts import Prompts +from modules.prompt.service.prompt_service import DeletePromptResponse + + def test_get_public_prompts(client, api_key): response = client.get( "/prompts", @@ -5,3 +13,30 @@ def test_get_public_prompts(client, api_key): ) assert response.status_code == 200 assert len(response.json()) == 0 + + +def test_delete_prompt_by_id(): + # Arrange + prompts = Prompts() + prompt_id = uuid.uuid4() # Generate a valid UUID + + # Act + result = prompts.delete_prompt_by_id(prompt_id) + + # Assert + assert isinstance(result, DeletePromptResponse) + assert result.status == "deleted" + assert result.prompt_id == prompt_id + + +def test_delete_prompt_by_id_not_found(): + # Arrange + prompts = Prompts() + prompt_id = uuid.uuid4() # Generate a valid UUID + + # Act and Assert + with pytest.raises(HTTPException) as exc_info: + prompts.delete_prompt_by_id(prompt_id) + + assert exc_info.value.status_code == 404 + assert str(exc_info.value.detail) == "Prompt not found"