|
| 1 | +import unittest |
| 2 | +from unittest.mock import MagicMock, patch |
| 3 | +import json |
| 4 | +import datetime |
| 5 | +from plugins.shrimpgemini.shrimpgemini import shrimpgemini |
| 6 | + |
| 7 | + |
| 8 | +class TestShrimpGemini(unittest.TestCase): |
| 9 | + def setUp(self): |
| 10 | + self.plugin = shrimpgemini() |
| 11 | + # Mock settings for started() |
| 12 | + self.settings = json.dumps( |
| 13 | + {"key": "test-key", "trigger": "gemini:", "channel": "#test", "temperature": "0.5"} |
| 14 | + ) |
| 15 | + self.plugin.started(self.settings) |
| 16 | + |
| 17 | + def test_started_temperature_is_float(self): |
| 18 | + self.assertEqual(self.plugin.temperature, 0.5) |
| 19 | + self.assertIsInstance(self.plugin.temperature, float) |
| 20 | + |
| 21 | + @patch("utils.gemini.get_response") |
| 22 | + def test_respond_to_message_includes_date_time(self, mock_get_response): |
| 23 | + mock_get_response.return_value = "Test response" |
| 24 | + self.plugin.safe_privmsg = MagicMock() |
| 25 | + |
| 26 | + # Test query |
| 27 | + query = "What time is it?" |
| 28 | + server = "test-server" |
| 29 | + channel = "#test" |
| 30 | + |
| 31 | + # Call the method |
| 32 | + self.plugin.respond_to_message(query, server, channel) |
| 33 | + |
| 34 | + # Check call arguments |
| 35 | + # messages should be the second argument |
| 36 | + args, kwargs = mock_get_response.call_args |
| 37 | + messages = args[1] |
| 38 | + |
| 39 | + # The system message should be the first in the list |
| 40 | + system_msg = messages[0] |
| 41 | + self.assertEqual(system_msg["role"], "system") |
| 42 | + |
| 43 | + # Check if "Current date and time" is in the system message content |
| 44 | + self.assertIn("Current date and time:", system_msg["content"]) |
| 45 | + |
| 46 | + # Verify the date format |
| 47 | + now_str = datetime.datetime.now().astimezone().strftime("%A, %B %d, %Y") |
| 48 | + self.assertIn(now_str, system_msg["content"]) |
| 49 | + |
| 50 | + # Verify timezone is present (e.g., UTC, CET, etc.) |
| 51 | + tz_str = datetime.datetime.now().astimezone().strftime("%Z") |
| 52 | + self.assertIn(tz_str, system_msg["content"]) |
| 53 | + |
| 54 | + |
| 55 | +if __name__ == "__main__": |
| 56 | + unittest.main() |
0 commit comments