コード例 #1
0
ファイル: test_slack_event.py プロジェクト: lyft/omnibot
def test_event_callback_test_message(client: Client, instrument: MagicMock,
                                     queue: MagicMock):
    with get_mock_data("event/event_callback_test_message.json") as json_data:
        event: Dict[str, Any] = json.loads(json_data.read())
        resp: Response = client.post(_ENDPOINT,
                                     data=json.dumps(event),
                                     content_type="application/json")
        assert resp.status_code == 200
        assert resp.json["status"] == "success"
        instrument.assert_called_once_with(get_test_bot(), event)
        queue.assert_called_once_with(get_test_bot(), event, "event")
コード例 #2
0
ファイル: test_get_channel.py プロジェクト: lyft/omnibot
def test_get_channel_by_name(internal_client: Client, mocker: MockerFixture):
    get_channel_by_name = mocker.patch(
        "omnibot.services.slack.get_channel_by_name")
    mock_channel_value = {"channel": {"id": "test-channel-id"}}
    get_channel_by_name.return_value = mock_channel_value
    resp: Response = internal_client.get(
        "/api/v1/slack/get_channel/test-team-name/TEST_OMNIBOT_NAME/test-channel"
    )
    assert resp.status_code == 200
    assert resp.json == mock_channel_value
    get_channel_by_name.assert_called_once_with(get_test_bot(), "test-channel")
コード例 #3
0
ファイル: test_get_channel.py プロジェクト: lyft/omnibot
def test_get_channel_by_name_invalid(internal_client: Client,
                                     mocker: MockerFixture):
    get_channel_by_name = mocker.patch(
        "omnibot.services.slack.get_channel_by_name")
    get_channel_by_name.return_value = None
    resp: Response = internal_client.get(
        "/api/v1/slack/get_channel/test-team-name/TEST_OMNIBOT_NAME/test-channel"
    )
    assert resp.status_code == 404
    assert resp.json["error"] == "provided channel_name was not found."
    get_channel_by_name.assert_called_once_with(get_test_bot(), "test-channel")
コード例 #4
0
ファイル: test_slack_action.py プロジェクト: lyft/omnibot
def test_slack_action(internal_client: Client, mocker: MockerFixture,
                      slack_api_call: MagicMock):
    mock_channel_value = {"id": "TEST_CHANNEL_ID", "name": "test-channel"}

    get_channel_by_name = mocker.patch(
        "omnibot.services.slack.get_channel_by_name")
    get_user_by_name = mocker.patch("omnibot.services.slack.get_user_by_name")
    get_channel_by_name.return_value = mock_channel_value
    get_user_by_name.return_value = {
        "profile": {
            "display_name": "testuser"
        },
        "id": "test_user_id",
    }
    slack_api_call.return_value = {"ok": True}

    resp: Response = internal_client.post(
        "/api/v2/slack/action/test-team-name/TEST_OMNIBOT_NAME",
        data=json.dumps({
            "action": "chat.postMessage",
            "kwargs": {
                "channel": "TEST_CHANNEL_ID",
                "text": "@example see #general and use @here",
                "as_user": True,
                "omnibot_parse": {
                    "text": ["channels", "users", "specials"]
                },
            },
        }),
        content_type="application/json",
    )
    assert resp.status_code == 200
    assert resp.json == {"ok": True}
    get_channel_by_name.assert_called_once_with(get_test_bot(), "#general")
    get_user_by_name.assert_called_once_with(get_test_bot(), "@example")
    slack_api_call.assert_called_once_with(
        "chat.postMessage",
        channel="TEST_CHANNEL_ID",
        text="<@test_user_id|testuser> see #general and use <!here|here>",
        as_user=True,
    )
コード例 #5
0
def test_get_user_v2_user_not_found(internal_client: Client,
                                    mocker: MockerFixture):
    get_user_by_email = mocker.patch(
        "omnibot.services.slack.get_user_by_email")
    get_user_by_email.return_value = None
    resp: Response = internal_client.get(
        "/api/v1/slack/get_user/test-team-name/TEST_OMNIBOT_NAME/[email protected]"
    )
    assert resp.status_code == 404
    assert resp.json["error"] == "user not found"
    get_user_by_email.assert_called_once_with(get_test_bot(),
                                              "*****@*****.**")
