def cli(ctx, mongodb, username, password, host, port, logfile, loglevel, config): """Manage Scout interactions.""" init_log(logger, logfile, loglevel) mongo_configs = {} configs = {} if config: logger.info("Use config file {0}".format(config)) configs = ConfigObj(config) if mongodb: mongo_configs['mongodb'] = mongodb else: mongo_configs['mongodb'] = configs.get('mongodb', 'variantDatabase') logger.info("Setting mongodb to {0}".format(mongo_configs['mongodb'])) if host: mongo_configs['host'] = host else: mongo_configs['host'] = configs.get('host', 'localhost') logger.info("Setting host to {0}".format(mongo_configs['host'])) if port: mongo_configs['port'] = port else: mongo_configs['port'] = int(configs.get('port', 27017)) logger.info("Setting port to {0}".format(mongo_configs['port'])) if username: mongo_configs['username'] = username else: mongo_configs['username'] = configs.get('username') if password: mongo_configs['password'] = password else: mongo_configs['password'] = configs.get('password') logger.info("Setting up a mongo adapter") mongo_adapter = MongoAdapter() logger.info("Connecting to database") mongo_adapter.connect_to_database( database=mongo_configs['mongodb'], host=mongo_configs['host'], port=mongo_configs['port'], username=mongo_configs['username'], password=mongo_configs['password'] ) mongo_configs['adapter'] = mongo_adapter ctx.obj = mongo_configs
# We will use mongomock when mongoengine allows it # from mongomock import MongoClient from pymongo import MongoClient from mongoengine import DoesNotExist from configobj import ConfigObj from vcf_parser import VCFParser from scout.ext.backend import MongoAdapter from scout.models import (Variant, Case, Event, Institute, PhenotypeTerm, Institute, User) from scout.commands import cli from scout.log import init_log root_logger = logging.getLogger() init_log(root_logger, loglevel='INFO') logger = logging.getLogger(__name__) vcf_file = "tests/fixtures/337334.clinical.vcf" one_variant = "tests/fixtures/337334.one_variant.clinical.vcf" ped_file = "tests/fixtures/337334.ped" scout_config = "tests/fixtures/scout_config_test.ini" gene_list_file = "tests/fixtures/gene_lists/gene_list_test.txt" madeline_file = "tests/fixtures/madeline.xml" @pytest.fixture(scope='function') def variant_file(request): """Get the path to a variant file""" print('') return vcf_file
research_sv_path, clinical_snv_path, clinical_sv_path, ped_path, load_path, panel_path, empty_sv_clinical_path, ) from scout.models.hgnc_map import HgncGene DATABASE = 'testdb' REAL_DATABASE = 'realtestdb' root_logger = logging.getLogger() init_log(root_logger, loglevel='INFO') LOG = logging.getLogger(__name__) ############################################################# ###################### App fixtures ######################### ############################################################# # use this app object to test CLI commands which use a test database @pytest.fixture def mock_app(real_populated_database): mock_app = create_app(config=dict(TESTING=True, DEBUG=True, MONGO_DBNAME=REAL_DATABASE, DEBUG_TB_ENABLED=False,
@click.option("-v", "--verbose", is_flag=True, help="Increase output verbosity.") def delete_case(case_id, owner, mongo_db, username, password, port, host, verbose): """ Delete a case and all of its variants from the mongo database. """ logger = logging.getLogger("scout.commands.delete_case") logger.info("Running delete_case") if not mongo_db: logger.warning("Please specify a database to wipe and populate" " with flag '-db/--mongo-db'.") sys.exit(0) if not case_id: logger.warning("Please specify the id of the case that should be deleted" " with flag '-c/--case_id'.") sys.exit(0) if not owner: logger.warning("Please specify the owner of the case that should be deleted" " with flag '-o/--owner'.") sys.exit(0) remove_case(case_id, owner, mongo_db, username, password, port, host, logger) if __name__ == "__main__": from scout.log import init_log logger = logging.getLogger("scout") init_log(logger, loglevel="DEBUG") delete_case()
Delete a case and all of its variants from the mongo database. """ logger = logging.getLogger('scout.commands.delete_case') logger.info("Running delete_case") if not mongo_db: logger.warning("Please specify a database to wipe and populate"\ " with flag '-db/--mongo-db'.") sys.exit(0) if not case_id: logger.warning("Please specify the id of the case that should be deleted"\ " with flag '-c/--case_id'.") sys.exit(0) if not owner: logger.warning("Please specify the owner of the case that should be deleted"\ " with flag '-o/--owner'.") sys.exit(0) remove_case(case_id, owner, mongo_db, username, password, port, host, logger) if __name__ == '__main__': from scout.log import init_log logger = logging.getLogger('scout') init_log(logger, loglevel='DEBUG') delete_case()