From 2b818a72d12e8916a1f7557e6462742156c3d126 Mon Sep 17 00:00:00 2001 From: Michal Hecko Date: Wed, 16 Oct 2024 17:38:36 +0200 Subject: [PATCH] testutils: add support for configs Extend the CurrentActorMocked class to accept a `config` value, allowing developers to mock actors that rely on configuration. A library function `_make_default_config` is also introduced, allowing to instantiate default configs from config schemas. --- repos/system_upgrade/common/libraries/testutils.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/repos/system_upgrade/common/libraries/testutils.py b/repos/system_upgrade/common/libraries/testutils.py index c538af1a13..afeb360a64 100644 --- a/repos/system_upgrade/common/libraries/testutils.py +++ b/repos/system_upgrade/common/libraries/testutils.py @@ -4,6 +4,7 @@ from collections import namedtuple from leapp import reporting +from leapp.actors.config import _normalize_config, normalize_schemas from leapp.libraries.common.config import architecture from leapp.models import EnvVar from leapp.utils.deprecation import deprecated @@ -67,9 +68,15 @@ def __call__(self): return self +def _make_default_config(actor_config_schema): + """ Make a config dict populated with default values. """ + merged_schema = normalize_schemas((actor_config_schema, )) + return _normalize_config({}, merged_schema) # Will fill default values during normalization + + class CurrentActorMocked(object): # pylint:disable=R0904 def __init__(self, arch=architecture.ARCH_X86_64, envars=None, kernel='3.10.0-957.43.1.el7.x86_64', - release_id='rhel', src_ver='7.8', dst_ver='8.1', msgs=None, flavour='default'): + release_id='rhel', src_ver='7.8', dst_ver='8.1', msgs=None, flavour='default', config=None): envarsList = [EnvVar(name=k, value=v) for k, v in envars.items()] if envars else [] version = namedtuple('Version', ['source', 'target'])(src_ver, dst_ver) release = namedtuple('OS_release', ['release_id', 'version_id'])(release_id, src_ver) @@ -82,6 +89,7 @@ def __init__(self, arch=architecture.ARCH_X86_64, envars=None, kernel='3.10.0-95 'configuration', ['architecture', 'kernel', 'leapp_env_vars', 'os_release', 'version', 'flavour'] )(arch, kernel, envarsList, release, version, flavour) self._msgs = msgs or [] + self.config = {} if config is None else config def __call__(self): return self