Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_test_config():
try:
conf = Config.get_user_config()
except PackitException:
conf = Config()
conf.dry_run = True
return conf
def test_base_push_bad(distgit_and_remote):
distgit, _ = distgit_and_remote
b = PackitRepositoryBase(config=Config(), package_config=PackageConfig())
b.local_project = LocalProject(
working_dir=str(distgit), git_url="https://github.com/packit-service/lol"
)
flexmock(
LocalProject,
push=lambda *args, **kwargs: [
PushInfo(PushInfo.REMOTE_REJECTED, None, None, None, None)
],
)
with pytest.raises(PackitException) as e:
b.push("master")
assert "unable to push" in str(e.value)
def get_test_config():
conf = Config()
conf._pagure_user_token = "test"
conf._github_token = "test"
return conf
def get_from_dict(cls, raw_dict: dict, validate=True) -> "Config":
if validate:
cls.validate(raw_dict)
config = Config()
config.debug = raw_dict.get("debug", False)
config.dry_run = raw_dict.get("dry_run", False)
config.fas_user = raw_dict.get("fas_user", None)
config.keytab_path = raw_dict.get("keytab_path", None)
config.webhook_secret = raw_dict.get("webhook_secret", "")
config.command_handler = RunCommandType.local
a_h = raw_dict.get("command_handler")
if a_h:
config.command_handler = RunCommandType(a_h)
config.command_handler_work_dir = raw_dict.get(
"command_handler_work_dir", SANDCASTLE_WORK_DIR
)
config.command_handler_pvc_env_var = raw_dict.get(
directory = Path.home() / ".config"
logger.debug(f"Loading user config from directory: {directory}")
loaded_config: dict = {}
for config_file_name in CONFIG_FILE_NAMES:
config_file_name_full = directory / config_file_name
logger.debug(f"Trying to load user config from: {config_file_name_full}")
if config_file_name_full.is_file():
try:
loaded_config = safe_load(open(config_file_name_full))
except Exception as ex:
logger.error(f"Cannot load user config '{config_file_name_full}'.")
raise PackitException(f"Cannot load user config: {ex}.")
break
return Config.get_from_dict(raw_dict=loaded_config)
def make_instance(self, data, **kwargs):
return Config(**data)