def main( ctx: click.Context, config_path: T.Optional[T.Text], host: T.Text, port: int, log_level: T.Text, syslog: bool, log_file: T.Optional[T.Text], graphiql: bool, ): """Console script for kofi.""" shell_config = {} # type: T.Dict[T.Text, T.Any] if host: shell_config["host"] = host if port: shell_config["port"] = port log_conf = { "level": log_level, "syslog": syslog, } if log_file: log_conf["log_file"] = log_file if log_level or syslog or log_file: shell_config["log"] = log_conf if graphiql: shell_config["graphiql"] = True config = read_config(config_path) def_config = merge_configs(config, shell_config) if log_level and log_level.upper() == "DEBUG": click.echo("Resulting conf:\n{}".format(pformat(def_config))) run_from_shell(def_config)
def test_port_validation(port: int, tmpdir: py.path.local) -> None: """Test the conf validation""" conf_path = fill_mock_conf({"port": port}, tmpdir) with pytest.raises(ValueError) as e: with mock.patch("kofi.config._find_conf", return_value=str(conf_path)): conf = read_config() assert "is invalid in configuration" in str(e.value) assert str(port) in str(e.value)
def test_log_validation(log_conf: T.Dict[T.Text, T.Any], msg: T.Text, tmpdir: py.path.local) -> None: """Test the conf validation""" conf_path = fill_mock_conf({"log": log_conf}, tmpdir) with pytest.raises(ValueError) as e: with mock.patch("kofi.config._find_conf", return_value=str(conf_path)): conf = read_config() assert "is invalid in configuration" in str(e.value) assert msg in str(e.value)
def test_override_conf( conf_data: T.Dict[T.Text, T.Any], result: T.Dict[T.Text, T.Any], tmpdir: py.path.local, ) -> None: """Test the overrided conf.""" conf_path = fill_mock_conf(conf_data, tmpdir) with mock.patch("kofi.config._find_conf", return_value=str(conf_path)): conf = read_config() assert conf == result
def run() -> None: """KoFi entrypoint.""" config = read_config() app = setup(config) start(app)