Esempio n. 1
0
def test_create_fail_if_pick_list_empty(client):
    error_message = "Field may not be empty."
    with pytest.raises(ValidationError, match=error_message):
        create_command_processor(
            user_id=user_id,
            team_id=team_id,
            channel_id=channel_id,
            new_command_name=command_name,
            pick_list=[],
        )
Esempio n. 2
0
def test_create_fail_if_command_name_in_multiple_words(client):
    error_message = "Command name must be a single word, i.e without spaces."
    with pytest.raises(ValidationError, match=error_message):
        create_command_processor(
            user_id=user_id,
            team_id=team_id,
            channel_id=channel_id,
            new_command_name="a command",
            pick_list=default_pick_list,
        )
Esempio n. 3
0
def test_create_fail_if_non_valid_strategy(client):
    error_message = "boop is not a valid strategy."
    with pytest.raises(ValidationError, match=error_message):
        create_command_processor(
            user_id=user_id,
            team_id=team_id,
            channel_id=channel_id,
            new_command_name=command_name,
            strategy="boop",
            pick_list=default_pick_list,
        )
Esempio n. 4
0
def test_create_fail_if_already_exist(client):
    create_command_processor(
        user_id=user_id,
        team_id=team_id,
        channel_id=channel_id,
        new_command_name=command_name,
        pick_list=["1", "2", "3"],
    )

    with pytest.raises(BadRequestError,
                       match=f"Command {command_name} already exists."):
        create_command_processor(
            user_id=user_id,
            team_id=team_id,
            channel_id=channel_id,
            new_command_name=command_name,
            pick_list=["1", "2", "3"],
        )
Esempio n. 5
0
def test_create(input_data, expected_command, expected_message, client):
    if not input_data.get("pick_list"):
        input_data["pick_list"] = default_pick_list

    response = create_command_processor(
        user_id=user_id,
        team_id=team_id,
        channel_id=channel_id,
        new_command_name=command_name,
        **input_data,
    )

    message = response.get("message")
    if expected_message:
        assert expected_message in message.content
    assert message.status == MessageStatus.SUCCESS
    assert message.visibility == MessageVisibility.NORMAL

    created_command = (Command.find_one_by_name_and_chanel(
        name=command_name, channel_id=channel_id).to_son().to_dict())

    for key in expected_command:
        assert created_command[key] == expected_command[key]