Expand unit tests for ChatGPTTelegramInferenceBot and AnthropicTelegramInferenceBot
- Added test cases for get_chat_response method in both classes. - Added test cases for handle_message method in both classes. - Added test cases for switch_model method in ChatGPTTelegramInferenceBot.
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import unittest
|
||||
from unittest.mock import patch, MagicMock
|
||||
from anthropic_telegram_inference_bot import AnthropicTelegramInferenceBot
|
||||
|
||||
class TestAnthropicTelegramInferenceBot(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.bot = AnthropicTelegramInferenceBot()
|
||||
|
||||
@patch('anthropic_telegram_inference_bot.Anthropic')
|
||||
def test_get_chat_response(self, MockAnthropic):
|
||||
mock_anthropic = MockAnthropic.return_value
|
||||
mock_anthropic.messages.create.return_value = MagicMock()
|
||||
|
||||
messages = [{"role": "user", "content": "Hello"}]
|
||||
response = self.bot.get_chat_response(messages)
|
||||
|
||||
self.assertIsNotNone(response)
|
||||
|
||||
@patch('anthropic_telegram_inference_bot.Anthropic')
|
||||
def test_handle_message(self, MockAnthropic):
|
||||
mock_anthropic = MockAnthropic.return_value
|
||||
mock_anthropic.messages.create.return_value = MagicMock(content=[MagicMock(type="message", text="response content")])
|
||||
|
||||
user_id = "user123"
|
||||
user_message = "Hello"
|
||||
response = self.bot.handle_message(user_id, user_message)
|
||||
|
||||
self.assertIsNotNone(response)
|
||||
|
||||
# Additional testing for error cases and edge cases
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user