Skip to content

Commit d9d6a7a

Browse files
authored
Implement the variable validation logic in the user input node (jsocol#146)
* Implemented get_variable_type on the repository * Fetching variable type in the user input node execution * Added test to check for email validation * Validating email addresses * Raise an error if the reprompt is not needed but not defined * Show the cancel quick reply * Renaming the agent handover failure quick replies logic into a more generic name * Add Cancel QR texts in all languages * Do not show the cancel quick reply if the targeted use case is not published * Upgrade requirements
1 parent 5fd0b66 commit d9d6a7a

29 files changed

+1080
-375
lines changed

requirements-base.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# File generated automatically. Do not update it manually.
22
# Update files in the requirements folder instead.
3-
pip==22.1.1
3+
pip==22.1.2
44
setuptools==62.3.2
55
wheel==0.37.1

tests/adapters/database_repository/test_get_use_case_from_uuid.py

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ def test_get_use_case_from_uuid_returns_none_if_use_case_does_not_exist():
1515

1616

1717
def test_get_use_case_from_uuid_returns_the_proper_use_case_when_it_exists():
18+
UseCaseFactory() # decoy
1819
db_use_case = UseCaseFactory()
1920
assert DatabaseRepository().get_use_case_from_uuid(
2021
use_case_uuid=db_use_case.uuid
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import uuid
2+
3+
import pytest
4+
5+
from tests.factories.variable_factory import VariableFactory
6+
from use_case_executor.adapters.database_repository.database_repository import (
7+
DatabaseRepository,
8+
)
9+
from use_case_executor.domain.errors import VariableNotFound
10+
from use_case_executor.domain.flow_execution.substeps.variable_type import VariableType
11+
12+
13+
def test_get_variable_type_raises_if_variable_does_not_exist():
14+
VariableFactory() # decoy
15+
with pytest.raises(VariableNotFound):
16+
DatabaseRepository().get_variable_type(variable_uuid=uuid.uuid4())
17+
18+
19+
@pytest.mark.parametrize("variable_type", VariableType)
20+
def test_get_variable_type_returns_variable_type(variable_type):
21+
VariableFactory() # decoy
22+
db_variable = VariableFactory(type=variable_type)
23+
assert (
24+
DatabaseRepository().get_variable_type(variable_uuid=db_variable.uuid)
25+
== variable_type
26+
)

tests/api/namespace/use_case/test_clone_use_case.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
)
2727
from use_case_executor.domain.flow.node_data.node_type import NodeType
2828
from use_case_executor.domain.flow.node_data.user_input_data import UserInputData
29-
from use_case_executor.domain.flow_execution.substeps.variable_type import Variabletype
29+
from use_case_executor.domain.flow_execution.substeps.variable_type import VariableType
3030

3131

3232
@pytest.fixture(
@@ -360,10 +360,10 @@ def test_creates_new_variables_if_cloning_to_other_instance( # pylint: disable=
360360
)
361361

362362
variable_1 = VariableFactory(
363-
instance_id=use_case.instance_id, name="variable_1", type=Variabletype.free_text
363+
instance_id=use_case.instance_id, name="variable_1", type=VariableType.free_text
364364
)
365365
variable_2 = VariableFactory(
366-
instance_id=use_case.instance_id, name="variable_2", type=Variabletype.email
366+
instance_id=use_case.instance_id, name="variable_2", type=VariableType.email
367367
)
368368
variable_3 = VariableFactory(instance_id=use_case.instance_id, name="variable_3")
369369
VariableFactory(instance_id=use_case.instance_id, name="unused_variable")

tests/domain/execute_flow_from_position/test_agent_handover_node.py

+5-7
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,8 @@
1919
from use_case_executor.domain.flow.node_data.agent_handover_data import (
2020
AgentHandoverData,
2121
)
22-
from use_case_executor.domain.flow.node_data.agent_handover_data import (
23-
HandoverFailureQuickReply,
24-
)
2522
from use_case_executor.domain.flow.node_data.node_type import NodeType
23+
from use_case_executor.domain.flow.node_data.quick_reply import QuickReply
2624
from use_case_executor.domain.flow_execution.answer import Answer
2725
from use_case_executor.domain.flow_execution.execution_environment import (
2826
ExecutionEnvironment,
@@ -63,12 +61,12 @@ def flow(
6361
node for node in _flow.get_nodes() if node.type == NodeType.agent_handover
6462
)
6563
handover_node.data.handover_failure_quick_replies = [
66-
HandoverFailureQuickReply(
64+
QuickReply(
6765
target_use_case_uuid=target_use_case_uuid,
6866
target_intent_record_id=None,
6967
title_translations={content_language: "Content language V2 QR"},
7068
),
71-
HandoverFailureQuickReply(
69+
QuickReply(
7270
target_use_case_uuid=None,
7371
target_intent_record_id=target_intent_record_id,
7472
title_translations={content_language: "Content language Advanced QR"},
@@ -142,7 +140,7 @@ def test_flow_returns_failure_answer_if_agent_unavailable(
142140
mocker=mocker, return_value=False
143141
)
144142
if use_latest is False:
145-
mock_repository.set_filter_use_case_uuids_without_production_version(
143+
mock_repository.set_filter_use_case_uuids_without_production_version_return_value(
146144
mocker=mocker,
147145
return_value={target_use_case_uuid} if has_production_version else set(),
148146
)
@@ -305,7 +303,7 @@ def test_flow_raises_if_target_use_case_uuid_and_target_intent_record_id_are_bot
305303

306304
with pytest.raises(
307305
InvalidFlowConfiguration,
308-
match="the use case to send the customer to is not filled for an agent handover quick reply",
306+
match="the use case to send the customer to is not filled for an agent handover failure quick reply",
309307
):
310308
facade.execute_flow_from_position(
311309
flow=flow,

tests/domain/execute_flow_from_position/test_go_to_flow.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def test_flow_returns_all_go_to_flow_quick_replies_in_the_content_language_when_
138138
target_intent_record_id: int,
139139
):
140140
execution_environment = dataclasses.replace(execution_environment, use_latest=False)
141-
mock_repository.set_filter_use_case_uuids_without_production_version(
141+
mock_repository.set_filter_use_case_uuids_without_production_version_return_value(
142142
mocker=mocker,
143143
return_value={
144144
execution_environment.use_case_uuid,

0 commit comments

Comments
 (0)