From 96fe10f2e447ee405ca25ffff9180b73eb740e8c Mon Sep 17 00:00:00 2001 From: Oleksandr Kozachuk Date: Tue, 4 Apr 2023 15:35:07 +0200 Subject: [PATCH] Add history test. --- tests/test_main.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tests/test_main.py b/tests/test_main.py index 1591cda..682d993 100644 --- a/tests/test_main.py +++ b/tests/test_main.py @@ -148,6 +148,18 @@ class TestFunctionality(TestBotBase): with pytest.raises(RuntimeError, match="Failed to generate answer after multiple retries"): await self.bot.on_message(message) + @patch("builtins.open", new_callable=mock_open) + def test_update_history_with_file(self, mock_file): + self.bot.airesponder.update_history({"q": "What's your name?"}, {"a": "AI"}, 10) + self.assertEqual(len(self.bot.airesponder.history), 2) + self.bot.airesponder.update_history({"q1": "Q1"}, {"a1": "A1"}, 2) + self.bot.airesponder.update_history({"q2": "Q2"}, {"a2": "A2"}, 2) + self.assertEqual(len(self.bot.airesponder.history), 2) + self.bot.airesponder.history_file = "mock_file.pkl" + self.bot.airesponder.update_history({"q": "What's your favorite color?"}, {"a": "Blue"}, 10) + mock_file.assert_called_once_with("mock_file.pkl", "wb") + mock_file().write.assert_called_once() + async def test_on_message_event4(self) -> None: async def acreate(*a, **kw): answer = {'answer': 'Hello!',