def init_crud_clients(): config = nest_config.generate_config(ProjectEnv.knoweng_instance(), RunLevel.development_instance()) init_token_maker(config['JWT_SECRET'], config['JWT_ISSUER'], config['JWT_AUDIENCES']) global SCHEMA_REGISTRY SCHEMA_REGISTRY = knoweng_schemas.get_schemas() global CLIENT_REGISTRY CLIENT_REGISTRY = dict() #make db clients #TODO: knoweng should declare the db it's using, but for now #the default postgres container on localhost is all there is, #which is what the global db engine defaults to. engine = nest_db.get_global_sqlalchemy_engine() sqla_md = nest_db.get_global_sqlalchemy_metadata() db_client_makers = knoweng_db.get_sqla_makers() for name in DB_COLLECTIONS: cm = db_client_makers[name] client = cm.get_db_client(engine, sqla_md) CLIENT_REGISTRY[name] = client #make api clients http_client = get_http_client() api_client_makers = knoweng_api_clients.get_api_client_makers() for name in API_COLLECTIONS: cm = api_client_makers[name] crud_client = cm.get_crud_client(http_client) CLIENT_REGISTRY[name] = crud_client return
def make_flask_app(): project_env = ProjectEnv.detect_from_os(fallback_to_default=True) runlevel = RunLevel.detect_from_os(fallback_to_default=True) config = nest_config.generate_config(project_env, runlevel) print('make flask app: ' + str(project_env) + ' ' + str(runlevel)) app = create_app(config, project_env, runlevel) return app
def test_dev_config(): run_level = RunLevel.development_instance() project_env = ProjectEnv.knoweng_instance() config = nest_config.generate_config(project_env, run_level) app = create_app(config, project_env, run_level) if app is None: assert False, "create_app returned None" assert app.config['ENV'] == 'dev' assert app.config['DEBUG'] is True return
def test_production_config(): run_level = RunLevel.production_instance() project_env = ProjectEnv.knoweng_instance() config = nest_config.generate_config(project_env, run_level) app = create_app(config, project_env, run_level) if app is None: assert False, "create_app returned None" assert app.config['ENV'] == 'prod' assert app.config['DEBUG'] is False assert app.config['DEBUG_TB_ENABLED'] is False return
def test_all_config_combos(): """ just making sure they can all be generated """ all_project_names = nest_envs.VALID_PROJECT_NAMES all_run_levels = nest_envs.VALID_RUNLEVEL_NAMES for project_name in all_project_names: project_env = ProjectEnv(project_name) for run_level in all_run_levels: run_env = RunLevel(run_level) config = nest_config.generate_config(project_env, run_env) return
def app(): from nest_py.core.flask.app2 import create_app run_level = RunLevel.development_instance() project_env = ProjectEnv.knoweng_instance() config = nest_config.generate_config(run_level, project_env) #force localhost as the db server host = NestSite.localhost_instance().get_server_ip_address() config['host'] = host _app = create_app(config, project_env, run_level) ctx = _app.test_request_context() ctx.push() yield _app ctx.pop()