Skip to content

Commit

Permalink
fix: add check for set facts reporting
Browse files Browse the repository at this point in the history
Signed-off-by: Joe Shimkus <[email protected]>
  • Loading branch information
jshimkus-rh committed Jan 3, 2024
1 parent f0ebb4a commit 940f149
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 6 deletions.
12 changes: 10 additions & 2 deletions tests/unit/action/test_run_job_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import pytest

from ansible_rulebook import terminal
from ansible_rulebook.action.control import Control
from ansible_rulebook.action.metadata import Metadata
from ansible_rulebook.action.run_job_template import RunJobTemplate
Expand Down Expand Up @@ -119,7 +120,7 @@ async def test_run_job_template_exception(err_msg, err):

@pytest.mark.parametrize("drools_call,additional_args", DROOLS_CALLS)
@pytest.mark.asyncio
async def test_run_job_template(drools_call, additional_args):
async def test_run_job_template(drools_call, additional_args, capsys):
queue = asyncio.Queue()
metadata = Metadata(
rule="r1",
Expand Down Expand Up @@ -156,10 +157,17 @@ async def test_run_job_template(drools_call, additional_args):
return_value=controller_job,
):
with patch(drools_call) as drools_mock:
await RunJobTemplate(metadata, control, **action_args)()
await RunJobTemplate(
metadata,
control,
print_events=True,
**action_args,
)()
captured = capsys.readouterr()
drools_mock.assert_called_once()

_validate(queue, True)
assert terminal.Display.get_banners("job: set-facts", captured.out)


URL_PARAMETERS = [
Expand Down
9 changes: 7 additions & 2 deletions tests/unit/action/test_run_playbook.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import pytest
from freezegun import freeze_time

from ansible_rulebook import terminal
from ansible_rulebook.action.control import Control
from ansible_rulebook.action.metadata import Metadata
from ansible_rulebook.action.run_playbook import RunPlaybook
Expand Down Expand Up @@ -94,7 +95,7 @@ def _validate(queue, metadata, status, rc):
@pytest.mark.asyncio
@freeze_time("2023-06-11 12:13:14")
@pytest.mark.asyncio
async def test_run_playbook(drools_call, additional_args):
async def test_run_playbook(drools_call, additional_args, capsys):
os.chdir(HERE)
queue = asyncio.Queue()
metadata = Metadata(
Expand Down Expand Up @@ -131,12 +132,16 @@ async def test_run_playbook(drools_call, additional_args):

with patch("uuid.uuid4", return_value=DUMMY_UUID):
with patch(drools_call) as drools_mock:
await RunPlaybook(metadata, control, **action_args)()
await RunPlaybook(
metadata, control, print_events=True, **action_args
)()
captured = capsys.readouterr()
drools_mock.assert_called_once_with(
action_args["ruleset"], set_fact_args
)

_validate(queue, metadata, "successful", 0)
assert terminal.Display.get_banners("playbook: set-facts", captured.out)


@freeze_time("2023-06-11 12:13:14")
Expand Down
14 changes: 12 additions & 2 deletions tests/unit/action/test_run_workflow_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import pytest

from ansible_rulebook import terminal
from ansible_rulebook.action.control import Control
from ansible_rulebook.action.metadata import Metadata
from ansible_rulebook.action.run_workflow_template import RunWorkflowTemplate
Expand Down Expand Up @@ -122,7 +123,7 @@ async def test_run_workflow_template_exception(err_msg, err):

@pytest.mark.parametrize("drools_call,additional_args", DROOLS_CALLS)
@pytest.mark.asyncio
async def test_run_workflow_template(drools_call, additional_args):
async def test_run_workflow_template(drools_call, additional_args, capsys):
queue = asyncio.Queue()
metadata = Metadata(
rule="r1",
Expand Down Expand Up @@ -159,10 +160,19 @@ async def test_run_workflow_template(drools_call, additional_args):
return_value=controller_job,
):
with patch(drools_call) as drools_mock:
await RunWorkflowTemplate(metadata, control, **action_args)()
await RunWorkflowTemplate(
metadata,
control,
print_events=True,
**action_args,
)()
captured = capsys.readouterr()
drools_mock.assert_called_once()

_validate(queue, True)
assert terminal.Display.get_banners(
"workflow: set-facts", captured.out
)


@pytest.mark.asyncio
Expand Down

0 comments on commit 940f149

Please sign in to comment.