def test_init():
    """Test extension initialization."""
    app = Flask('testapp')
    ext = InvenioMail(app)
    assert 'invenio-mail' in app.extensions

    app = Flask('testapp')
    ext = InvenioMail()
    assert 'invenio-mail' not in app.extensions
    ext.init_app(app)
    assert 'invenio-mail' in app.extensions
Ejemplo n.º 2
0
def test_print_email():
    """Test printing of email."""
    app = Flask('testapp')
    app.config.update(MAIL_SUPPRESS_SEND=True)

    if PY3:
        from io import StringIO
    else:
        from StringIO import StringIO

    output = StringIO()
    InvenioMail(app, stream=output)

    with app.app_context():
        msg = Message("Test subject",
                      sender="*****@*****.**",
                      recipients=["*****@*****.**"],
                      body="Test Body")
        app.extensions['mail'].send(msg)

    email = output.getvalue()
    output.close()

    sep = '\r\n' if PY3 else '\n'

    assert "Subject: Test subject%s" % sep in email
    assert "From: [email protected]%s" % sep in email
    assert "To: [email protected]%s" % sep in email
    assert "{0}{0}Test Body".format(sep) in email
Ejemplo n.º 3
0
def email_task_app(request):
    """Flask application fixture."""
    app = Flask('testapp')
    app.config.update(SQLALCHEMY_DATABASE_URI=os.environ.get(
        'SQLALCHEMY_DATABASE_URI', 'sqlite://'),
                      CELERY_ALWAYS_EAGER=True,
                      CELERY_RESULT_BACKEND="cache",
                      CELERY_CACHE_BACKEND="memory",
                      CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
                      MAIL_SUPPRESS_SEND=True)
    FlaskCeleryExt(app)

    InvenioMail(app, StringIO())

    return app
Ejemplo n.º 4
0
def test_init():
    """Test extension initialization."""
    app = Flask('testapp')
    ext = InvenioMail(app)
    assert 'invenio-mail' in app.extensions

    app = Flask('testapp')
    ext = InvenioMail()
    assert 'invenio-mail' not in app.extensions
    ext.init_app(app)
    assert 'invenio-mail' in app.extensions
Ejemplo n.º 5
0
def email_app(request):
    """Email-aware Flask application fixture."""
    app = create_app(
        CFG_SITE_SUPPORT_EMAIL='*****@*****.**',
        INSPIRELABS_FEEDBACK_EMAIL='*****@*****.**',
        CELERY_ALWAYS_EAGER=True,
        CELERY_RESULT_BACKEND='cache',
        CELERY_CACHE_BACKEND='memory',
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        MAIL_SUPPRESS_SEND=True,
    )
    FlaskCeleryExt(app)

    InvenioMail(app, StringIO())

    with app.app_context():
        yield app
Ejemplo n.º 6
0
def app(request):
    """Flask application fixture."""
    instance_path = tempfile.mkdtemp()
    app = Flask('testapp', instance_path=instance_path)
    app.config.update(
        TESTING=True,
        CELERY_ALWAYS_EAGER=True,
        CELERY_CACHE_BACKEND="memory",
        CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
        CELERY_RESULT_BACKEND="cache",
        COMMUNITIES_MAIL_ENABLED=False,
        SECRET_KEY='CHANGE_ME',
        SECURITY_PASSWORD_SALT='CHANGE_ME_ALSO',
        SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                               'sqlite:///test.db'),
        SEARCH_ELASTIC_HOSTS=os.environ.get('SEARCH_ELASTIC_HOSTS', None),
        SQLALCHEMY_TRACK_MODIFICATIONS=True,
        OAISERVER_REGISTER_RECORD_SIGNALS=True,
        OAISERVER_REGISTER_SET_SIGNALS=False,
        OAISERVER_ID_PREFIX='oai:localhost:recid/',
        SERVER_NAME='inveniosoftware.org',
        THEME_SITEURL='https://inveniosoftware.org',
        MAIL_SUPPRESS_SEND=True,
    )
    FlaskCeleryExt(app)
    Menu(app)
    Babel(app)
    InvenioDB(app)
    InvenioAccounts(app)
    InvenioAssets(app)
    InvenioSearch(app)
    InvenioRecords(app)
    InvenioIndexer(app)
    InvenioOAIServer(app)
    InvenioCommunities(app)
    InvenioMail(app)

    app.register_blueprint(ui_blueprint)
    app.register_blueprint(api_blueprint, url_prefix='/api/communities')

    with app.app_context():
        yield app

    shutil.rmtree(instance_path)
Ejemplo n.º 7
0
def test_print_email():
    """Test printing of email."""
    app = Flask('testapp')
    app.config.update(MAIL_SUPPRESS_SEND=True)

    output = StringIO()
    InvenioMail(app, stream=output)

    with app.app_context():
        msg = Message('Test subject',
                      sender='*****@*****.**',
                      recipients=['*****@*****.**'],
                      body='Test Body')
        app.extensions['mail'].send(msg)

    email = output.getvalue()
    output.close()

    sep = '\r\n' if PY3 else '\n'

    assert 'Subject: Test subject{0}'.format(sep) in email
    assert 'From: [email protected]{0}'.format(sep) in email
    assert 'To: [email protected]{0}'.format(sep) in email
    assert '{0}{0}Test Body'.format(sep) in email
Ejemplo n.º 8
0
# Create Flask application
app = Flask(__name__)
app.config.update(
    ACCOUNTS_USE_CELERY=False,
    BABEL_DEFAULT_LOCALE='da',
    I18N_TRASNLATION_PATHS=[messages_path()],
    MAIL_SUPPRESS_SEND=True,
    SECRET_KEY='CHANGE_ME',
    SQLALCHEMY_DATABASE_URI=os.environ.get('SQLALCHEMY_DATABASE_URI',
                                           'sqlite:///test.db'),
    SQLALCHEMY_TRACK_MODIFICATIONS=True,
    WTF_CSRF_ENABLED=False,
)
Babel(app)
InvenioMail(app)
InvenioI18N(app)
InvenioDB(app)
if INVENIO_ASSETS_AVAILABLE:
    InvenioAssets(app)
if INVENIO_THEME_AVAILABLE:
    InvenioTheme(app)
InvenioAccounts(app)
app.register_blueprint(blueprint)
InvenioUserProfiles(app)
app.register_blueprint(blueprint2)
app.register_blueprint(blueprint_api_init)
app.register_blueprint(blueprint_ui_init)
InvenioAdmin(app,
             permission_factory=lambda x: x,
             view_class_factory=lambda x: x)