def test_delete_messages(mongo_chat_store: MongoChatStore):
    """Test deleting all messages from a chat session."""
    # Create a chat with messages
    key = "test_delete_messages"
    messages = [
        ChatMessage(role="user", content="Message to be deleted"),
        ChatMessage(role="assistant", content="This will also be deleted"),
    ]
    mongo_chat_store.set_messages(key=key, messages=messages)

    # Delete all messages
    deleted_messages = mongo_chat_store.delete_messages(key=key)

    # Verify the messages were deleted
    assert len(deleted_messages) == 2
    assert deleted_messages[0].content == "Message to be deleted"

    # Verify the chat is empty
    remaining_messages = mongo_chat_store.get_messages(key=key)
    assert len(remaining_messages) == 0

    # Verify the key is not present in the store
    keys = mongo_chat_store.get_keys()
    assert key not in keys
Test deleting all messages from a chat session.
llama-index-integrations/storage/chat_store/llama-index-storage-chat-store-mongo/tests/test_chat_store_mongo_chat_store.py