コード例 #6
0
ファイル: test_send_im.py プロジェクト: lyft/omnibot
def test_send_bot_im(
    internal_client: Client, mocker: MockerFixture, slack_api_call: MagicMock
):
    get_im_channel_id = mocker.patch("omnibot.services.slack.get_im_channel_id")
    get_user_by_email = mocker.patch("omnibot.services.slack.get_user_by_email")
    get_user_by_email.return_value = {"id": "TEST_USER_ID"}
    get_im_channel_id.return_value = "TEST_CHANNEL_ID"
    slack_api_call.return_value = {"ok": True}

    resp: Response = internal_client.post(
        "/api/v1/slack/send_im/test-team-name/TEST_OMNIBOT_NAME/[email protected]",
        data=json.dumps({"action": "test-send-bot-im", "kwargs": {}}),
        content_type="application/json",
    )
    assert resp.status_code == 200
    assert resp.json == {"ok": True}
    get_user_by_email.assert_called_once_with(get_test_bot(), "*****@*****.**")
    get_im_channel_id.assert_called_once_with(get_test_bot(), "TEST_USER_ID")
    slack_api_call.assert_called_once_with(
        "test-send-bot-im", channel="TEST_CHANNEL_ID"
    )
コード例 #7
0
ファイル: test_slash_command.py プロジェクト: lyft/omnibot
def test_user_issues_echo_command(client: Client, queue: MagicMock):
    with get_mock_data(
            "slash_command/user_issues_echo_command.json") as json_data:
        event: Dict[str, Any] = json.loads(json_data.read())
        resp: Response = client.post(
            _ENDPOINT,
            data=event,
            content_type="application/x-www-form-urlencoded",
        )
        assert resp.status_code == 200
        command = event.copy()
        command["omnibot_bot_id"] = "TEST_OMNIBOT_ID"
        queue.assert_called_once_with(get_test_bot(), command, "slash_command")
        assert resp.json["response_type"] == "in_channel"
コード例 #8
0
ファイル: test_interactive.py プロジェクト: lyft/omnibot
def test_dialog_submission_echo_test(client: Client, queue: MagicMock,
                                     slack_api_call: MagicMock):
    with get_mock_data(
            "interactive/dialog_submission_echo_test.json") as json_data:
        event: Dict[str, Any] = json.loads(json_data.read())
        resp: Response = client.post(
            _ENDPOINT,
            data=event,
            content_type="application/x-www-form-urlencoded",
        )
        assert resp.status_code == 200

        component = json.loads(event["payload"])
        component["omnibot_bot_id"] = "TEST_OMNIBOT_ID"
        queue.assert_called_once_with(get_test_bot(), component,
                                      "interactive_component")
        slack_api_call.assert_not_called()
コード例 #9
0
def test_get_user_v2_user_found(internal_client: Client,
                                mocker: MockerFixture):
    get_user_by_email = mocker.patch(
        "omnibot.services.slack.get_user_by_email")
    get_user_by_email.return_value = {
        "profile": {
            "display_name": "testuser"
        },
        "id": "test_user_id",
    }
    resp: Response = internal_client.get(
        "/api/v1/slack/get_user/test-team-name/TEST_OMNIBOT_NAME/[email protected]"
    )
    assert resp.status_code == 200
    user_resp = resp.json["user"]
    assert user_resp["email"] == "*****@*****.**"
    assert user_resp["name"] == "testuser"
    assert user_resp["team_id"] == "TEST_TEAM_ID"
    assert user_resp["user_id"] == "test_user_id"
    get_user_by_email.assert_called_once_with(get_test_bot(),
                                              "*****@*****.**")
コード例 #10
0
def test_get_bot_ims(internal_client: Client, mocker: MockerFixture):
    get_ims = mocker.patch("omnibot.services.slack.get_ims")
    mock_im = {
        "id": "TEST_IM_ID",
        "created": 0,
        "is_im": True,
        "is_org_shared": True,
        "user": "******",
        "is_user_deleted": False,
        "priority": 0,
    }
    mock_ims_value = [(
        "TEST_IM_ID",
        json.dumps(mock_im),
    )]
    get_ims.return_value = mock_ims_value
    resp: Response = internal_client.get(
        "/api/v1/slack/get_ims/test-team-name/TEST_OMNIBOT_NAME")
    assert resp.status_code == 200
    assert resp.json == {"ims": [mock_im]}
    get_ims.assert_called_once_with(get_test_bot())