示例#1
0
def test_slack_form_metadata():
    user = "******"
    channel = "channel1"
    authed_user = "******"
    team_id = "XXXXXXXXX"
    ts = "1579802617.000800"
    header = {"content-type": "application/x-www-form-urlencoded"}
    payload = {
        "type": "block_actions",
        "team": {
            "id": team_id,
            "domain": "example"
        },
        "user": {
            "id": authed_user,
            "username": user,
            "name": "name"
        },
        "channel": {
            "id": channel
        },
        "message": {
            "type":
            "message",
            "text":
            "text",
            "user":
            authed_user,
            "ts":
            ts,
            "blocks": [{
                "type":
                "actions",
                "block_id":
                "XXXXX",
                "elements": [{
                    "type": "button",
                    "action_id": "XXXXX",
                    "text": {
                        "type": "plain_text",
                        "text": "text"
                    },
                    "value": "value",
                }],
            }],
        },
    }
    form_event = {"payload": [json.dumps(payload)]}

    input_channel = SlackInput(
        slack_token="YOUR_SLACK_TOKEN",
        slack_channel="YOUR_SLACK_CHANNEL",
        slack_signing_secret="foobar",
    )

    r = Mock()
    r.form = form_event
    r.headers = header
    metadata = input_channel.get_metadata(request=r)
    assert metadata["out_channel"] == channel
    assert metadata["users"][0] == authed_user
    assert metadata["thread_id"] == ts
    assert metadata["team_id"] == team_id
示例#2
0
    data = {"name": "ka[pa[opi[opj[oj[oija"}
    _, response = rasa_app.post(f"/conversations/{test_sender}/trigger_intent",
                                json=data)

    assert response.status == 404


@pytest.mark.parametrize(
    "input_channels, output_channel_to_use, expected_channel",
    [
        (None, "slack", CollectingOutputChannel),
        ([], None, CollectingOutputChannel),
        ([RestInput()], "slack", CollectingOutputChannel),
        ([RestInput()], "rest", CollectingOutputChannel),
        ([RestInput(), SlackInput("test")], "slack", SlackBot),
    ],
)
def test_get_output_channel(input_channels: List[Text], output_channel_to_use,
                            expected_channel: Type):
    request = MagicMock()
    app = MagicMock()
    app.input_channels = input_channels
    request.app = app
    request.args = {"output_channel": output_channel_to_use}

    actual = rasa.server._get_output_channel(request, None)

    assert isinstance(actual, expected_channel)