Beispiel #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'
Beispiel #2
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'
Beispiel #3
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"
Beispiel #4
0
def test_folder_crud(db, default_account, mock_imapclient, obj_type):
    mock_imapclient.create_folder = mock.Mock()
    mock_imapclient.rename_folder = mock.Mock()
    mock_imapclient.delete_folder = mock.Mock()
    cat = add_fake_category(db.session, default_account.namespace.id,
                            'MyFolder')
    with writable_connection_pool(default_account.id).get() as crispin_client:
        if obj_type == 'folder':
            create_folder(crispin_client, default_account.id, cat.id)
        else:
            create_label(crispin_client, default_account.id, cat.id)
        mock_imapclient.create_folder.assert_called_with('MyFolder')

        cat.display_name = 'MyRenamedFolder'
        db.session.commit()
        if obj_type == 'folder':
            update_folder(crispin_client, default_account.id, cat.id,
                          {'old_name': 'MyFolder'})
        else:
            update_label(crispin_client, default_account.id, cat.id,
                         {'old_name': 'MyFolder'})
        mock_imapclient.rename_folder.assert_called_with('MyFolder',
                                                         'MyRenamedFolder')

        category_id = cat.id
        if obj_type == 'folder':
            delete_folder(crispin_client, default_account.id, cat.id)
        else:
            delete_label(crispin_client, default_account.id, cat.id)
    mock_imapclient.delete_folder.assert_called_with('MyRenamedFolder')
    db.session.commit()
    assert db.session.query(Category).get(category_id) is None
Beispiel #5
0
def test_folder_crud(db, default_account, mock_imapclient, obj_type):
    mock_imapclient.create_folder = mock.Mock()
    mock_imapclient.rename_folder = mock.Mock()
    mock_imapclient.delete_folder = mock.Mock()
    cat = add_fake_category(db.session, default_account.namespace.id,
                            'MyFolder')
    with writable_connection_pool(default_account.id).get() as crispin_client:
        if obj_type == 'folder':
            create_folder(crispin_client, default_account.id, cat.id)
        else:
            create_label(crispin_client, default_account.id, cat.id)
        mock_imapclient.create_folder.assert_called_with('MyFolder')

        cat.display_name = 'MyRenamedFolder'
        db.session.commit()
        if obj_type == 'folder':
            update_folder(crispin_client, default_account.id, cat.id,
                          {'old_name': 'MyFolder',
                           'new_name': 'MyRenamedFolder'})
        else:
            update_label(crispin_client, default_account.id, cat.id,
                         {'old_name': 'MyFolder',
                          'new_name': 'MyRenamedFolder'})
        mock_imapclient.rename_folder.assert_called_with('MyFolder',
                                                         'MyRenamedFolder')

        category_id = cat.id
        if obj_type == 'folder':
            delete_folder(crispin_client, default_account.id, cat.id)
        else:
            delete_label(crispin_client, default_account.id, cat.id)
    mock_imapclient.delete_folder.assert_called_with('MyRenamedFolder')
    db.session.commit()
    assert db.session.query(Category).get(category_id) is None
Beispiel #6
0
def test_updating_message_categories_increments_version(
        db, thread, default_namespace):
    assert thread.version == 0

    message = add_fake_message(db.session, default_namespace.id, thread)
    category = add_fake_category(db.session, default_namespace.id,
                                 'mia kategorio')

    # Modifying message's categories increments the thread.version
    message.categories = [category]
    db.session.commit()

    assert thread.version == 2
def test_message_category_updates_create_transaction(db, default_namespace):
    with db.session.no_autoflush:
        thr = add_fake_thread(db.session, default_namespace.id)
        msg = add_fake_message(db.session, default_namespace.id, thr)
        cat = add_fake_category(db.session, default_namespace.id, 'category')
        thread_trx_before_category_change = get_latest_transaction(
            db.session, 'thread', thr.id, default_namespace.id)

        msg.categories = [cat]
        db.session.commit()
        latest_message_trx = get_latest_transaction(
            db.session, 'message', msg.id, default_namespace.id)
        thread_trx_after_category_change = get_latest_transaction(
            db.session, 'thread', thr.id, default_namespace.id)

        assert latest_message_trx.command == 'update'
        assert thread_trx_before_category_change.id != \
            thread_trx_after_category_change.id
Beispiel #8
0
def test_message_category_updates_create_transaction(db, default_namespace):
    with db.session.no_autoflush:
        thr = add_fake_thread(db.session, default_namespace.id)
        msg = add_fake_message(db.session, default_namespace.id, thr)
        cat = add_fake_category(db.session, default_namespace.id, 'category')
        thread_trx_before_category_change = get_latest_transaction(
            db.session, 'thread', thr.id, default_namespace.id)

        msg.categories = [cat]
        db.session.commit()
        latest_message_trx = get_latest_transaction(
            db.session, 'message', msg.id, default_namespace.id)
        thread_trx_after_category_change = get_latest_transaction(
            db.session, 'thread', thr.id, default_namespace.id)

        assert latest_message_trx.command == 'update'
        assert thread_trx_before_category_change.id != \
            thread_trx_after_category_change.id
def test_message_category_updates_create_transaction(db, default_namespace):
    with db.session.no_autoflush:
        thr = add_fake_thread(db.session, default_namespace.id)
        msg = add_fake_message(db.session, default_namespace.id, thr)
        cat = add_fake_category(db.session, default_namespace.id, "category")
        thread_trx_before_category_change = get_latest_transaction(
            db.session, "thread", thr.id, default_namespace.id
        )

        msg.categories = [cat]
        db.session.commit()
        latest_message_trx = get_latest_transaction(
            db.session, "message", msg.id, default_namespace.id
        )
        thread_trx_after_category_change = get_latest_transaction(
            db.session, "thread", thr.id, default_namespace.id
        )

        assert latest_message_trx.command == "update"
        assert (
            thread_trx_before_category_change.id != thread_trx_after_category_change.id
        )