Пример #1
0
def test_folder_stripping(db, generic_account, imap_api_client):
    # Check that regular IMAP paths get converted to unix-style paths
    generic_account.folder_separator = '.'
    folder = add_fake_folder(db.session, generic_account)
    add_fake_category(db.session, generic_account.namespace.id,
                      'INBOX.Red.Carpet')

    r = imap_api_client.get_data('/folders')
    for folder in r:
        if 'Carpet' in folder['display_name']:
            assert folder['display_name'] == 'INBOX/Red/Carpet'

    # Check that if we define an account-level prefix, it gets stripped
    # from the API response.
    generic_account.folder_prefix = 'INBOX.'
    db.session.commit()

    r = imap_api_client.get_data('/folders')
    for folder in r:
        if 'Carpet' in folder['display_name']:
            assert folder['display_name'] == 'Red/Carpet'

    # Test again with a prefix without integrated separator:
    generic_account.folder_prefix = 'INBOX'
    db.session.commit()

    r = imap_api_client.get_data('/folders')
    for folder in r:
        if 'Carpet' in folder['display_name']:
            assert folder['display_name'] == 'Red/Carpet'
Пример #2
0
def test_folder_sanitized(db, generic_account):
    long_name = "F" * (MAX_INDEXABLE_LENGTH + 10)
    folder = add_fake_folder(db.session, generic_account, long_name)
    assert len(folder.name) == MAX_INDEXABLE_LENGTH

    # Test that we get back the correct model even when querying with a long
    # name
    found = db.session.query(Folder).filter(Folder.name == long_name).one()
    assert len(found.name) == MAX_INDEXABLE_LENGTH
    assert folder.id == found.id
    assert found.name == folder.name
Пример #3
0
def test_folder_sanitized(db, generic_account):
    long_name = 'F' * (MAX_INDEXABLE_LENGTH + 10)
    folder = add_fake_folder(db.session, generic_account, long_name)
    assert len(folder.name) == MAX_INDEXABLE_LENGTH

    # Test that we get back the correct model even when querying with a long
    # name
    found = db.session.query(Folder).filter(Folder.name == long_name).one()
    assert len(found.name) == MAX_INDEXABLE_LENGTH
    assert folder.id == found.id
    assert found.name == folder.name
Пример #4
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(('\\Draft', ), None)}
    update_metadata(generic_account.id, folder.id, folder_role, new_flags,
                    db.session)
    assert message.is_draft == (folder_role == 'drafts')
Пример #5
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(('\\Draft',), None)}
    update_metadata(generic_account.id, folder.id, folder_role, new_flags,
                    db.session)
    assert message.is_draft == (folder_role == 'drafts')
Пример #6
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
Пример #7
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
Пример #8
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
Пример #9
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