Example #1
0
def test_custom_action_merge():
    "Test `merge=True` for custom actions"
    action_config = {"url": "http://localhost:8080/v2/action"}
    action = CustomAction(name="action_call_people", config=action_config)

    with patch("requests.post") as mock_object:
        mock_object.return_value = Mock()
        mock_object.return_value.status_code = 200
        mock_object.return_value.json.return_value = {
            "directives": ["directive3", "directive4"],
            "frame": {"k2": "v2"},
            "slots": {"s2": "v2"},
            "params": {
                "allowed_intents": ["intent3", "intent4"],
                "dynamic_resource": {"r2": "v2"},
                "language": "some-language",
                "locale": "some-locale",
                "time_zone": "some-time-zone",
                "target_dialogue_state": "some-state",
                "timestamp": "some-timestamp",
            },
        }

        request = Request(
            text="sing a song", domain="some domain", intent="some intent"
        )
        responder = DialogueResponder()
        responder.directives = ["directive1", "directive2"]
        responder.frame = {"k1": "v1"}
        responder.slots = {"s1": "v1"}
        responder.params.allowed_intents = ("intent1", "intent2")
        responder.params.dynamic_resource = {"r1": "v1"}
        assert action.invoke(request, responder)
        assert responder.directives == [
            "directive1",
            "directive2",
            "directive3",
            "directive4",
        ]
        assert responder.frame == {"k1": "v1", "k2": "v2"}
        assert responder.slots == {"s1": "v1", "s2": "v2"}
        assert responder.params.allowed_intents == (
            "intent1",
            "intent2",
            "intent3",
            "intent4",
        )
        assert responder.params.dynamic_resource == {"r1": "v1", "r2": "v2"}
        assert responder.params.target_dialogue_state == "some-state"
        assert responder.params.language == "some-language"
        assert responder.params.locale == "some-locale"
        assert responder.params.time_zone == "some-time-zone"
        assert responder.params.timestamp == "some-timestamp"
Example #2
0
def test_custom_action():
    """Test CustomAction.invoke to ensure that the parameters of the JSON body are correct"""
    action_config = {"url": "http://localhost:8080/v2/action"}
    action = CustomAction(name="action_call_people", config=action_config)

    with patch("requests.post") as mock_object:
        mock_object.return_value = Mock()
        mock_object.return_value.status_code = 200
        mock_object.return_value.json.return_value = {}

        request = Request(
            text="sing a song", domain="some domain", intent="some intent"
        )
        responder = DialogueResponder()
        assert action.invoke(request, responder)
        assert mock_object.call_args[1]["url"] == action_config["url"]
        assert "request" in mock_object.call_args[1]["json"]
        assert "responder" in mock_object.call_args[1]["json"]
        assert mock_object.call_args[1]["json"]["action"] == "action_call_people"
Example #3
0
async def test_custom_action_async():
    """Test CustomAction.invoke_async to ensure that the parameters of the JSON body are correct"""
    action_config = {"url": "http://localhost:8080/v2/action"}
    action = CustomAction(name="action_call_people", config=action_config)

    with patch("mindmeld.components.CustomAction.post_async") as mock_object:

        async def mock_coroutine():
            return 200, {}

        mock_object.return_value = mock_coroutine()
        request = Request(text="sing a song",
                          domain="some domain",
                          intent="some intent")
        responder = DialogueResponder()
        assert await action.invoke_async(request, responder)
        call_args = mock_object.call_args_list[0][0][0]
        assert "request" in call_args
        assert "responder" in call_args
        assert call_args["action"] == "action_call_people"