Exemple #1
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"
Exemple #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"
Exemple #3
0
def test_auto_fill_custom_validation_resolution(kwik_e_mart_app):
    """Tests slot-filling's custom validation with custom resolution"""
    app = kwik_e_mart_app
    request = Request(
        text="what is the sum of 5 and 15?",
        domain="some domain",
        intent="some intent",
    )
    responder = DialogueResponder()

    # custom eval func
    @app.register_func()
    def test_custom_eval(r):
        return 5 + 15

    form = {
        "entities": [
            FormEntity(
                entity="sys_number",
                default_eval=False,
                custom_eval="test_custom_eval",
            )
        ],
    }

    def handler_sub(request, responder):
        entity = next((e for e in request.entities if e["type"] == "sys_number"), None)

        # Check custom resolution validity
        assert entity
        assert entity["value"][0]["value"] == 20

    @app.handle(domain="some domain", intent="some intent")
    def handler(request, responder):
        AutoEntityFilling(handler_sub, form, app).invoke(request, responder)

    handler(request, responder)
Exemple #4
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": [{
                "payload": "directive3"
            }, {
                "payload": "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 = [{
            "payload": "directive1"
        }, {
            "payload": "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 == [
            {
                "payload": "directive1"
            },
            {
                "payload": "directive2"
            },
            {
                "payload": "directive3"
            },
            {
                "payload": "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"