def test_jwtkey_flag(with_keys):
    _,jwt = with_keys
    config_short = serverconfig.get_config(['-jk',jwt])
    config_long = serverconfig.get_config([f'--jwtkey={jwt}'])
    
    assert config_short.JWT_KEY == jwt # Check JWT_KEY
    config_is_base(config_short)
    
    assert config_long.JWT_KEY == jwt  # Check JWT_KEY
    config_is_base(config_long)
def test_serverkey_flag(with_keys):
    key,_ = with_keys
    config_short = serverconfig.get_config(['-sk',key])
    config_long = serverconfig.get_config([f'--serverkey={key}'])
    
    assert config_short.SECRET_KEY == key # Check SECRET_KEY
    config_is_base(config_short)
    
    assert config_long.SECRET_KEY == key # Check SECRET_KEY
    config_is_base(config_long)
def test_keys_flag(with_keys):
    key,jwt = with_keys
    config_short = serverconfig.get_config(['-k',key,jwt])
    config_long = serverconfig.get_config(['--keys',key,jwt])
    
    assert config_short.SECRET_KEY == key # Check SECRET_KEY
    assert config_short.JWT_KEY == jwt    # Check JWT_KEY
    config_is_base(config_short)
    
    assert config_long.SECRET_KEY == key  # Check SECRET_KEY
    assert config_long.JWT_KEY == jwt     # Check JWT_KEY
    config_is_base(config_long)
def test_keydb_env(set_env,with_keys):
    key,jwt = with_keys
    db_uri = 'dburi'
    set_env(env_dict={'SECRET_KEY':key, 'JWT_KEY':jwt, 'DATABASE_URI':db_uri})
    config = serverconfig.get_config([])
    assert config.SECRET_KEY == key # Check SECRET_KEY
    assert config.JWT_KEY == jwt    # Check JWT_KEY
    assert config.DATABASE_URI == db_uri # Check DATABASE_URI
Exemplo n.º 5
0
def create_app(conf=None, log=False, return_ext=None):
    global init
    logger = make_logger("APPFACTORY")

    if not log:
        logger.setLevel(logging.WARNING)

    # Configures App
    app = Flask(__name__)
    config = conf if conf else get_config()
    logger.debug(f"Config name: {config.CONFIG_NAME}")
    # Session(app)
    app.config.from_object(config)
    logger.debug(f"App configured with {config.CONFIG_NAME}")

    # Logs app initialization type for debug mode
    if not config.DEBUG:
        logger.debug("Creating Application")
    elif not init:
        logger.debug("Creating watch instance")
    else:
        logger.debug("Creating Server instance")

    # Mock Setup
    if config.DEBUG or config.TESTING:
        from server.mocks import setup_mocks

        setup_mocks()

    # Configures socketio function wrappers
    from server.socket_events.socket_utils import configure_socket_functions

    # configure_socket_functions(config, logger=logger)

    # Socket event imports
    #! Dont move this or it will break things
    import server.socket_events.message_events
    import server.socket_events.debug_events
    import server.socket_events.connection_events
    import server.socket_events.game_events

    # Extention initialization
    CORS(app)
    db.init_app(app)
    migrate.init_app(app, db=db)
    socketio.init_app(
        app,
        logger=socketio_logger,
        engineio_logger=engineio_logger,
        cors_allowed_origins="*",
    )
    celery.conf.update(app.config)

    # Helper class initialization
    poolman.init_app(app)
    auth.init_app(app)

    # Attaches helper classes to g
    @app.before_request
    def attach_globs():
        g.poolman = poolman
        g.auth = auth
        serverlogger.debug("Globals attached")

    logger.debug("Extensions initialized")

    # Registering Blueprints
    from server.blueprints.registration_bp import registration_bp
    from server.blueprints.auth_bp import auth_bp
    from server.blueprints.user_bp import user_bp
    from server.blueprints.message_bp import message_bp
    from server.blueprints.load_bp import load_bp

    app.register_blueprint(auth_bp)
    logger.debug("Added authbp")
    app.register_blueprint(registration_bp)
    logger.debug("Added registrationbp")
    app.register_blueprint(user_bp)
    logger.debug("Added userbp")
    app.register_blueprint(message_bp)
    logger.debug("Added message_bp")
    app.register_blueprint(load_bp)
    logger.debug("Added load_bp")
    logger.debug("Blueprints Added")

    @app.route("/", methods=["GET", "POST"])
    def index_page():
        import server.db.game_actions

        server.db.game_actions.test3()
        return "<h1>hello world</h1>"

    # Logs app initialization type for debug mode
    if not config.DEBUG:
        logger.debug(f"App Created. Config: {app.config['CONFIG_NAME']}")
    elif not init:
        logger.debug(
            f"Application watch instance created. Config: {app.config['CONFIG_NAME']}"
        )
        init += 1
    else:
        logger.debug(
            f"Application server instance created. Config: {app.config['CONFIG_NAME']}"
        )
    if return_ext:
        if return_ext == "socketio":
            return app, socketio

    return app
def test_testing_flag():
    config_test = serverconfig.get_config(['-t'])
    config_is_test(config_test)
def test_debug_flag():
    config_dev = serverconfig.get_config(['-d'])
    config_is_dev(config_dev)
def test_prod_flag():
    config_base = serverconfig.get_config(['-p'])
    config_is_base(config_base)
def test_testing_env(set_env):
    set_env(env_dict={'DEBUG':'FALSE', 'TESTING':'TRUE'})
    config_test = serverconfig.get_config([])
    config_is_test(config_test)
def test_debug_env(set_env):
    set_env(env_dict={'DEBUG':'TRUE', 'TESTING':'FALSE'})
    config_dev = serverconfig.get_config([])
    config_is_dev(config_dev)
def test_prod_env(set_env):
    set_env(env_dict={'DEBUG':'FALSE', 'TESTING':'FALSE'})
    config_base = serverconfig.get_config([])
    config_is_base(config_base)