Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests: Add tests for deleting prompts by ID #2156

Merged
merged 1 commit into from
Feb 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions backend/modules/prompt/tests/test_prompt.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,42 @@
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",
headers={"Authorization": "Bearer " + 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"
Loading