Exemplo n.º 1
0
def create_app(test_config=None):
    app = Flask(__name__)

    try:
        if test_config is not None:
            environment = "test"
        else:
            environment = getenv("FLASK_ENV")
        app.config.from_object(get_config(environment))
    except ValueError as error:
        print(error)
        exit(1)

    @app.route("/health-check")
    def health_check():  # pylint: disable=unused-variable
        return "FLASKR app is running."

    db.init_app(app)

    app.register_blueprint(auth.AUTH_BP)
    app.register_blueprint(blog.BLOG_BP)

    app.add_url_rule("/", endpoint="index")

    print(app.config)
    return app
Exemplo n.º 2
0
def test_port(monkeypatch):
    monkeypatch.setenv("PORT", "1234")
    config = DevelopmentConfig()
    assert config.PORT == "1234"

    monkeypatch.setenv("FLASKR_SECRET_KEY", "secret")
    production_config = get_config("production")
    assert production_config.PORT == "1234"
Exemplo n.º 3
0
def test_get_config_with_invalid_environment():
    with pytest.raises(ValueError) as raised_exception:
        get_config("")
    assert "Invalid environment:" in str(raised_exception.value)

    with pytest.raises(ValueError) as raised_exception:
        get_config("bar")
    assert "Invalid environment: bar" in str(raised_exception.value)

    with pytest.raises(ValueError) as raised_exception:
        get_config("production")
    assert "Invalid secret key." in str(raised_exception.value)
Exemplo n.º 4
0
def test_secret_key(monkeypatch):
    monkeypatch.setenv("FLASKR_SECRET_KEY", "secret")
    config = get_config("production")
    assert config.SECRET_KEY == "secret"
Exemplo n.º 5
0
def test_development_config():
    config = get_config("development")
    assert config.DEBUG is True
    assert config.TESTING is False
    assert config.SECRET_KEY == "dev"