-
Notifications
You must be signed in to change notification settings - Fork 233
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
189 additions
and
166 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
from typing import List, Dict, Text, Any | ||
|
||
import pytest | ||
|
||
from rasa_sdk import Action, FormValidationAction, Tracker, ValidationAction | ||
from rasa_sdk.events import SlotSet | ||
from rasa_sdk.executor import CollectingDispatcher | ||
from rasa_sdk.types import DomainDict | ||
|
||
|
||
class CustomAsyncAction(Action): | ||
def name(cls) -> Text: | ||
return "custom_async_action" | ||
|
||
async def run( | ||
self, | ||
dispatcher: CollectingDispatcher, | ||
tracker: Tracker, | ||
domain: DomainDict, | ||
) -> List[Dict[Text, Any]]: | ||
return [SlotSet("test", "foo"), SlotSet("test2", "boo")] | ||
|
||
|
||
class CustomAction(Action): | ||
def name(cls) -> Text: | ||
return "custom_action" | ||
|
||
def run( | ||
self, | ||
dispatcher: CollectingDispatcher, | ||
tracker: Tracker, | ||
domain: DomainDict, | ||
) -> List[Dict[Text, Any]]: | ||
return [SlotSet("test", "bar")] | ||
|
||
|
||
class CustomActionRaisingException(Action): | ||
def name(cls) -> Text: | ||
return "custom_action_exception" | ||
|
||
def run( | ||
self, | ||
dispatcher: CollectingDispatcher, | ||
tracker: Tracker, | ||
domain: DomainDict, | ||
) -> List[Dict[Text, Any]]: | ||
raise Exception("test exception") | ||
|
||
|
||
class CustomActionWithDialogueStack(Action): | ||
def name(cls) -> Text: | ||
return "custom_action_with_dialogue_stack" | ||
|
||
def run( | ||
self, | ||
dispatcher: CollectingDispatcher, | ||
tracker: Tracker, | ||
domain: DomainDict, | ||
) -> List[Dict[Text, Any]]: | ||
return [SlotSet("stack", tracker.stack)] | ||
|
||
|
||
class MockFormValidationAction(FormValidationAction): | ||
def __init__(self) -> None: | ||
self.fail_if_undefined("run") | ||
|
||
def fail_if_undefined(self, method_name: str) -> None: | ||
if not ( | ||
hasattr(self.__class__.__base__, method_name) | ||
and callable(getattr(self.__class__.__base__, method_name)) | ||
): | ||
pytest.fail( | ||
f"method '{method_name}' not found in {self.__class__.__base__}. " | ||
f"This likely means the method was renamed, which means the " | ||
f"instrumentation needs to be adapted!" | ||
) | ||
|
||
async def _extract_validation_events( | ||
self, | ||
dispatcher: "CollectingDispatcher", | ||
tracker: "Tracker", | ||
domain: "DomainDict", | ||
) -> None: | ||
return tracker.events | ||
|
||
def name(self) -> str: | ||
return "mock_form_validation_action" | ||
|
||
|
||
class MockValidationAction(ValidationAction): | ||
def __init__(self) -> None: | ||
self.fail_if_undefined("run") | ||
|
||
def fail_if_undefined(self, method_name: Text) -> None: | ||
if not ( | ||
hasattr(self.__class__.__base__, method_name) | ||
and callable(getattr(self.__class__.__base__, method_name)) | ||
): | ||
pytest.fail( | ||
f"method '{method_name}' not found in {self.__class__.__base__}. " | ||
f"This likely means the method was renamed, which means the " | ||
f"instrumentation needs to be adapted!" | ||
) | ||
|
||
async def run( | ||
self, | ||
dispatcher: "CollectingDispatcher", | ||
tracker: "Tracker", | ||
domain: "DomainDict", | ||
) -> None: | ||
pass | ||
|
||
def name(self) -> Text: | ||
return "mock_validation_action" | ||
|
||
async def _extract_validation_events( | ||
self, | ||
dispatcher: "CollectingDispatcher", | ||
tracker: "Tracker", | ||
domain: "DomainDict", | ||
) -> None: | ||
return tracker.events | ||
|
||
|
||
class SubclassTestActionA(Action): | ||
def name(self): | ||
return "subclass_test_action_a" | ||
|
||
|
||
class SubclassTestActionB(SubclassTestActionA): | ||
def name(self): | ||
return "subclass_test_action_b" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Oops, something went wrong.