Esempio n. 1
0
def test_change_flags(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_flags = mock.Mock()
    mock_imapclient.remove_flags = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)
    with writable_connection_pool(default_account.id).get() as crispin_client:
        mark_unread(crispin_client, default_account.id, message.id,
                    {"unread": False})
        mock_imapclient.add_flags.assert_called_with([22], ["\\Seen"],
                                                     silent=True)

        mark_unread(crispin_client, default_account.id, message.id,
                    {"unread": True})
        mock_imapclient.remove_flags.assert_called_with([22], ["\\Seen"],
                                                        silent=True)

        mark_starred(crispin_client, default_account.id, message.id,
                     {"starred": True})
        mock_imapclient.add_flags.assert_called_with([22], ["\\Flagged"],
                                                     silent=True)

        mark_starred(crispin_client, default_account.id, message.id,
                     {"starred": False})
        mock_imapclient.remove_flags.assert_called_with([22], ["\\Flagged"],
                                                        silent=True)
Esempio n. 2
0
def add_completely_fake_account(db, email="*****@*****.**"):
    fake_account = add_fake_gmail_account(db.session, email_address=email)
    calendar = add_fake_calendar(db.session, fake_account.namespace.id)
    for i in random_range(1, 10):
        add_fake_event(
            db.session, fake_account.namespace.id, calendar=calendar, title="%s" % i
        )

    # Add fake Threads, Messages and ImapUids.
    folder = add_fake_folder(db.session, fake_account)
    for i in random_range(1, 4):
        th = add_fake_thread(db.session, fake_account.namespace.id)

        for j in random_range(1, 3):
            msg = add_fake_msg_with_calendar_part(
                db.session, fake_account, "fake part", thread=th
            )
            db.session.add(msg)
            db.session.flush()

            for k in random_range(1, 2):
                add_fake_imapuid(
                    db.session, fake_account.id, msg, folder, int("%s%s" % (msg.id, k))
                )
    # Add fake contacts
    for i in random_range(1, 5):
        add_fake_contact(db.session, fake_account.namespace.id, uid=str(i))

    db.session.commit()

    return fake_account
Esempio n. 3
0
def test_update_metadata(db, folder):
    """Check that threads are updated correctly when a label that we haven't
    seen before is added to multiple threads -- previously, this would fail
    with an IntegrityError because autoflush was disabled."""
    first_thread = add_fake_thread(db.session, NAMESPACE_ID)
    second_thread = add_fake_thread(db.session, NAMESPACE_ID)
    uids = []

    first_thread_uids = (22222, 22223)
    for msg_uid in first_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, first_thread)
        uids.append(
            add_fake_imapuid(db.session, ACCOUNT_ID, message, folder, msg_uid))

    second_thread_uids = (22224, 22226)
    for msg_uid in second_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, second_thread)
        uids.append(
            add_fake_imapuid(db.session, ACCOUNT_ID, message, folder, msg_uid))
    db.session.add_all(uids)
    db.session.commit()

    msg_uids = first_thread_uids + second_thread_uids

    new_flags = {
        msg_uid: GmailFlags((), (u'\\some_new_label', ))
        for msg_uid in msg_uids
    }
    update_metadata(ACCOUNT_ID, db.session, folder.name, folder.id, msg_uids,
                    new_flags)
    db.session.commit()
    assert 'some_new_label' in [tag.name for tag in first_thread.tags]
    assert 'some_new_label' in [tag.name for tag in second_thread.tags]
Esempio n. 4
0
def test_deleting_from_a_message_with_multiple_uids(db, default_account,
                                                    message, thread):
    """Check that deleting a imapuid from a message with
    multiple uids doesn't mark the message for deletion."""
    inbox_folder = Folder.find_or_create(db.session, default_account, "inbox",
                                         "inbox")
    sent_folder = Folder.find_or_create(db.session, default_account, "sent",
                                        "sent")

    add_fake_imapuid(db.session, default_account.id, message, sent_folder,
                     1337)
    add_fake_imapuid(db.session, default_account.id, message, inbox_folder,
                     2222)

    assert len(message.imapuids) == 2

    remove_deleted_uids(default_account.id, inbox_folder.id, [2222])
    db.session.expire_all()

    assert (
        message.deleted_at is None
    ), "The associated message should not have been marked for deletion."

    assert len(
        message.imapuids) == 1, "The message should have only one imapuid."
Esempio n. 5
0
def test_update_metadata(db, folder):
    """Check that threads are updated correctly when a label that we haven't
    seen before is added to multiple threads -- previously, this would fail
    with an IntegrityError because autoflush was disabled."""
    first_thread = add_fake_thread(db.session, NAMESPACE_ID)
    second_thread = add_fake_thread(db.session, NAMESPACE_ID)
    uids = []

    first_thread_uids = (22222, 22223)
    for msg_uid in first_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, first_thread)
        uids.append(add_fake_imapuid(db.session, ACCOUNT_ID, message, folder, msg_uid))

    second_thread_uids = (22224, 22226)
    for msg_uid in second_thread_uids:
        message = add_fake_message(db.session, NAMESPACE_ID, second_thread)
        uids.append(add_fake_imapuid(db.session, ACCOUNT_ID, message, folder, msg_uid))
    db.session.add_all(uids)
    db.session.commit()

    msg_uids = first_thread_uids + second_thread_uids

    new_flags = {msg_uid: GmailFlags((), (u"\\some_new_label",)) for msg_uid in msg_uids}
    update_metadata(ACCOUNT_ID, db.session, folder.name, folder.id, msg_uids, new_flags)
    db.session.commit()
    assert "some_new_label" in [tag.name for tag in first_thread.tags]
    assert "some_new_label" in [tag.name for tag in second_thread.tags]
