Skip to content

Commit

Permalink
testutils: add support for configs
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Michal Hecko authored and pirat89 committed Nov 13, 2024
1 parent f025759 commit 2b818a7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion repos/system_upgrade/common/libraries/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 2b818a7

Please sign in to comment.