Exemplo n.º 1
0
def test_custom_only_active_users_error():
    error_message = "No active users to select found."
    with pytest.raises(MissingElementError, match=error_message):
        instant_command_processor(
            user_id=user_id,
            team_id=team_id,
            channel_id=channel_id,
            label=label,
            pick_list=["<@4321|name>"],
            number_of_items_to_select=number_of_items_to_select,
            self_exclude=self_exclude,
            only_active_users=True,
        )
Exemplo n.º 2
0
def test_create_fail_if_number_of_items_to_select_is_too_high():
    error_message = "Selecting more than 50 at once is prohibited."
    with pytest.raises(ValidationError, match=error_message):
        instant_command_processor(
            user_id=user_id,
            team_id=team_id,
            channel_id=channel_id,
            label=label,
            pick_list=["1", "2", "3"],
            number_of_items_to_select=51,
            self_exclude=self_exclude,
            only_active_users=only_active_users,
        )
Exemplo n.º 3
0
def test_create_fail_if_number_of_items_to_select_is_0():
    error_message = "Must select at least 1 item."
    with pytest.raises(ValidationError, match=error_message):
        instant_command_processor(
            user_id=user_id,
            team_id=team_id,
            channel_id=channel_id,
            label=label,
            pick_list=["1", "2", "3"],
            number_of_items_to_select=0,
            self_exclude=self_exclude,
            only_active_users=only_active_users,
        )
Exemplo n.º 4
0
def test_custom_command_only_active_users():
    response = instant_command_processor(
        user_id=user_id,
        team_id=team_id,
        channel_id=channel_id,
        label=label,
        pick_list=[f"<@{user_id}|name>", "<@4321|name>"],
        number_of_items_to_select=number_of_items_to_select,
        self_exclude=self_exclude,
        only_active_users=True,
    )

    message = response.get("message")
    assert f"<@{user_id}|name>" in message.content

    selected_items = response.get("selected_items")
    assert selected_items == [f"<@{user_id}|name>"]
Exemplo n.º 5
0
def test_instant_command():
    response = instant_command_processor(
        user_id=user_id,
        team_id=team_id,
        channel_id=channel_id,
        label=label,
        pick_list=pick_list,
        number_of_items_to_select=number_of_items_to_select,
        self_exclude=self_exclude,
        only_active_users=only_active_users,
    )

    message = response.get("message")
    selected_items = response.get("selected_items")
    assert selected_items == ["1"] or ["2"]

    assert f"Hey ! <@{user_id}> choose {selected_items[0]}" in message.content
    assert label in message.content

    assert message.visibility == MessageVisibility.NORMAL
    assert message.as_attachment is False
Exemplo n.º 6
0
def test_custom_command_multi_select(
    number_of_items_to_select,
    expected_message,
    expected_items,
    set_seed,
):
    response = instant_command_processor(
        user_id=user_id,
        team_id=team_id,
        channel_id=channel_id,
        label=label,
        pick_list=["1", "2", "3"],
        number_of_items_to_select=number_of_items_to_select,
        self_exclude=self_exclude,
        only_active_users=only_active_users,
    )

    message = response.get("message")
    assert expected_message in message.content

    selected_items = response.get("selected_items")
    assert selected_items == expected_items