Esempio n. 6
0
def test_gmail_pagination(db, default_account, patch_crispin_client,
                          patch_handler_from_provider, folder):
    for i in range(10):
        thread = add_fake_thread(db.session, default_account.namespace.id)
        message = add_fake_message(db.session,
                                   default_account.namespace.id,
                                   thread=thread,
                                   from_addr=[{
                                       'name':
                                       '',
                                       'email':
                                       '{}@test.com'.format(str(i))
                                   }],
                                   subject='hi',
                                   g_msgid=i,
                                   received_date=datetime.datetime(
                                       2000 + i, 1, 1, 1, 0, 0))

        add_fake_imapuid(db.session, default_account.id, message, folder, i)

    first_ten_messages_db = db.session.query(Message)\
                            .filter(Message.namespace_id ==
                                    default_account.namespace.id). \
                            order_by(desc(Message.received_date)). \
                            limit(10).all()

    api_client = new_api_client(db, default_account.namespace)

    first_ten_messages_api = api_client.get_data('/messages/search?q=hi'
                                                 '&limit=10')
    assert len(first_ten_messages_api) == len(first_ten_messages_db)

    for db_message, api_message in zip(first_ten_messages_db,
                                       first_ten_messages_api):
        assert db_message.public_id == api_message['id']

    imap_uids = db.session.query(ImapUid).join(Message) \
                    .filter(
                        ImapUid.message_id == Message.id,
                        Message.g_msgid != None).all()
    uids = [uid.msg_uid for uid in imap_uids]

    first_ten_threads_db = db.session.query(Thread) \
                            .join(Message) \
                            .join(ImapUid) \
                            .filter(ImapUid.account_id == default_account.id,
                                    ImapUid.msg_uid.in_(uids),
                                    Thread.id == Message.thread_id)\
                            .order_by(desc(Message.received_date)) \
                            .limit(10).all()

    first_ten_threads_api = api_client.get_data('/threads/search?q=hi'
                                                '&limit=10')

    assert len(first_ten_threads_api) == len(first_ten_threads_db)

    for db_thread, api_thread in zip(first_ten_threads_db,
                                     first_ten_threads_api):
        assert db_thread.public_id == api_thread['id']
Esempio n. 7
0
def test_gmail_pagination(db, default_account,
                          patch_crispin_client,
                          patch_handler_from_provider,
                          folder):
    for i in range(10):
        thread = add_fake_thread(db.session, default_account.namespace.id)
        message = add_fake_message(db.session, default_account.namespace.id,
                                   thread=thread,
                                   from_addr=[{'name': '', 'email':
                                               '{}@test.com'.format(str(i))}],
                                   subject='hi',
                                   g_msgid=i,
                                   received_date=datetime.
                                   datetime(2000 + i, 1, 1, 1, 0, 0))

        add_fake_imapuid(db.session, default_account.id, message,
                         folder, i)

    first_ten_messages_db = db.session.query(Message)\
                            .filter(Message.namespace_id ==
                                    default_account.namespace.id). \
                            order_by(desc(Message.received_date)). \
                            limit(10).all()

    api_client = new_api_client(db, default_account.namespace)

    first_ten_messages_api = api_client.get_data('/messages/search?q=hi'
                                                      '&limit=10')
    assert len(first_ten_messages_api) == len(first_ten_messages_db)

    for db_message, api_message in zip(first_ten_messages_db,
                                        first_ten_messages_api):
        assert db_message.public_id == api_message['id']

    imap_uids = db.session.query(ImapUid).join(Message) \
                    .filter(
                        ImapUid.message_id == Message.id,
                        Message.g_msgid != None).all()
    uids = [uid.msg_uid for uid in imap_uids]

    first_ten_threads_db = db.session.query(Thread) \
                            .join(Message) \
                            .join(ImapUid) \
                            .filter(ImapUid.account_id == default_account.id,
                                    ImapUid.msg_uid.in_(uids),
                                    Thread.id == Message.thread_id)\
                            .order_by(desc(Message.received_date)) \
                            .limit(10).all()

    first_ten_threads_api = api_client.get_data('/threads/search?q=hi'
                                                      '&limit=10')

    assert len(first_ten_threads_api) == len(first_ten_threads_db)

    for db_thread, api_thread in zip(first_ten_threads_db,
                                        first_ten_threads_api):
        assert db_thread.public_id == api_thread['id']
Esempio n. 8
0
def test_generic_drafts_flag_constrained_by_folder(db, generic_account, folder_role):
    msg_uid = 22
    thread = add_fake_thread(db.session, generic_account.namespace.id)
    message = add_fake_message(db.session, generic_account.namespace.id, thread)
    folder = add_fake_folder(db.session, generic_account)
    add_fake_imapuid(db.session, generic_account.id, message, folder, msg_uid)

    new_flags = {msg_uid: Flags((b"\\Draft",), None)}
    update_metadata(generic_account.id, folder.id, folder_role, new_flags, db.session)
    assert message.is_draft == (folder_role == "drafts")
