From 3c4f93cc51dac1d98f1cf01e8cfcb79d76cacdda Mon Sep 17 00:00:00 2001 From: juk0de Date: Tue, 26 Sep 2023 18:18:11 +0200 Subject: [PATCH] test_chat: added test for file_path collision detection --- tests/test_chat.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/test_chat.py b/tests/test_chat.py index 0d4f672..fca61e5 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -235,6 +235,24 @@ class TestChatDB(TestChatBase): pathlib.Path(self.db_path.name)) self.assertEqual(str(cm.exception), "Validation failed") + def test_file_path_ID_exists(self) -> None: + """ + Tests if the CacheDB chooses another ID if a file path with + the given one exists. + """ + # create a new and empty CacheDB + db_path = tempfile.TemporaryDirectory() + cache_path = tempfile.TemporaryDirectory() + chat_db = ChatDB.from_dir(pathlib.Path(cache_path.name), + pathlib.Path(db_path.name)) + # add a message file + message = Message(Question('What?'), + file_path=pathlib.Path(cache_path.name) / f'0001{msg_suffix}') + message.to_file() + message1 = Message(Question('Where?')) + chat_db.cache_write([message1]) + self.assertEqual(message1.msg_id(), '0002') + def test_from_dir(self) -> None: chat_db = ChatDB.from_dir(pathlib.Path(self.cache_path.name), pathlib.Path(self.db_path.name))