def test_adding_message_to_thread(db): """recompute_thread_labels is not invoked when a new message is added (only when UID metadata changes, or when a UID is deleted). Test that tag changes work when adding messages to a thread.""" account = db.session.query(Account).get(ACCOUNT_ID) account.namespace.create_canonical_tags() thread = db.session.query(Thread).get(THREAD_ID) account.trash_folder = Folder(name='Trash', account=account) fld_item = FolderItem(thread=thread, folder=account.trash_folder) folder_names = [folder.name for folder in thread.folders] m = Message(namespace_id=account.namespace.id, subject='test message', thread_id=thread.id, received_date=datetime.datetime.now(), size=64, sanitized_body="body", snippet="snippet") uid = ImapUid(account=account, message=m, g_labels=['\\Inbox', 'test-label'], msg_uid=22L, folder_id=account.inbox_folder.id) uid.folder = account.inbox_folder uid2 = ImapUid(account=account, message=m, g_labels=['test-2'], msg_uid=24L, folder_id=account.trash_folder.id) uid2.folder = account.trash_folder thread.messages.append(m) add_any_new_thread_labels(thread, uid, db.session) add_any_new_thread_labels(thread, uid2, db.session) folder_names = [folder.name for folder in thread.folders] for folder in folder_names: assert folder in ['Inbox', 'Trash', 'test-label', 'test-2', '[Gmail]/All Mail', '[Gmail]/Important'],\ "all folders should be present" # Now, remove the message m.imapuids.remove(uid2) db.session.delete(uid2) db.session.flush() recompute_thread_labels(thread, db.session) folder_names = [folder.name for folder in thread.folders] assert 'test-2' not in folder_names,\ "test-2 label should have been removed from thread"
def test_deleting_from_a_message_with_multiple_uids(db): # Now check that deleting a imapuid from a message with # multiple uids doesn't delete the message itself ACCOUNT_ID = 1 UID = 380 account = db.session.query(Account).get(ACCOUNT_ID) inbox_folder = account.inbox_folder spam_folder = account.spam_folder old_number_of_imapuids = len(inbox_folder.imapuids) imapuid = db.session.query(ImapUid).filter( ImapUid.account_id == ACCOUNT_ID, ImapUid.msg_uid == UID).one() message = imapuid.message message_id = message.id uid = ImapUid() uid.message = message uid.account = account uid.folder = spam_folder uid.msg_uid = 1337 db.session.commit() remove_messages(ACCOUNT_ID, db.session, [UID], inbox_folder.name) msg = db.session.query(Message).get(message_id) assert msg is not None, "the associated message should not have been deleted" assert len(msg.imapuids) == 1, "the message should have only one imapuid"
def test_adding_message_to_thread(db): """recompute_thread_labels is not invoked when a new message is added (only when UID metadata changes, or when a UID is deleted). Test that tag changes work when adding messages to a thread.""" account = db.session.query(Account).get(ACCOUNT_ID) account.namespace.create_canonical_tags() thread = db.session.query(Thread).get(THREAD_ID) account.trash_folder = Folder(name='Trash', account=account) FolderItem(thread=thread, folder=account.trash_folder) folder_names = [folder.name for folder in thread.folders] m = Message(namespace_id=account.namespace.id, subject='test message', thread_id=thread.id, received_date=datetime.datetime.now(), size=64, body="body", snippet="snippet") uid = ImapUid(account=account, message=m, g_labels=['\\Inbox', 'test-label'], msg_uid=22L, folder_id=account.inbox_folder.id) uid.folder = account.inbox_folder uid2 = ImapUid(account=account, message=m, g_labels=['test-2'], msg_uid=24L, folder_id=account.trash_folder.id) uid2.folder = account.trash_folder thread.messages.append(m) add_any_new_thread_labels(thread, uid, db.session) add_any_new_thread_labels(thread, uid2, db.session) folder_names = [folder.name for folder in thread.folders] for folder in folder_names: assert folder in ['Inbox', 'Trash', 'test-label', 'test-2', '[Gmail]/All Mail', '[Gmail]/Important'],\ "all folders should be present" # Now, remove the message m.imapuids.remove(uid2) db.session.delete(uid2) db.session.flush() recompute_thread_labels(thread, db.session) folder_names = [folder.name for folder in thread.folders] assert 'test-2' not in folder_names,\ "test-2 label should have been removed from thread"