Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion leapp/dialogs/dialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def serialize(self):

@property
def answerfile_sections(self):
return {"{}.{}".format(self.scope, c.key): c.choices for c in self.components}
return {"{}.{}".format(self.scope, c.key): getattr(c, "choices", []) for c in self.components}

@property
def min_label_width(self):
Expand Down
31 changes: 31 additions & 0 deletions tests/data/actor-api-tests/actors/first/actor.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from leapp.actors import Actor
from leapp.dialogs import Dialog
from leapp.dialogs.components import BooleanComponent, ChoiceComponent, NumberComponent, TextComponent
from leapp.tags import ActorFileApiTag
from leapp.models import ApiTestConsume, ApiTestProduce

Expand All @@ -9,6 +11,35 @@ class First(Actor):
consumes = (ApiTestConsume,)
produces = (ApiTestProduce,)
tags = (ActorFileApiTag,)
dialogs = (
Dialog(
scope='first_actor',
reason='need to test dialogs',
components=(
TextComponent(
key='text',
label='text',
description='a text value is needed',
),
BooleanComponent(
key='bool',
label='bool',
description='a boolean value is needed'
),
NumberComponent(
key='num',
label='num',
description='a numeric value is needed'
),
ChoiceComponent(
key='choice',
label='choice',
description='need to choose one of these choices',
choices=('One', 'Two', 'Three', 'Four', 'Five'),
),
),
),
)

def process(self):
pass
27 changes: 27 additions & 0 deletions tests/scripts/test_actor_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import pytest

from leapp.actors import Actor, get_actors
from leapp.config import get_config
from leapp.libraries.stdlib import api
from leapp.messaging import BaseMessaging
from leapp.models import ApiTestConsume, ApiTestProduce
Expand Down Expand Up @@ -168,3 +169,29 @@ def test_actor_all_files_paths(leapp_forked, repository, actor_name): # noqa; p

assert not actor.get_actor_file_path('directory/repository')
assert not api.get_actor_file_path('directory/repository')


@pytest.fixture(scope="module")
def setup_database():
get_config().set('database', 'path', '/tmp/leapp-test.db')


@pytest.mark.parametrize("actor_name", ('first',))
def test_actor_get_answers(monkeypatch, leapp_forked, setup_database, repository, actor_name): # noqa; pylint: disable=unused-argument
user_responses = {
'text': ('expected_value', 'expected_value'),
'bool': ('Yes', True),
'num': (42, 42),
'choice': ("3", "Four"),
}

def mocked_input(title):
return user_responses[title.split()[0].split(':')[0].lower()][0]

monkeypatch.setattr('leapp.dialogs.renderer.input', mocked_input)

messaging = _TestableMessaging()
with _with_loaded_actor(repository, actor_name, messaging) as (_unused, actor):
answers = actor.get_answers(actor.dialogs[0])
for component in actor.dialogs[0].components:
assert answers.get(component.key) == user_responses[component.key][1]