257b6fe19e
- Bump leapp-framework to 4.0 - Improve the report summary output to make it more visible - Fix processing data in remediation instructions with non-ascii characters - Fix creation of Dialog for Component without choices - Store tracebacks from actors in leapp.db - Resolves: #2223312
107 lines
3.8 KiB
Diff
107 lines
3.8 KiB
Diff
From 07ff6eb4c383137f2b5f6730deecf8ffa9e4cd98 Mon Sep 17 00:00:00 2001
|
|
From: Ygal Blum <ygal.blum@gmail.com>
|
|
Date: Thu, 4 May 2023 17:23:03 +0300
|
|
Subject: [PATCH 08/18] Test differnt types of Dialog components
|
|
|
|
Add a multi component dialog to one of the tester actors
|
|
Verify that the input is handled correctly
|
|
|
|
Signed-off-by: Ygal Blum <ygal.blum@gmail.com>
|
|
---
|
|
.../actor-api-tests/actors/first/actor.py | 31 +++++++++++++++++++
|
|
tests/scripts/test_actor_api.py | 27 ++++++++++++++++
|
|
2 files changed, 58 insertions(+)
|
|
|
|
diff --git a/tests/data/actor-api-tests/actors/first/actor.py b/tests/data/actor-api-tests/actors/first/actor.py
|
|
index 27650bd..2b5a6e1 100644
|
|
--- a/tests/data/actor-api-tests/actors/first/actor.py
|
|
+++ b/tests/data/actor-api-tests/actors/first/actor.py
|
|
@@ -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
|
|
|
|
@@ -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
|
|
diff --git a/tests/scripts/test_actor_api.py b/tests/scripts/test_actor_api.py
|
|
index 0a28257..f009e68 100644
|
|
--- a/tests/scripts/test_actor_api.py
|
|
+++ b/tests/scripts/test_actor_api.py
|
|
@@ -7,6 +7,7 @@ import py
|
|
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
|
|
@@ -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]
|
|
--
|
|
2.41.0
|
|
|