def test_generic_drafts_flag_constrained_by_folder(db, generic_account, folder_role):
    msg_uid = 22
    thread = add_fake_thread(db.session, generic_account.namespace.id)
    message = add_fake_message(db.session, generic_account.namespace.id, thread)
    folder = add_fake_folder(db.session, generic_account)
    add_fake_imapuid(db.session, generic_account.id, message, folder, msg_uid)

    new_flags = {msg_uid: Flags(("\\Draft",), None)}
    update_metadata(generic_account.id, folder.id, folder_role, new_flags, db.session)
    assert message.is_draft == (folder_role == "drafts")
Esempio n. 10
0
def test_change_labels(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_gmail_labels = mock.Mock()
    mock_imapclient.remove_gmail_labels = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)

    change_labels(default_account.id, message.id,
                  {'removed_labels': ['\\Inbox'],
                   'added_labels': [u'motörhead', u'μετάνοια']})
    mock_imapclient.add_gmail_labels.assert_called_with(
        [22], ['mot&APY-rhead', '&A7wDtQPEA6wDvQO,A7kDsQ-'])
    mock_imapclient.remove_gmail_labels.assert_called_with([22], ['\\Inbox'])
def test_recompute_thread_labels(db, thread, default_namespace):
    # This is smoke test that checks that a lone label gets
    # added to a thread's labels.
    account = default_namespace.account
    message = add_fake_message(db.session, default_namespace.id, thread)
    add_fake_imapuid(db.session, account.id, message, account.inbox_folder, 22)
    g_labels = thread.messages[-1].imapuids[-1].g_labels

    g_labels.append('Random-label-1')
    recompute_thread_labels(thread, db.session)
    folders = {folder.name: folder for folder in thread.folders}
    assert 'Random-label-1' in folders
Esempio n. 12
0
def test_change_labels(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_gmail_labels = mock.Mock()
    mock_imapclient.remove_gmail_labels = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)

    with writable_connection_pool(default_account.id).get() as crispin_client:
        change_labels(crispin_client, default_account.id, message.id,
                      {'removed_labels': ['\\Inbox'],
                       'added_labels': [u'motörhead', u'μετάνοια']})
        mock_imapclient.add_gmail_labels.assert_called_with(
            [22], ['mot&APY-rhead', '&A7wDtQPEA6wDvQO,A7kDsQ-'])
        mock_imapclient.remove_gmail_labels.assert_called_with([22], ['\\Inbox'])
Esempio n. 13
0
def test_change_labels(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_gmail_labels = mock.Mock()
    mock_imapclient.remove_gmail_labels = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)

    remote_change_labels(default_account, message.id,
                         db.session,
                         removed_labels=['\\Inbox'],
                         added_labels=[u'motörhead', u'μετάνοια'])
    mock_imapclient.add_gmail_labels.assert_called_with(
        [22], ['mot&APY-rhead', '&A7wDtQPEA6wDvQO,A7kDsQ-'])
    mock_imapclient.remove_gmail_labels.assert_called_with([22], ['\\Inbox'])
def test_recompute_thread_labels(db, thread, default_namespace):
    # This is smoke test that checks that a lone label gets
    # added to a thread's labels.
    account = default_namespace.account
    message = add_fake_message(db.session, default_namespace.id, thread)
    add_fake_imapuid(db.session, account.id, message,
                     account.inbox_folder, 22)
    g_labels = thread.messages[-1].imapuids[-1].g_labels

    g_labels.append('Random-label-1')
    recompute_thread_labels(thread, db.session)
    folders = {folder.name: folder for folder in thread.folders}
    assert 'Random-label-1' in folders
Esempio n. 15
0
def test_change_labels(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_gmail_labels = mock.Mock()
    mock_imapclient.remove_gmail_labels = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)

    with writable_connection_pool(default_account.id).get() as crispin_client:
        change_labels(crispin_client, default_account.id, message.id,
                      {'removed_labels': ['\\Inbox'],
                       'added_labels': [u'motörhead', u'μετάνοια']})
        mock_imapclient.add_gmail_labels.assert_called_with(
            [22], ['mot&APY-rhead', '&A7wDtQPEA6wDvQO,A7kDsQ-'], silent=True)
        mock_imapclient.remove_gmail_labels.assert_called_with([22], ['\\Inbox'],
                                                               silent=True)
Esempio n. 16
0
def folder_and_message_maps(db, default_account):
    folder_map, message_map = {}, {}
    for name in ("all", "trash", "spam"):
        # Create a folder
        display_name = name.capitalize() if name != "all" else "All Mail"
        folder = add_fake_folder(db.session, default_account, display_name, name)
        thread = add_fake_thread(db.session, default_account.namespace.id)
        # Create a message in the folder
        message = add_fake_message(db.session, default_account.namespace.id, thread)
        add_fake_imapuid(db.session, default_account.id, message, folder, 13)
        update_message_metadata(db.session, default_account, message, False)
        db.session.commit()
        folder_map[name] = folder
        message_map[name] = message
    return folder_map, message_map
Esempio n. 17
0
def folder_and_message_maps(db, default_account):
    folder_map, message_map = {}, {}
    for name in ('all', 'trash', 'spam'):
        # Create a folder
        display_name = name.capitalize() if name != 'all' else 'All Mail'
        folder = add_fake_folder(db.session, default_account, display_name, name)
        thread = add_fake_thread(db.session, default_account.namespace.id)
        # Create a message in the folder
        message = add_fake_message(db.session, default_account.namespace.id,
                                   thread)
        add_fake_imapuid(db.session, default_account.id, message, folder, 13)
        update_message_metadata(db.session, default_account, message, False)
        db.session.commit()
        folder_map[name] = folder
        message_map[name] = message
    return folder_map, message_map
