prompt-engine / tests /test_similar_prompts.py
Lazar Radojevic
final version
da82b2b
raw
history blame
1.36 kB
import unittest
from unittest.mock import patch, Mock
import requests
# Assuming the function to be tested is in a module named `frontend.app_ui`
from frontend.app_ui import get_similar_prompts
class TestGetSimilarPrompts(unittest.TestCase):
@patch("frontend.app_ui.requests.post")
def test_get_similar_prompts_success(self, mock_post):
# Mock the response object to simulate a successful API call
mock_response = Mock()
mock_response.status_code = 200
mock_response.json.return_value = {"prompts": ["prompt1", "prompt2", "prompt3"]}
mock_post.return_value = mock_response
# Call the function with a sample query and number
result = get_similar_prompts("test query", 3)
# Assertions
self.assertIsInstance(result, dict)
self.assertEqual(result, {"prompts": ["prompt1", "prompt2", "prompt3"]})
@patch("frontend.app_ui.requests.post")
def test_get_similar_prompts_failure(self, mock_post):
# Mock the response object to simulate a failed API call
mock_post.side_effect = requests.RequestException("Mock request exception")
# Call the function with a sample query and number
result = get_similar_prompts("test query", 3)
# Assertions
self.assertIsNone(result)
if __name__ == "__main__":
unittest.main()