Skip to content

Commit

Permalink
allow to make a local config. shortcut in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
idevat committed Jan 16, 2018
1 parent 4cbf853 commit 8defe1e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
11 changes: 11 additions & 0 deletions pcs/test/tools/command_env/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,17 @@ def __init__(self):

self.spy = None

def add_extension(self, name, Extension):
if hasattr(self, name):
raise AssertionError(
"Config (integration tests) has the extension '{0}' already."
.format(name)
)
setattr(self, name, self.__wrap_helper(
Extension(self.__calls, self.__wrap_helper, self)
))


def set_spy(self, auth_tokens, ports=None):
self.spy = Spy(auth_tokens, ports)
return self
Expand Down
12 changes: 12 additions & 0 deletions pcs/test/tools/command_env/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,17 @@ def get_env_tools(
default_wait_timeout=DEFAULT_WAIT_TIMEOUT,
default_wait_error_returncode=WAIT_TIMEOUT_EXPIRED_RETURNCODE,
exception_reports_in_processor_by_default=True,
local_extensions=None
):
"""
Shortcut for preparing EnvAssistant and Config
TestCase test_case -- corresponding test_case is used to registering cleanup
method - to assert that everything is finished
dict local_extensions -- key is name of local extension, value is class that
will be used for local extension. So in config will be possible use
something like this:
config.my_local_extension.my_local_call_shortcut()
"""

env_assistant = EnvAssistant(
Expand All @@ -38,4 +43,11 @@ def get_env_tools(
runner.pcmk.default_wait_timeout = default_wait_timeout
runner.pcmk.default_wait_error_returncode = default_wait_error_returncode

if local_extensions:
for name, ExtensionClass in local_extensions.items():
env_assistant.config.add_extension(
name,
ExtensionClass,
)

return env_assistant, env_assistant.config

0 comments on commit 8defe1e

Please sign in to comment.