Esempio n. 18
0
def test_change_flags(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_flags = mock.Mock()
    mock_imapclient.remove_flags = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)
    mark_unread(default_account.id, message.id, {'unread': False})
    mock_imapclient.add_flags.assert_called_with([22], ['\\Seen'])

    mark_unread(default_account.id, message.id, {'unread': True})
    mock_imapclient.remove_flags.assert_called_with([22], ['\\Seen'])

    mark_starred(default_account.id, message.id, {'starred': True})
    mock_imapclient.add_flags.assert_called_with([22], ['\\Flagged'])

    mark_starred(default_account.id, message.id, {'starred': False})
    mock_imapclient.remove_flags.assert_called_with([22], ['\\Flagged'])
Esempio n. 19
0
def test_change_flags(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_flags = mock.Mock()
    mock_imapclient.remove_flags = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)
    mark_unread(default_account.id, message.id, {'unread': False})
    mock_imapclient.add_flags.assert_called_with([22], ['\\Seen'])

    mark_unread(default_account.id, message.id, {'unread': True})
    mock_imapclient.remove_flags.assert_called_with([22], ['\\Seen'])

    mark_starred(default_account.id, message.id, {'starred': True})
    mock_imapclient.add_flags.assert_called_with([22], ['\\Flagged'])

    mark_starred(default_account.id, message.id, {'starred': False})
    mock_imapclient.remove_flags.assert_called_with([22], ['\\Flagged'])
Esempio n. 20
0
def add_completely_fake_account(db, email='*****@*****.**'):
    from inbox.models.backends.gmail import GmailAuthCredentials
    fake_account = add_fake_gmail_account(db.session, email_address=email)
    calendar = add_fake_calendar(db.session, fake_account.namespace.id)
    for i in random_range(1, 10):
        add_fake_event(db.session,
                       fake_account.namespace.id,
                       calendar=calendar,
                       title='%s' % i)

    # Add fake Threads, Messages and ImapUids.
    folder = add_fake_folder(db.session, fake_account)
    for i in random_range(1, 4):
        th = add_fake_thread(db.session, fake_account.namespace.id)

        for j in random_range(1, 3):
            msg = add_fake_msg_with_calendar_part(db.session,
                                                  fake_account,
                                                  'fake part',
                                                  thread=th)
            db.session.add(msg)
            db.session.flush()

            for k in random_range(1, 2):
                add_fake_imapuid(db.session, fake_account.id, msg, folder,
                                 int('%s%s' % (msg.id, k)))
    # Add fake contacts
    for i in random_range(1, 5):
        add_fake_contact(db.session, fake_account.namespace.id, uid=str(i))

    auth_creds = GmailAuthCredentials()
    auth_creds.gmailaccount = fake_account
    auth_creds.scopes = "email"
    auth_creds.g_id_token = "test"
    auth_creds.client_id = "test"
    auth_creds.client_secret = "test"
    auth_creds.refresh_token = "test"
    auth_creds.is_valid = True
    db.session.add(auth_creds)
    db.session.commit()

    return fake_account
def test_recompute_thread_labels_removes_trash(db, default_account, thread):
    default_account.trash_folder = Folder(name='Trash',
                                          account_id=default_account.id)
    message = add_fake_message(db.session, default_account.namespace.id,
                               thread)
    add_fake_imapuid(db.session, default_account.id, message,
                     default_account.inbox_folder, 22)
    db.session.commit()

    # Check that the we remove the trash folder from a thread
    # if the latest message has the inbox flag.
    # To do this, we manufacture this situation.
    g_labels = thread.messages[-1].imapuids[-1].g_labels
    if '\\Inbox' not in g_labels:
        g_labels.append('\\Inbox')

    thread.folders.add(default_account.trash_folder)
    recompute_thread_labels(thread, db.session)
    assert default_account.trash_folder not in thread.folders,\
        "should have removed trash folder from thread"
def test_recompute_thread_labels_removes_trash(db, default_account, thread):
    default_account.trash_folder = Folder(name='Trash',
                                          account_id=default_account.id)
    message = add_fake_message(db.session, default_account.namespace.id,
                               thread)
    add_fake_imapuid(db.session, default_account.id, message,
                     default_account.inbox_folder, 22)
    db.session.commit()

    # Check that the we remove the trash folder from a thread
    # if the latest message has the inbox flag.
    # To do this, we manufacture this situation.
    g_labels = thread.messages[-1].imapuids[-1].g_labels
    if '\\Inbox' not in g_labels:
        g_labels.append('\\Inbox')

    thread.folders.add(default_account.trash_folder)
    recompute_thread_labels(thread, db.session)
    assert default_account.trash_folder not in thread.folders,\
        "should have removed trash folder from thread"
Esempio n. 23
0
def test_change_labels(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_gmail_labels = mock.Mock()
    mock_imapclient.remove_gmail_labels = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)

    with writable_connection_pool(default_account.id).get() as crispin_client:
        change_labels(
            crispin_client,
            default_account.id,
            [message.id],
            {
                "removed_labels": ["\\Inbox"],
                "added_labels": [u"motörhead", u"μετάνοια"],
            },
        )
        mock_imapclient.add_gmail_labels.assert_called_with(
            [22], ["mot&APY-rhead", "&A7wDtQPEA6wDvQO,A7kDsQ-"], silent=True)
        mock_imapclient.remove_gmail_labels.assert_called_with([22],
                                                               ["\\Inbox"],
                                                               silent=True)
