Example #1
0
def create_app(name, config_file, **kwargs_config):
    return appfactory(
        name,
        config_file,
        load=True,
        **kwargs_config
    )
Example #2
0
def test_conf_overwrite():
    """."""
    class conf:
        SOMEVAR = True

    app = appfactory("dummyapp", conf, SOMEVAR=False)
    assert app.config['SOMEVAR'] == False
Example #3
0
def create_app(load=True, **kwargs_config):
    app = appfactory("unterwegs",
                     "unterwegs.config",
                     load=load,
                     **kwargs_config)
    compress.init_app(app)

    return app
def test_dummy_app_noext():
    """"Test celery app creation without extension."""
    pytest.importorskip("celery")
    from flask_appfactory.celery import celeryfactory
    app = appfactory("app3", None)
    celery = celeryfactory(app)
    assert celery
    assert celery.flask_app == app
    assert 'flask-celeryext' not in app.extensions
Example #5
0
def test_envvars_string():
    """."""
    class conf:
        pass

    try:
        os.environ['MYAPP_APP_CONFIG_ENVS'] = 'SOMEVAR'
        os.environ['SOMEVAR'] = 'syntaxerror'
        app = appfactory("myapp", conf)
        assert app.config['SOMEVAR'] == "syntaxerror"
    finally:
        del os.environ['MYAPP_APP_CONFIG_ENVS']
        del os.environ['SOMEVAR']
def test_dummy_app():
    """"Test celery app creation."""
    pytest.importorskip("celery")
    from flask_appfactory.celery import celeryfactory

    class conf:
        EXTENSIONS = ['flask_celeryext:FlaskCeleryExt']

    app = appfactory("app2", conf)
    celery = celeryfactory(app)
    assert celery
    assert celery.flask_app == app
    assert app.extensions['flask-celeryext'].celery == celery
Example #7
0
def test_jinja2_ext():
    """Test Jinja2 extension."""
    class conf:
        PACKAGES = ['simplemodule', 'simplemodule2']
        EXTENSIONS = ['flask_appfactory.ext.jinja2']
        JINJA2_EXTENSIONS = ['jinja2.ext.do']

    app = appfactory("dummyapp", conf)

    with app.test_client() as c:
        c.get('/simplemodule').data == "SIMPLEMODULE"
        c.get('/simplemodule2') == "SIMPLEMODULE"

    # Test reverse package order
    class conf:
        PACKAGES = ['simplemodule2', 'simplemodule']
        EXTENSIONS = ['flask_appfactory.ext.jinja2']

    app = appfactory("dummyapp", conf)

    with app.test_client() as c:
        c.get('/simplemodule').data == "SIMPLEMODULE2"
        c.get('/simplemodule2') == "SIMPLEMODULE2"
Example #8
0
def test_jinja2_ext():
    """Test Jinja2 extension."""
    class conf:
        PACKAGES = ['simplemodule', 'simplemodule2']
        EXTENSIONS = ['flask_appfactory.ext.jinja2']
        JINJA2_EXTENSIONS = ['jinja2.ext.do']

    app = appfactory("dummyapp", conf)

    with app.test_client() as c:
        c.get('/simplemodule').data == "SIMPLEMODULE"
        c.get('/simplemodule2') == "SIMPLEMODULE"

    # Test reverse package order
    class conf:
        PACKAGES = ['simplemodule2', 'simplemodule']
        EXTENSIONS = ['flask_appfactory.ext.jinja2']

    app = appfactory("dummyapp", conf)

    with app.test_client() as c:
        c.get('/simplemodule').data == "SIMPLEMODULE2"
        c.get('/simplemodule2') == "SIMPLEMODULE2"
Example #9
0
def test_dummy_app():
    """."""
    class conf:
        SOMEVAR = True

    app = appfactory("dummyapp", conf)
    assert app.name == "dummyapp"
    assert app.config['SOMEVAR']
    assert app.config['SECRET_KEY'] == "change_me"
    assert len(app.extensions['registry']['packages']) == 0
    assert len(app.extensions['registry']['blueprints']) == 0

    with app.test_client() as c:
        rv = c.get('/')
        assert rv.status_code == 404
Example #10
0
def test_simple_app_noload():
    """."""
    class conf:
        PACKAGES = ['simplemodule']

    app = appfactory("simpleapp", conf, load=False)

    assert not app.extensions['loaded']
    assert len(app.extensions['registry']['packages']) == 1
    assert 'blueprints' not in app.extensions['registry']
    assert 'SIMPLEMODULE_VAR' not in app.config
    assert 'PACKAGES' in app.config

    with app.test_client() as c:
        assert c.get('/').status_code == 404
Example #11
0
def test_simple_app():
    """."""
    class conf:
        PACKAGES = ['simplemodule']

    app = appfactory("simpleapp", conf)

    assert app.extensions['loaded']
    assert len(app.extensions['registry']['packages']) == 1
    assert len(app.extensions['registry']['blueprints']) == 1
    assert app.config['SIMPLEMODULE_VAR']

    with app.test_client() as c:
        rv = c.get('/')
        assert rv.status_code == 200
        assert rv.data == 'TEST'.encode('utf-8')
Example #12
0
def test_envvars_overwrite():
    """."""
    class conf:
        SOMEVAR = True

    try:
        os.environ['MYAPP_APP_CONFIG_ENVS'] = 'SOMEVAR, SOMEVAR1'
        os.environ['SOMEVAR'] = 'False'
        os.environ['SOMEVAR1'] = '"V1"'
        os.environ['SOMEVAR2'] = '"V2"'

        app = appfactory("myapp", conf, SOMEVAR=True)
        # Env overrides kwargs
        assert app.config['SOMEVAR'] == False
        # Only vars specified in MYAPP_APP_CONFIG_ENVS is set.
        assert app.config['SOMEVAR1'] == "V1"
        assert 'SOMEVAR2' not in app.config
    finally:
        del os.environ['MYAPP_APP_CONFIG_ENVS']
        del os.environ['SOMEVAR']
        del os.environ['SOMEVAR1']
        del os.environ['SOMEVAR2']
Example #13
0
def create_app(load=True, **kwargs_config):
    return appfactory("myapp", "myapp.config", load=load, **kwargs_config)
Example #14
0
def create_app(load=True):
    """Application factory used for testing."""
    class conf:
        PACKAGES = ['simplemodule']

    return appfactory('myapp', conf, load=load)
Example #15
0
def create_app(load=True):
    """Application factory used for testing."""
    class conf:
        PACKAGES = ['simplemodule']

    return appfactory('myapp', conf, load=load)