Ejemplo n.º 1
0
    def load_email_configuration():
        """
            Loads the variables from the
            email.yaml file
        """

        Utility.email_conf = ConfigLoader(os.getenv("EMAIL_CONF", "./email.yaml")).get_config()
Ejemplo n.º 2
0
 def get_db_url():
     """
     Fetches MongoDB URL defined in system.yaml file
     :return: MongoDB connection URL
     """
     environment = ConfigLoader(os.getenv("system_file", "./system.yaml")).get_config()
     return environment['database']["url"]
Ejemplo n.º 3
0
 def connect_db():
     """
     Creates connection to database.
     :return: MongoDB connection URL
     """
     system_yml_parent_dir = str(Path(os.path.realpath(__file__)).parent)
     environment = ConfigLoader(os.getenv("system_file", system_yml_parent_dir + "/system.yaml")).get_config()
     connect(host=environment['database']["url"])
Ejemplo n.º 4
0
    def load_evironment():
        """
        Loads the environment variables and their values from the
        system.yaml file for defining the working environment of the app

        :return: None
        """
        Utility.environment = ConfigLoader(os.getenv("system_file", "./system.yaml")).get_config()
Ejemplo n.º 5
0
 def get_db_url():
     """
     Fetches MongoDB URL defined in system.yaml file
     :return: MongoDB connection URL
     """
     system_yml_parent_dir = str(Path(os.path.realpath(__file__)).parent)
     environment = ConfigLoader(os.getenv("system_file", system_yml_parent_dir + "/system.yaml")).get_config()
     return environment['database']["url"]
Ejemplo n.º 6
0
 def test_load_configuration_no_env_toml(self):
     data = ConfigLoader("./tests/data/sample.toml").get_config()
     assert data['system'] == 'testing'
     assert data['testing']['demo'] == 'default'
     assert data['plain'] == "value"
     assert data['boolean']
     assert data['integer'] == 1
     assert data['float'] == 1.0
Ejemplo n.º 7
0
 def test_load_configuration_invalid_value_toml(self):
     old_data = toml_load(open('./tests/data/sample.toml'))
     sample = {'system': "${SYSTEM:testing"}
     toml_dump(sample, open('./tests/data/sample.toml', mode='w+'))
     with pytest.raises(Exception):
         ConfigLoader("./tests/data/sample.toml")
     toml_dump(old_data, open('./tests/data/sample.toml', mode='w+'))
     data = ConfigLoader("./tests/data/sample.toml").get_config()
     assert data['system'] == 'testing'
     assert data['testing']['demo'] == 'default'
     assert data['plain'] == "value"
     assert data['integer'] == 1
     assert data['float'] == 1.0
     sample = {'system': "SYSTEM:testing}"}
     toml_dump(sample, open('./tests/data/sample.toml', mode='w+'))
     with pytest.raises(Exception):
         ConfigLoader("./tests/data/sample.toml")
     toml_dump(old_data, open('./tests/data/sample.toml', mode='w+'))
Ejemplo n.º 8
0
 def test_load_configuration_invalid_value_cfg(self):
     config_parser = ConfigParser()
     config_parser.read_file((open('./tests/data/sample.cfg')))
     config_parser.set('default', 'system', '${SYSTEM:testing')
     config_parser.write(open('./tests/data/sample.cfg', mode='w+'))
     with pytest.raises(Exception):
         ConfigLoader("./tests/data/sample.cfg")
     config_parser.set('default', 'system', '${SYSTEM:testing}')
     config_parser.write(open('./tests/data/sample.cfg', mode='w+'))
     data = ConfigLoader("./tests/data/sample.cfg").get_config()
     assert data['default']['system'] == 'testing'
     assert data['testing']['demo'] == 'default'
     assert data['default']['plain'] == "value"
     assert data['default']['integer'] == 1
     assert data['default']['float'] == 1.0
     config_parser.set('default', 'system', 'SYSTEM:testing}')
     config_parser.write(open('./tests/data/sample.cfg', mode='w+'))
     with pytest.raises(Exception):
         ConfigLoader("./tests/data/sample.cfg")
     config_parser.set('default', 'system', '${SYSTEM:testing}')
     config_parser.write(open('./tests/data/sample.cfg', mode='w+'))
Ejemplo n.º 9
0
    def on_start(self):
        global USER_INDEX

        os.environ["system_file"] = "./tests/testing_data/system.yaml"
        env = ConfigLoader(os.getenv("system_file",
                                     "./system.yaml")).get_config()
        self.email = 'user{0}@demo.ai'.format(USER_INDEX)
        self.username = self.email
        self.first_name = 'load'
        self.last_name = 'test'
        self.password = env['security']['test_user_password']
        self.account = 'user{0}'.format(USER_INDEX)
        self.bot = 'user{0}'.format(USER_INDEX)
        USER_INDEX += 1
Ejemplo n.º 10
0
 def on_stop(self):
     logging.info("Cleaning up database..")
     try:
         os.environ["system_file"] = "./tests/testing_data/system.yaml"
         env = ConfigLoader(os.getenv("system_file",
                                      "./system.yaml")).get_config()
         logging.info("Connecting to: " + env['database']["stress_test"])
         connect(host=env['database']["stress_test"])
         User.objects(email=self.username).delete()
         Bot.objects(name=self.bot).delete()
         Account.objects(name=self.account).delete()
         logging.info("Cleanup complete")
         disconnect()
     except Exception as e:
         logging.error(e)
Ejemplo n.º 11
0
 def test_load_configuration_env_toml(self):
     os.environ['SYSTEM'] = "env_value"
     os.environ['ENVIRONMENT_VARIABLE'] = "value"
     os.environ['INT_VALUE'] = "2"
     os.environ['FLOAT_VALUE'] = "2.0"
     os.environ['BOOLEAN_VALUE'] = "False"
     data = ConfigLoader("./tests/data/sample.toml").get_config()
     assert data['system'] == 'env_value'
     assert data['testing']['demo'] == 'value'
     assert data['plain'] == "value"
     assert not data['boolean']
     assert data['integer'] == 2
     assert data['float'] == 2.0
     del os.environ['SYSTEM']
     del os.environ['ENVIRONMENT_VARIABLE']
     del os.environ['INT_VALUE']
     del os.environ['BOOLEAN_VALUE']
     del os.environ['FLOAT_VALUE']
Ejemplo n.º 12
0
def main():
    parser = create_arg_parser()
    arguments = parser.parse_args()
    config = ConfigLoader('./system.yaml').get_config()
    connect(host=config['database']['url'])
    start_training(arguments.bot, arguments.user, reload=False)
Ejemplo n.º 13
0
 def test_load_configuration_yaml_invalid(self):
     with pytest.raises(Exception):
         ConfigLoader("demo.txt")