test_chat: added test for file_path collision detection
This commit is contained in:
parent
f352d71177
commit
3bc5f7cd63
@ -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))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user