def test_condstore_flags_refresh(db, default_account, all_mail_folder, mock_imapclient, monkeypatch): monkeypatch.setattr( 'inbox.mailsync.backends.imap.generic.CONDSTORE_FLAGS_REFRESH_BATCH_SIZE', 10) uid_dict = uids.example() mock_imapclient.add_folder_data(all_mail_folder.name, uid_dict) mock_imapclient.capabilities = lambda: ['CONDSTORE'] folder_sync_engine = FolderSyncEngine(default_account.id, default_account.namespace.id, all_mail_folder.name, default_account.email_address, 'gmail', BoundedSemaphore(1)) folder_sync_engine.initial_sync() # Change the labels provided by the mock IMAP server for k, v in mock_imapclient._data[all_mail_folder.name].items(): v['X-GM-LABELS'] = ('newlabel',) v['MODSEQ'] = (k,) folder_sync_engine.highestmodseq = 0 # Don't sleep at the end of poll_impl before returning. folder_sync_engine.poll_frequency = 0 folder_sync_engine.poll_impl() imapuids = db.session.query(ImapUid). \ filter_by(folder_id=all_mail_folder.id).all() for imapuid in imapuids: assert 'newlabel' in [l.name for l in imapuid.labels] assert folder_sync_engine.highestmodseq == mock_imapclient.folder_status( all_mail_folder.name, ['HIGHESTMODSEQ'])['HIGHESTMODSEQ']
def test_generic_flags_refresh_expunges_transient_uids( db, generic_account, inbox_folder, mock_imapclient, monkeypatch): # Check that we delete UIDs which are synced but quickly deleted, so never # show up in flags refresh. uid_dict = uids.example() mock_imapclient.add_folder_data(inbox_folder.name, uid_dict) inbox_folder.imapfolderinfo = ImapFolderInfo(account=generic_account, uidvalidity=1, uidnext=1) db.session.commit() folder_sync_engine = FolderSyncEngine(generic_account.id, generic_account.namespace.id, inbox_folder.name, generic_account.email_address, 'custom', BoundedSemaphore(1)) folder_sync_engine.initial_sync() # Don't sleep at the end of poll_impl before returning. folder_sync_engine.poll_frequency = 0 folder_sync_engine.poll_impl() msg = db.session.query(Message).filter_by( namespace_id=generic_account.namespace.id).first() transient_uid = ImapUid(folder=inbox_folder, account=generic_account, message=msg, msg_uid=max(uid_dict) + 1) db.session.add(transient_uid) db.session.commit() folder_sync_engine.last_slow_refresh = None folder_sync_engine.poll_impl() with pytest.raises(ObjectDeletedError): transient_uid.id
def test_condstore_flags_refresh(db, default_account, all_mail_folder, mock_imapclient, monkeypatch): monkeypatch.setattr( 'inbox.mailsync.backends.imap.generic.CONDSTORE_FLAGS_REFRESH_BATCH_SIZE', 10) uid_dict = uids.example() mock_imapclient.add_folder_data(all_mail_folder.name, uid_dict) mock_imapclient.capabilities = lambda: ['CONDSTORE'] folder_sync_engine = FolderSyncEngine(default_account.id, default_account.namespace.id, all_mail_folder.name, default_account.email_address, 'gmail', BoundedSemaphore(1)) folder_sync_engine.initial_sync() # Change the labels provided by the mock IMAP server for k, v in mock_imapclient._data[all_mail_folder.name].items(): v['X-GM-LABELS'] = ('newlabel', ) v['MODSEQ'] = (k, ) folder_sync_engine.highestmodseq = 0 # Don't sleep at the end of poll_impl before returning. folder_sync_engine.poll_frequency = 0 folder_sync_engine.poll_impl() imapuids = db.session.query(ImapUid). \ filter_by(folder_id=all_mail_folder.id).all() for imapuid in imapuids: assert 'newlabel' in [l.name for l in imapuid.labels] assert folder_sync_engine.highestmodseq == mock_imapclient.folder_status( all_mail_folder.name, ['HIGHESTMODSEQ'])['HIGHESTMODSEQ']
def test_generic_flags_refresh_expunges_transient_uids(db, generic_account, inbox_folder, mock_imapclient, monkeypatch): # Check that we delete UIDs which are synced but quickly deleted, so never # show up in flags refresh. uid_dict = uids.example() mock_imapclient.add_folder_data(inbox_folder.name, uid_dict) inbox_folder.imapfolderinfo = ImapFolderInfo(account=generic_account, uidvalidity=1, uidnext=1) db.session.commit() folder_sync_engine = FolderSyncEngine(generic_account.id, generic_account.namespace.id, inbox_folder.name, generic_account.email_address, 'custom', BoundedSemaphore(1)) folder_sync_engine.initial_sync() # Don't sleep at the end of poll_impl before returning. folder_sync_engine.poll_frequency = 0 folder_sync_engine.poll_impl() msg = db.session.query(Message).filter_by( namespace_id=generic_account.namespace.id).first() transient_uid = ImapUid(folder=inbox_folder, account=generic_account, message=msg, msg_uid=max(uid_dict) + 1) db.session.add(transient_uid) db.session.commit() folder_sync_engine.last_slow_refresh = None folder_sync_engine.poll_impl() with pytest.raises(ObjectDeletedError): transient_uid.id
def test_new_uids_synced_when_polling(db, generic_account, inbox_folder, mock_imapclient): uid_dict = uids.example() mock_imapclient.add_folder_data(inbox_folder.name, uid_dict) inbox_folder.imapfolderinfo = ImapFolderInfo(account=generic_account, uidvalidity=1, uidnext=1) db.session.commit() folder_sync_engine = FolderSyncEngine(generic_account.id, inbox_folder.name, inbox_folder.id, generic_account.email_address, 'custom', BoundedSemaphore(1)) folder_sync_engine.poll_frequency = 0 folder_sync_engine.poll_impl() saved_uids = db.session.query(ImapUid).filter( ImapUid.folder_id == inbox_folder.id) assert {u.msg_uid for u in saved_uids} == set(uid_dict)
def test_new_uids_synced_when_polling(db, generic_account, inbox_folder, mock_imapclient): uid_dict = uids.example() mock_imapclient.add_folder_data(inbox_folder.name, uid_dict) inbox_folder.imapfolderinfo = ImapFolderInfo(account=generic_account, uidvalidity=1, uidnext=1) db.session.commit() folder_sync_engine = FolderSyncEngine(generic_account.id, generic_account.namespace.id, inbox_folder.name, generic_account.email_address, 'custom', BoundedSemaphore(1)) folder_sync_engine.poll_frequency = 0 folder_sync_engine.poll_impl() saved_uids = db.session.query(ImapUid).filter( ImapUid.folder_id == inbox_folder.id) assert {u.msg_uid for u in saved_uids} == set(uid_dict)
def test_condstore_flags_refresh(db, default_account, all_mail_folder, mock_imapclient, monkeypatch): monkeypatch.setattr( "inbox.mailsync.backends.imap.generic.CONDSTORE_FLAGS_REFRESH_BATCH_SIZE", 10) uid_dict = uids.example() mock_imapclient.add_folder_data(all_mail_folder.name, uid_dict) mock_imapclient.capabilities = lambda: [b"CONDSTORE"] folder_sync_engine = FolderSyncEngine( default_account.id, default_account.namespace.id, all_mail_folder.name, default_account.email_address, "gmail", BoundedSemaphore(1), ) folder_sync_engine.initial_sync() # Change the labels provided by the mock IMAP server for k, v in mock_imapclient._data[all_mail_folder.name].items(): v[b"X-GM-LABELS"] = (b"newlabel", ) v[b"MODSEQ"] = (k, ) with folder_sync_engine.conn_pool.get() as crispin_client: assert crispin_client.condstore_supported() folder_sync_engine.highestmodseq = 0 # Don't sleep at the end of poll_impl before returning. folder_sync_engine.poll_frequency = 0 folder_sync_engine.poll_impl() imapuids = db.session.query(ImapUid).filter_by( folder_id=all_mail_folder.id).all() for imapuid in imapuids: assert "newlabel" in [l.name for l in imapuid.labels] assert (folder_sync_engine.highestmodseq == mock_imapclient.folder_status( all_mail_folder.name, ["HIGHESTMODSEQ"])[b"HIGHESTMODSEQ"])