Esempio n. 24
0
def test_change_flags(db, default_account, message, folder, mock_imapclient):
    mock_imapclient.add_folder_data(folder.name, {})
    mock_imapclient.add_flags = mock.Mock()
    mock_imapclient.remove_flags = mock.Mock()
    add_fake_imapuid(db.session, default_account.id, message, folder, 22)
    with writable_connection_pool(default_account.id).get() as crispin_client:
        mark_unread(crispin_client, default_account.id, message.id,
                    {'unread': False})
        mock_imapclient.add_flags.assert_called_with([22], ['\\Seen'], silent=True)

        mark_unread(crispin_client, default_account.id, message.id,
                    {'unread': True})
        mock_imapclient.remove_flags.assert_called_with([22], ['\\Seen'], silent=True)

        mark_starred(crispin_client, default_account.id, message.id,
                     {'starred': True})
        mock_imapclient.add_flags.assert_called_with([22], ['\\Flagged'], silent=True)

        mark_starred(crispin_client, default_account.id, message.id,
                     {'starred': False})
        mock_imapclient.remove_flags.assert_called_with([22], ['\\Flagged'], silent=True)
Esempio n. 25
0
def sorted_gmail_messages(db, default_account, sorted_gmail_threads, folder):
    thread1, thread2, thread3 = sorted_gmail_threads
    message1 = add_fake_message(
        db.session,
        default_account.namespace.id,
        thread=thread1,
        g_msgid=1,
        from_addr=[{
            "name": "Ben Bitdiddle",
            "email": "*****@*****.**"
        }],
        to_addr=[{
            "name": "Barrack Obama",
            "email": "*****@*****.**"
        }],
        received_date=datetime.datetime(2015, 7, 9, 23, 50, 7),
        subject="YOO!",
    )

    add_fake_imapuid(db.session, default_account.id, message1, folder, 3000)

    message2 = add_fake_message(
        db.session,
        default_account.namespace.id,
        thread=thread2,
        g_msgid=2,
        from_addr=[{
            "name": "Ben Bitdiddle",
            "email": "*****@*****.**"
        }],
        to_addr=[{
            "name": "Barrack Obama",
            "email": "*****@*****.**"
        }],
        received_date=datetime.datetime(2014, 7, 9, 23, 50, 7),
        subject="Hey!",
    )

    add_fake_imapuid(db.session, default_account.id, message2, folder, 3001)

    message3 = add_fake_message(
        db.session,
        default_account.namespace.id,
        thread=thread3,
        g_msgid=3,
        from_addr=[{
            "name": "Ben Bitdiddle",
            "email": "*****@*****.**"
        }],
        to_addr=[{
            "name": "Barrack Obama",
            "email": "*****@*****.**"
        }],
        received_date=datetime.datetime(2013, 7, 9, 23, 50, 7),
        subject="Sup?",
    )

    add_fake_imapuid(db.session, default_account.id, message3, folder, 3002)

    return [message1, message2, message3]
Esempio n. 26
0
def add_completely_fake_account(db, email='*****@*****.**'):
    from inbox.models.backends.gmail import GmailAuthCredentials
    fake_account = add_fake_gmail_account(db.session, email_address=email)
    calendar = add_fake_calendar(db.session, fake_account.namespace.id)
    for i in random_range(1, 10):
        add_fake_event(db.session, fake_account.namespace.id,
                       calendar=calendar, title='%s' % i)

    # Add fake Threads, Messages and ImapUids.
    folder = add_fake_folder(db.session, fake_account)
    for i in random_range(1, 4):
        th = add_fake_thread(db.session, fake_account.namespace.id)

        for j in random_range(1, 3):
            msg = add_fake_msg_with_calendar_part(db.session,
                                                  fake_account,
                                                  'fake part', thread=th)
            db.session.add(msg)
            db.session.flush()

            for k in random_range(1, 2):
                add_fake_imapuid(db.session, fake_account.id, msg, folder,
                                 int('%s%s' % (msg.id, k)))
    # Add fake contacts
    for i in random_range(1, 5):
        add_fake_contact(db.session, fake_account.namespace.id, uid=str(i))

    auth_creds = GmailAuthCredentials()
    auth_creds.gmailaccount = fake_account
    auth_creds.scopes = "email"
    auth_creds.g_id_token = "test"
    auth_creds.client_id = "test"
    auth_creds.client_secret = "test"
    auth_creds.refresh_token = "test"
    auth_creds.is_valid = True
    db.session.add(auth_creds)
    db.session.commit()

    return fake_account
Esempio n. 27
0
def test_deleting_from_a_message_with_multiple_uids(db, default_account,
                                                    message, thread):
    """Check that deleting a imapuid from a message with
    multiple uids doesn't mark the message for deletion."""
    inbox_folder = default_account.inbox_folder
    sent_folder = default_account.sent_folder

    add_fake_imapuid(db.session, default_account.id, message, sent_folder,
                     1337)
    add_fake_imapuid(db.session, default_account.id, message, inbox_folder,
                     2222)

    assert len(message.imapuids) == 2

    remove_deleted_uids(default_account.id, db.session, [2222],
                        inbox_folder.id)

    assert message.deleted_at is None, \
        "The associated message should not have been marked for deletion."

    assert len(message.imapuids) == 1, \
        "The message should have only one imapuid."
