示例#1
0
def get_config(is_child=False):
    global CONFIG

    if is_child:
        config_file = 'child-config.json'
    else:
        config_file = 'config.json'

    if CONFIG is None:
        # Required for handling the different starting points for the unit tests
        cwd = os.getcwd()
        path = ""

        if cwd.endswith("/helper") or cwd.endswith("/plugins") or cwd.endswith(
                "/plugins"):
            path = "../../configs/"
        elif cwd.endswith("/remote_plugins") or cwd.endswith("/local_plugins"):
            path = "../configs/"
        elif cwd.endswith("/integration"):
            path = "configs/"

        try:
            with open(path + config_file) as config_file:
                file_config = json.load(config_file)
        except Exception:
            file_config = {}

        CONFIG = load_config(**file_config)

    return CONFIG
示例#2
0
    def test_load_config_cli_custom_argument_parser_vars(self):
        parser = brewtils.get_argument_parser()
        parser.add_argument("some_parameter")

        cli_args = ["param", "--bg-host", "the_host"]
        parsed_args = parser.parse_args(cli_args)

        config = brewtils.load_config(**vars(parsed_args))
        assert config.bg_host == "the_host"
        assert parsed_args.some_parameter == "param"
        assert "some_parameter" not in config
示例#3
0
    def test_load_config_cli_custom_argument_parser_vars(self):
        parser = brewtils.get_argument_parser()
        parser.add_argument('some_parameter')

        cli_args = ['param', '--bg-host', 'the_host']
        parsed_args = parser.parse_args(cli_args)

        config = brewtils.load_config(**vars(parsed_args))
        assert config.bg_host == 'the_host'
        assert parsed_args.some_parameter == 'param'
        assert 'some_parameter' not in config
示例#4
0
def get_config():
    global CONFIG

    if CONFIG is None:
        try:
            with open('config.json') as config_file:
                file_config = json.load(config_file)
        except Exception:
            file_config = {}

        CONFIG = load_config(**file_config)

    return CONFIG
示例#5
0
    def test_load_config_environment(self):
        os.environ["BG_HOST"] = "the_host"

        config = brewtils.load_config([])
        assert config.bg_host == "the_host"
示例#6
0
    def test_load_config_cli(self):
        cli_args = ["--bg-host", "the_host"]

        config = brewtils.load_config(cli_args)
        assert config.bg_host == "the_host"
示例#7
0
    def test_load_config_environment(self):
        os.environ['BG_HOST'] = 'the_host'

        config = brewtils.load_config([])
        assert config.bg_host == 'the_host'
示例#8
0
    def test_load_config_cli(self):
        cli_args = ['--bg-host', 'the_host']

        config = brewtils.load_config(cli_args)
        assert config.bg_host == 'the_host'