def app(real_database_name, real_variant_database, user_obj, loqusdburl): """A test app containing the endpoints of the real app""" app = create_app(config=dict( TESTING=True, DEBUG=True, MONGO_DBNAME=real_database_name, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True, WTF_CSRF_ENABLED=False, MME_URL="test_matchmaker.com", MME_ACCEPTS="application/vnd.ga4gh.matchmaker.v1.0+json", MME_TOKEN=str(uuid.uuid4()), BEACON_URL="http://*****:*****@app.route("/auto_login") def auto_login(): user_inst = LoginUser(user_obj) assert login_user(user_inst, remember=True) return "ok" return app
def test_variant_rank_scores(case_obj, variant_obj): """Test the function that retrieves variant rank scores and info regrding the rank score model applied""" # GIVEN a case with SNV variants with rank score model assert case_obj["rank_model_version"] # GIVEN a snv variant assert variant_obj["category"] == "snv" # GIVEN that the variant has rank scores: variant_obj["rank_score_results"] = [ {"category": "Splicing", "score": 0}, {"category": "Inheritance_Models", "score": -12}, {"category": "Consequence", "score": 1}, ] # GIVEN a test app containing config params to retrieve a genetic model test_app = create_app( config=dict( TESTING=True, DEBUG=True, MONGO_DBNAME="TEST_DB", DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True, RANK_MODEL_LINK_PREFIX="https://raw.githubusercontent.com/Clinical-Genomics/reference-files/master/rare-disease/rank_model/rank_model_-v", RANK_MODEL_LINK_POSTFIX="-.ini", ) ) with test_app.app_context(): # THEN the rank score results of the variant should be returned by the function rank_score_results = variant_rank_scores(store, case_obj, variant_obj) assert isinstance(rank_score_results, list) # WITH the relative model ranges values assert rank_score_results[0]["model_ranges"]
def get_app(ctx): """Create an app with the correct config or with default app params""" # store provided params into a options variable options = ctx.find_root() cli_config = {} # if a .yaml config file was provided use its params to intiate the app if options.params.get("config"): with open(options.params["config"], 'r') as in_handle: cli_config = yaml.load(in_handle, Loader=yaml.FullLoader) if options.params.get("demo"): cli_config['demo'] = 'scout-demo' app = create_app(config=dict( MONGO_DBNAME=cli_config.get('demo') or options.params.get("mongodb") or cli_config.get('mongodb') or 'scout', MONGO_HOST=options.params.get("host") or cli_config.get('host') or 'localhost', MONGO_PORT=options.params.get("port") or cli_config.get('port') or 27017, MONGO_USERNAME=options.params.get("username") or cli_config.get('username'), MONGO_PASSWORD=options.params.get("password") or cli_config.get('password'), OMIM_API_KEY=cli_config.get('omim_api_key'), )) return app
def serve(context, config, host, port, debug, livereload): """Start the web server.""" pymongo_config = dict( MONGO_HOST=context.obj['host'], MONGO_PORT=context.obj['port'], MONGO_DBNAME=context.obj['mongodb'], MONGO_USERNAME=context.obj['username'], MONGO_PASSWORD=context.obj['password'], ) valid_connection = check_connection( host=pymongo_config['MONGO_HOST'], port=pymongo_config['MONGO_PORT'], username=pymongo_config['MONGO_USERNAME'], password=pymongo_config['MONGO_PASSWORD'], authdb=context.obj['authdb'], ) log.info("Test if mongod is running") if not valid_connection: log.warning("Connection could not be established") log.info("Is mongod running?") context.abort() config = os.path.abspath(config) if config else None app = create_app(config=pymongo_config, config_file=config) if livereload: server = Server(app.wsgi_app) server.serve(host=host, port=port, debug=debug) else: app.run(host=host, port=port, debug=debug)
def serve(context, config, host, port, debug, livereload): """Start the web server.""" pymongo_config = dict( MONGO_HOST=context.obj['host'], MONGO_PORT=context.obj['port'], MONGO_DBNAME=context.obj['mongodb'], MONGO_USERNAME=context.obj['username'], MONGO_PASSWORD=context.obj['password'], ) valid_connection = check_connection( host=pymongo_config['MONGO_HOST'], port=pymongo_config['MONGO_PORT'], username=pymongo_config['MONGO_USERNAME'], password=pymongo_config['MONGO_PASSWORD'], ) log.info("Test if mongod is running") if not valid_connection: log.warning("Connection could not be established") log.info("Is mongod running?") context.abort() config = os.path.abspath(config) if config else None app = create_app(config=pymongo_config, config_file=config) if livereload: server = Server(app.wsgi_app) server.serve(host=host, port=port, debug=debug) else: app.run(host=host, port=port, debug=debug)
def app(database_name, real_database): app = create_app(config=dict(TESTING=True, DEBUG=True, MONGO_DBNAME=database_name, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True)) return app
def empty_mock_app(real_adapter): _mock_app = create_app(config=dict(TESTING=True, DEBUG=True, MONGO_DBNAME=REAL_DATABASE, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True)) return _mock_app
def mock_app(real_populated_database): mock_app = create_app(config=dict(TESTING=True, DEBUG=True, MONGO_DBNAME=REAL_DATABASE, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True)) return mock_app
def test_align_handler_public_tracks(igv_test_tracks): """Test The class creating cloud tracks with public tracks""" # GIVEN app config settings with a custom cloud public track config = dict(CLOUD_IGV_TRACKS=igv_test_tracks) # THEN the initialized app should create a cloud_tracks extension app = create_app(config=config) # Contanining the public track assert cloud_tracks.public_tracks["37"][0]["name"] == "Test public track"
def _mock_an_app(): _mock_app = create_app(config=dict( TESTING=True, DEBUG=True, MONGO_DBNAME=REAL_DATABASE, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True, )) return _mock_app
def loqus_api_app(): """Return an app connected to LoqusDB via REST API""" app = create_app( config=dict( TESTING=True, LOQUSDB_SETTINGS={"api_url": "url/to/loqus/api"}, ) ) return app
def empty_mock_app(real_adapter): """Return the path to a mocked app object without any data""" _mock_app = create_app(config=dict( TESTING=True, DEBUG=True, MONGO_DBNAME=REAL_DATABASE, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True, )) return _mock_app
def mock_app(real_populated_database): """Return the path to a mocked app object with data""" _mock_app = create_app(config=dict( TESTING=True, DEBUG=True, MONGO_DBNAME=REAL_DATABASE, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True, )) return _mock_app
def rerunner_app(user_obj): _mock_app = create_app(config=dict( TESTING=True, LOGIN_DISABLED=True, SERVER_NAME="test", RERUNNER_API_ENTRYPOINT="http://rerunner:5001/v1.0/rerun", RERUNNER_API_KEY="test_key", REMEMBER_COOKIE_NAME="remember_me", SESSION_TIMEOUT_MINUTES=10, )) return _mock_app
def loqus_exe_app(loqus_exe, loqus_config): """Return an app connected to LoqusDB via Loqus executable""" app = create_app( config=dict( TESTING=True, LOQUSDB_SETTINGS={ "binary_path": loqus_exe, "config_path": loqus_config, }, ) ) return app
def test_beacon_create_app(): """Test initiating the Beacon extensions when app config file contains right params""" # GIVEN an app initialized with BEACON_URL and BEACON_TOKEN params test_app = create_app(config=dict( TESTING=True, BEACON_TOKEN=str(uuid.uuid4()), BEACON_URL=BEACON_BASE_URL, )) # THEN it should contain the expected Beacon extension class attributes: with test_app.app_context(): assert beacon.add_variants_url assert beacon.delete_variants_url assert beacon.token
def test_init_app_loqus_list(monkeypatch, loqus_exe, loqus_config): """Test creating a Loqus extension from a list of config params""" # GIVEN a mocked loqus exe instance returning a supported loqus version def mockcommand(*args): return "2.5" monkeypatch.setattr(loqus_extension, "execute_command", mockcommand) # The app shold be created by providing LoqusDB params as a list app = create_app(config=dict( LOQUSDB_SETTINGS=[{ "binary_path": loqus_exe, "loqusdb_config": loqus_config }])) assert app
def serve(context, config, host, port, debug, livereload): """Start the web server.""" pymongo_config = dict( MONGO_HOST=context.obj['host'], MONGO_PORT=context.obj['port'], MONGO_DBNAME=context.obj['mongodb'], MONGO_USERNAME=context.obj['username'], MONGO_PASSWORD=context.obj['password'], ) config = os.path.abspath(config) if config else None app = create_app(config=pymongo_config, config_file=config) if livereload: server = Server(app.wsgi_app) server.serve(host=host, port=port, debug=debug) else: app.run(host=host, port=port, debug=debug)
def app(real_database_name, real_variant_database, user_obj): app = create_app(config=dict(TESTING=True, DEBUG=True, MONGO_DBNAME=real_database_name, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True)) @app.route('/auto_login') def auto_login(): log.debug('Got request for auto login for {}'.format(user_obj)) user_inst = LoginUser(user_obj) assert login_user(user_inst, remember=True) return "ok" return app
def minimal_app(real_database_name, real_populated_database, user_obj): "An app without data" app = create_app(config=dict( TESTING=True, DEBUG=True, MONGO_DBNAME=real_database_name, DEBUG_TB_ENABLED=False, LOGIN_DISABLED=True, )) @app.route("/auto_login") def auto_login(): log.debug("Got request for auto login for {}".format(user_obj)) user_inst = LoginUser(user_obj) assert login_user(user_inst, remember=True) return "ok" return app
def get_app(ctx=None): """Create an app with the correct config or with default app params""" loglevel() # Set up log level even before creating the app object # store provided params into a options variable options = ctx.find_root() cli_config = {} # if a .yaml config file was provided use its params to intiate the app if options.params.get("config"): LOG.warning( "Support for launching Scout using a .yaml config file is deprecated and will be removed in the next major release (5.0). Use a PYTHON (.py) config file instead.", ) with open(options.params["config"], "r") as in_handle: cli_config = yaml.load(in_handle, Loader=yaml.SafeLoader) flask_conf = None if options.params.get("flask_config"): flask_conf = pathlib.Path(options.params["flask_config"]).absolute() if options.params.get("demo"): cli_config["demo"] = "scout-demo" try: app = create_app( config=dict( MONGO_DBNAME=options.params.get("mongodb") or cli_config.get("demo") or cli_config.get("mongodb") or "scout", MONGO_HOST=options.params.get("host") or cli_config.get("host"), MONGO_PORT=options.params.get("port") or cli_config.get("port"), MONGO_USERNAME=options.params.get("username") or cli_config.get("username"), MONGO_PASSWORD=options.params.get("password") or cli_config.get("password"), MONGO_URI=options.params.get("mongo_uri") or cli_config.get("mongo_uri"), OMIM_API_KEY=cli_config.get("omim_api_key"), ), config_file=flask_conf, ) except SyntaxError as err: LOG.error(err) raise click.Abort return app
def ldap_app(request): """app ficture for testing LDAP connections.""" config = { "TESTING": True, "DEBUG": True, "SERVER_NAME": "fakey.server.name", "LDAP_HOST": "ldap://test_ldap_server", "WTF_CSRF_ENABLED": False, "MONGO_DBNAME": "testdb", } app = create_app(config=config) ctx = app.app_context() ctx.push() def teardown(): ctx.pop() request.addfinalizer(teardown) return app
def get_app(ctx): """Create an app with the correct config or with default app params""" # store provided params into a options variable options = ctx.find_root() cli_config = {} # if a .yaml config file was provided use its params to intiate the app if options.params.get("config"): with open(options.params["config"], "r") as in_handle: cli_config = yaml.load(in_handle, Loader=yaml.FullLoader) flask_conf = None if options.params.get("flask_config"): flask_conf = pathlib.Path(options.params["flask_config"]).absolute() if options.params.get("demo"): cli_config["demo"] = "scout-demo" try: app = create_app( config=dict( MONGO_DBNAME=cli_config.get("demo") or options.params.get("mongodb") or cli_config.get("mongodb") or "scout", MONGO_HOST=options.params.get("host") or cli_config.get("host") or "localhost", MONGO_PORT=options.params.get("port") or cli_config.get("port") or 27017, MONGO_USERNAME=options.params.get("username") or cli_config.get("username"), MONGO_PASSWORD=options.params.get("password") or cli_config.get("password"), OMIM_API_KEY=cli_config.get("omim_api_key"), ), config_file=flask_conf, ) except SyntaxError as err: LOG.error(err) raise click.Abort return app
def test_matchmaker_config_settings(mocker): """Test that the app is initialized with the correct MatchMaker Exchange settings""" # WHEN the app is initialized, it should contain the default MME parameters # GIVEN a patched MatchMaker server returning a list of connected nodes: nodes = [ { "description": "Node 1", "id": "node1" }, { "description": "Node 2", "id": "node2" }, ] mocker.patch( "scout.utils.scout_requests.get_request_json", return_value={ "status_code": 200, "content": nodes }, ) # WHEN app is created test_app = create_app(config=dict( TESTING=True, MME_URL="test_matchmaker.com", MME_ACCEPTS="application/vnd.ga4gh.matchmaker.v1.0+json", MME_TOKEN=str(uuid.uuid4()), )) # THEN it should contain the expected matchmaker class attributes: with test_app.app_context(): assert matchmaker.host assert matchmaker.accept assert matchmaker.token assert matchmaker.connected_nodes == nodes
#!/usr/bin/env python # -*- coding: utf-8 -*- import os from werkzeug.contrib.fixers import ProxyFix from scout.server.app import create_app app = create_app(config_file=os.environ['SCOUT_CONFIG']) app.wsgi_app = ProxyFix(app.wsgi_app) if __name__ == '__main__': app.run(host='0.0.0.0')
def gens_app(): """Return an app containing the Gens extension""" app = create_app(config=dict(TESTING=True, GENS_HOST="127.0.0.1", GENS_PORT=5000)) return app