Esempio n. 28
0
def test_deleting_from_a_message_with_multiple_uids(db, default_account,
                                                    message, thread):
    """Check that deleting a imapuid from a message with
    multiple uids doesn't mark the message for deletion."""
    inbox_folder = default_account.inbox_folder
    sent_folder = default_account.sent_folder

    add_fake_imapuid(db.session, default_account.id, message, sent_folder,
                     1337)
    add_fake_imapuid(db.session, default_account.id, message, inbox_folder,
                     2222)

    assert len(message.imapuids) == 2

    remove_deleted_uids(default_account.id, db.session, [2222],
                        inbox_folder.id)

    assert message.deleted_at is None, \
        "The associated message should not have been marked for deletion."

    assert len(message.imapuids) == 1, \
        "The message should have only one imapuid."
Esempio n. 29
0
def sorted_imap_messages(db, generic_account, sorted_imap_threads,
                         imap_folder):
    thread1, thread2, thread3 = sorted_imap_threads
    message1 = add_fake_message(db.session,
                                generic_account.namespace.id,
                                thread=thread1,
                                from_addr=[{
                                    'name': '',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                received_date=datetime.datetime(
                                    2015, 7, 9, 23, 50, 7),
                                subject='YOO!')

    add_fake_imapuid(db.session, generic_account.id, message1, imap_folder,
                     2000)

    message2 = add_fake_message(db.session,
                                generic_account.namespace.id,
                                thread=thread2,
                                from_addr=[{
                                    'name': '',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                received_date=datetime.datetime(
                                    2014, 7, 9, 23, 50, 7),
                                subject='Hey!')

    add_fake_imapuid(db.session, generic_account.id, message2, imap_folder,
                     2001)

    message3 = add_fake_message(db.session,
                                generic_account.namespace.id,
                                thread=thread3,
                                from_addr=[{
                                    'name': '',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                received_date=datetime.datetime(
                                    2013, 7, 9, 23, 50, 7),
                                subject='Sup?')

    add_fake_imapuid(db.session, generic_account.id, message3, imap_folder,
                     2002)

    return [message1, message2, message3]
Esempio n. 30
0
def different_imap_messages(db, generic_account, different_sorted_imap_threads,
                            different_imap_folder):
    thread1, thread2, thread3 = different_sorted_imap_threads
    message1 = add_fake_message(db.session,
                                generic_account.namespace.id,
                                thread=thread1,
                                from_addr=[{
                                    'name': '',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                received_date=datetime.datetime(
                                    2015, 7, 9, 23, 50, 7),
                                subject='LOL')

    add_fake_imapuid(db.session, generic_account.id, message1,
                     different_imap_folder, 5000)

    message2 = add_fake_message(db.session,
                                generic_account.namespace.id,
                                thread=thread2,
                                from_addr=[{
                                    'name': '',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                received_date=datetime.datetime(
                                    2014, 7, 9, 23, 50, 7),
                                subject='ROTFLMO')

    add_fake_imapuid(db.session, generic_account.id, message2,
                     different_imap_folder, 5001)

    message3 = add_fake_message(db.session,
                                generic_account.namespace.id,
                                thread=thread3,
                                from_addr=[{
                                    'name': '',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                received_date=datetime.datetime(
                                    2013, 7, 9, 23, 50, 7),
                                subject='ROFLCOPTER')

    add_fake_imapuid(db.session, generic_account.id, message3,
                     different_imap_folder, 5002)

    return [message1, message2, message3]
Esempio n. 31
0
def sorted_gmail_messages(db, default_account, sorted_gmail_threads, folder):
    thread1, thread2, thread3 = sorted_gmail_threads
    message1 = add_fake_message(db.session,
                                default_account.namespace.id,
                                thread=thread1,
                                from_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Barrack Obama',
                                    'email': '*****@*****.**'
                                }],
                                g_msgid=1,
                                received_date=datetime.datetime(
                                    2015, 7, 9, 23, 50, 7),
                                subject='YOO!')

    add_fake_imapuid(db.session, default_account.id, message1, folder, 3000)

    message2 = add_fake_message(db.session,
                                default_account.namespace.id,
                                thread=thread2,
                                from_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Barrack Obama',
                                    'email': '*****@*****.**'
                                }],
                                g_msgid=2,
                                received_date=datetime.datetime(
                                    2014, 7, 9, 23, 50, 7),
                                subject='Hey!')

    add_fake_imapuid(db.session, default_account.id, message2, folder, 3001)

    message3 = add_fake_message(db.session,
                                default_account.namespace.id,
                                thread=thread3,
                                from_addr=[{
                                    'name': 'Ben Bitdiddle',
                                    'email': '*****@*****.**'
                                }],
                                to_addr=[{
                                    'name': 'Barrack Obama',
                                    'email': '*****@*****.**'
                                }],
                                g_msgid=3,
                                received_date=datetime.datetime(
                                    2013, 7, 9, 23, 50, 7),
                                subject='Sup?')

    add_fake_imapuid(db.session, default_account.id, message3, folder, 3002)

    return [message1, message2, message3]
Esempio n. 32
0
def sorted_imap_messages(db, generic_account, sorted_imap_threads, folder):
    thread1, thread2, thread3 = sorted_imap_threads
    message1 = add_fake_message(db.session, generic_account.namespace.id,
                                 thread=thread1,
                                 from_addr=[{'name': '',
                                             'email':
                                                '*****@*****.**'}],
                                 to_addr=[{'name': 'Ben Bitdiddle',
                                           'email': '*****@*****.**'}],
                                 received_date=datetime.
                                 datetime(2015, 7, 9, 23, 50, 7),
                                 subject='YOO!')

    add_fake_imapuid(db.session, generic_account.id, message1,
                     folder, 2000)

    message2 = add_fake_message(db.session, generic_account.namespace.id,
                                 thread=thread2,
                                 from_addr=[{'name': '',
                                             'email':
                                                '*****@*****.**'}],
                                 to_addr=[{'name': 'Ben Bitdiddle',
                                           'email': '*****@*****.**'}],
                                 received_date=datetime.
                                 datetime(2014, 7, 9, 23, 50, 7),
                                 subject='Hey!')

    add_fake_imapuid(db.session, generic_account.id, message2,
                     folder, 2001)

    message3 = add_fake_message(db.session, generic_account.namespace.id,
                                 thread=thread3,
                                 from_addr=[{'name': '',
                                             'email':
                                                '*****@*****.**'}],
                                 to_addr=[{'name': 'Ben Bitdiddle',
                                           'email': '*****@*****.**'}],
                                 received_date=datetime.
                                 datetime(2013, 7, 9, 23, 50, 7),
                                 subject='Sup?')

    add_fake_imapuid(db.session, generic_account.id, message3,
                     folder, 2002)

    imap_ids.extend([2000, 2001, 2002])

    return [message1, message2, message3]
def different_imap_messages(db, generic_account, different_sorted_imap_threads,
                            different_imap_folder):
    thread1, thread2, thread3 = different_sorted_imap_threads
    message1 = add_fake_message(db.session, generic_account.namespace.id,
                                thread=thread1,
                                from_addr=[{'name': '',
                                            'email':
                                            '*****@*****.**'}],
                                to_addr=[{'name': 'Ben Bitdiddle',
                                          'email': '*****@*****.**'}],
                                received_date=datetime.
                                datetime(2015, 7, 9, 23, 50, 7),
                                subject='LOL')

    add_fake_imapuid(db.session, generic_account.id, message1,
                     different_imap_folder, 5000)

    message2 = add_fake_message(db.session, generic_account.namespace.id,
                                thread=thread2,
                                from_addr=[{'name': '',
                                            'email':
                                            '*****@*****.**'}],
                                to_addr=[{'name': 'Ben Bitdiddle',
                                          'email': '*****@*****.**'}],
                                received_date=datetime.
                                datetime(2014, 7, 9, 23, 50, 7),
                                subject='ROTFLMO')

    add_fake_imapuid(db.session, generic_account.id, message2,
                     different_imap_folder, 5001)

    message3 = add_fake_message(db.session, generic_account.namespace.id,
                                thread=thread3,
                                from_addr=[{'name': '',
                                            'email':
                                            '*****@*****.**'}],
                                to_addr=[{'name': 'Ben Bitdiddle',
                                          'email': '*****@*****.**'}],
                                received_date=datetime.
                                datetime(2013, 7, 9, 23, 50, 7),
                                subject='ROFLCOPTER')

    add_fake_imapuid(db.session, generic_account.id, message3,
                     different_imap_folder, 5002)

    return [message1, message2, message3]
Esempio n. 34
0
def sorted_gmail_messages(db, default_account, sorted_gmail_threads, folder):
    thread1, thread2, thread3 = sorted_gmail_threads
    message1 = add_fake_message(db.session, default_account.namespace.id,
                                 thread=thread1,
                                 from_addr=[{'name': 'Ben Bitdiddle',
                                             'email': '*****@*****.**'}],
                                 to_addr=[{'name': 'Barrack Obama',
                                           'email': '*****@*****.**'}],
                                 g_msgid=1,
                                 received_date=datetime.
                                 datetime(2015, 7, 9, 23, 50, 7),
                                 subject='YOO!')

    add_fake_imapuid(db.session, default_account.id, message1,
                     folder, 3000)

    message2 = add_fake_message(db.session, default_account.namespace.id,
                                 thread=thread2,
                                 from_addr=[{'name': 'Ben Bitdiddle',
                                             'email': '*****@*****.**'}],
                                 to_addr=[{'name': 'Barrack Obama',
                                           'email': '*****@*****.**'}],
                                 g_msgid=2,
                                 received_date=datetime.
                                 datetime(2014, 7, 9, 23, 50, 7),
                                 subject='Hey!')

    add_fake_imapuid(db.session, default_account.id, message2,
                     folder, 3001)

    message3 = add_fake_message(db.session, default_account.namespace.id,
                                 thread=thread3,
                                 from_addr=[{'name': 'Ben Bitdiddle',
                                             'email': '*****@*****.**'}],
                                 to_addr=[{'name': 'Barrack Obama',
                                           'email': '*****@*****.**'}],
                                 g_msgid=3,
                                 received_date=datetime.
                                 datetime(2013, 7, 9, 23, 50, 7),
                                 subject='Sup?')

    add_fake_imapuid(db.session, default_account.id, message3,
                     folder, 3002)

    return [message1, message2, message3]
Esempio n. 35
0
def sorted_gmail_messages(db, default_account, sorted_gmail_threads, folder):
    thread1, thread2, thread3 = sorted_gmail_threads
    message1 = add_fake_message(
        db.session,
        default_account.namespace.id,
        thread=thread1,
        g_msgid=1,
        from_addr=[{"name": "Ben Bitdiddle", "email": "*****@*****.**"}],
        to_addr=[{"name": "Barrack Obama", "email": "*****@*****.**"}],
        received_date=datetime.datetime(2015, 7, 9, 23, 50, 7),
        subject="YOO!",
    )

    add_fake_imapuid(db.session, default_account.id, message1, folder, 3000)

    message2 = add_fake_message(
        db.session,
        default_account.namespace.id,
        thread=thread2,
        g_msgid=2,
        from_addr=[{"name": "Ben Bitdiddle", "email": "*****@*****.**"}],
        to_addr=[{"name": "Barrack Obama", "email": "*****@*****.**"}],
        received_date=datetime.datetime(2014, 7, 9, 23, 50, 7),
        subject="Hey!",
    )

    add_fake_imapuid(db.session, default_account.id, message2, folder, 3001)

    message3 = add_fake_message(
        db.session,
        default_account.namespace.id,
        thread=thread3,
        g_msgid=3,
        from_addr=[{"name": "Ben Bitdiddle", "email": "*****@*****.**"}],
        to_addr=[{"name": "Barrack Obama", "email": "*****@*****.**"}],
        received_date=datetime.datetime(2013, 7, 9, 23, 50, 7),
        subject="Sup?",
    )

    add_fake_imapuid(db.session, default_account.id, message3, folder, 3002)

    return [message1, message2, message3]
Esempio n. 36
0
def sorted_imap_messages(db, generic_account, sorted_imap_threads, folder):
    thread1, thread2, thread3 = sorted_imap_threads
    message1 = add_fake_message(
        db.session,
        generic_account.namespace.id,
        thread=thread1,
        from_addr=[{"name": "", "email": "*****@*****.**"}],
        to_addr=[{"name": "Ben Bitdiddle", "email": "*****@*****.**"}],
        received_date=datetime.datetime(2015, 7, 9, 23, 50, 7),
        subject="YOO!",
    )

    add_fake_imapuid(db.session, generic_account.id, message1, folder, 2000)

    message2 = add_fake_message(
        db.session,
        generic_account.namespace.id,
        thread=thread2,
        from_addr=[{"name": "", "email": "*****@*****.**"}],
        to_addr=[{"name": "Ben Bitdiddle", "email": "*****@*****.**"}],
        received_date=datetime.datetime(2014, 7, 9, 23, 50, 7),
        subject="Hey!",
    )

    add_fake_imapuid(db.session, generic_account.id, message2, folder, 2001)

    message3 = add_fake_message(
        db.session,
        generic_account.namespace.id,
        thread=thread3,
        from_addr=[{"name": "", "email": "*****@*****.**"}],
        to_addr=[{"name": "Ben Bitdiddle", "email": "*****@*****.**"}],
        received_date=datetime.datetime(2013, 7, 9, 23, 50, 7),
        subject="Sup?",
    )

    add_fake_imapuid(db.session, generic_account.id, message3, folder, 2002)

    return [message1, message2, message3]
Esempio n. 37
0
def test_gmail_imap_uid(db, test_gmail_message, default_account, folder):
    return add_fake_imapuid(db.session,
                            default_account.id,
                            test_gmail_message,
                            folder,
                            1337)
Esempio n. 38
0
def test_imap_uid(db, test_imap_message, generic_account, imap_folder):
    return add_fake_imapuid(db.session,
                            generic_account.id,
                            test_imap_message,
                            imap_folder,
                            2222)
Esempio n. 39
0
def sorted_imap_messages(db, generic_account, sorted_imap_threads,
                         imap_folder):
    thread1, thread2, thread3 = sorted_imap_threads
    message1 = add_fake_message(
        db.session,
        generic_account.namespace.id,
        thread=thread1,
        from_addr=[{
            "name": "",
            "email": "*****@*****.**"
        }],
        to_addr=[{
            "name": "Ben Bitdiddle",
            "email": "*****@*****.**"
        }],
        received_date=datetime.datetime(2015, 7, 9, 23, 50, 7),
        subject="YOO!",
    )

    add_fake_imapuid(db.session, generic_account.id, message1, imap_folder,
                     2000)

    message2 = add_fake_message(
        db.session,
        generic_account.namespace.id,
        thread=thread2,
        from_addr=[{
            "name": "",
            "email": "*****@*****.**"
        }],
        to_addr=[{
            "name": "Ben Bitdiddle",
            "email": "*****@*****.**"
        }],
        received_date=datetime.datetime(2014, 7, 9, 23, 50, 7),
        subject="Hey!",
    )

    add_fake_imapuid(db.session, generic_account.id, message2, imap_folder,
                     2001)

    message3 = add_fake_message(
        db.session,
        generic_account.namespace.id,
        thread=thread3,
        from_addr=[{
            "name": "",
            "email": "*****@*****.**"
        }],
        to_addr=[{
            "name": "Ben Bitdiddle",
            "email": "*****@*****.**"
        }],
        received_date=datetime.datetime(2013, 7, 9, 23, 50, 7),
        subject="Sup?",
    )

    add_fake_imapuid(db.session, generic_account.id, message3, imap_folder,
                     2002)

    return [message1, message2, message3]
Esempio n. 40
0
def test_gmail_imap_uid(db, test_gmail_message, default_account, folder):
    return add_fake_imapuid(db.session, default_account.id, test_gmail_message, folder, 1337)
Esempio n. 41
0
def test_imap_uid(db, test_imap_message, generic_account, imap_folder):
    return add_fake_imapuid(db.session, generic_account.id, test_imap_message, imap_folder, 2222)