def db_connector(configuration_file, collection_config_key="mongo_encode_stats_collection"): """Connects to MongoDB instance Parameters ---------- configuration_file: string Path to configuration file collection_config_key: string Key used in config file for collection name under [mongo] section Returns ------- collection: mongodb collection """ config = ConfigurationParser(configuration_file) mongo_config = config.get_section("mongo") mongo_client = MongoClient( "mongodb://{}:{}@{}/{}".format( mongo_config["mongo_username"], mongo_config["mongo_password"], mongo_config["mongo_host"], mongo_config["mongo_dbname"], ), port=int(mongo_config["mongo_port"]), ) db = mongo_client.moca_encode_tf collection = db[mongo_config["mongo_encode_stats_collection"]] return collection
def init_params(configuration_file): config = ConfigurationParser(configuration_file) server_config = config.get_section('server') server_config = dict( (key.upper(), value) for key, value in list(server_config.items())) for key, value in list(server_config.items()): try: # For integer app.config[key] = int(value) except ValueError: app.config[key] = value
class TestConfigParser(unittest.TestCase): """Test configurationparser""" def setUp(self): self.config_file = 'tests/data/application.cfg' self.parsed_config = ConfigurationParser(self.config_file) def test_sections(self): """Test configuration sections""" sections = self.parsed_config.get_all_sections() assert 'binaries' in sections def test_get_section(self): """Test configuration sections""" section_dict = self.parsed_config.get_section('mongo') assert 'mongo_host' in section_dict.keys() def test_genomes(self): """Test configuration genomes""" genomes = self.parsed_config.get_all_genomes() assert 'hg19' in genomes
def setUp(self): self.config_file = 'tests/data/application.cfg' self.parsed_config = ConfigurationParser(self.config_file)