Example #1
0
def test_register_command_guild_only_unsuccessful():
    respx.post(
        "https://discord.com/api/v8/applications/EXAMPLE_APP_ID/guilds/EXAMPLE_GUILD/commands"
    ).mock(return_value=Response(500))

    from dispike.creating.registrator import RegisterCommands

    target_item = RegisterCommands(application_id="EXAMPLE_APP_ID",
                                   bot_token="EXAMPLE_BOT_TOKEN")
    command_to_be_created = DiscordCommand(
        name="wave",  # this is the main command name.
        description="Send a wave to a nice person! 👋 ",
        options=[
            CommandOption(
                name=
                "person",  # this is the attribute assigned to the value passed.,
                description=
                "person to target",  # this describes the value to pass,
                required=True,
                type=OptionTypes.USER,
            )
        ],
    )
    with pytest.raises(DiscordAPIError):
        target_item.register(command_to_be_created,
                             guild_only=True,
                             guild_to_target="EXAMPLE_GUILD")
Example #2
0
def test_updating_bot_token():
    from dispike.creating.registrator import RegisterCommands

    target_item = RegisterCommands(application_id="EXAMPLE_APP_ID",
                                   bot_token="EXAMPLE_BOT_TOKEN")

    target_item.bot_token = "NEW_BOT_TOKEN"

    assert target_item.request_headers == {
        "Authorization": "Bot NEW_BOT_TOKEN"
    }
Example #3
0
def test_permission_error_for_viewing_bot_token_directly():
    from dispike.creating.registrator import RegisterCommands

    target_item = RegisterCommands(application_id="EXAMPLE_APP_ID",
                                   bot_token="EXAMPLE_BOT_TOKEN")

    with pytest.raises(PermissionError):
        target_item.bot_token
Example #4
0
def test_requests_headers_correct():
    from dispike.creating.registrator import RegisterCommands

    target_item = RegisterCommands(application_id="EXAMPLE_APP_ID",
                                   bot_token="EXAMPLE_BOT_TOKEN")

    assert target_item.request_headers == {
        "Authorization": f"Bot EXAMPLE_BOT_TOKEN"
    }
Example #5
0
def test_register_command_guild_only_invalid_arguments():
    from dispike.creating.registrator import RegisterCommands

    target_item = RegisterCommands(application_id="EXAMPLE_APP_ID",
                                   bot_token="EXAMPLE_BOT_TOKEN")
    command_to_be_created = DiscordCommand(
        name="wave",  # this is the main command name.
        description="Send a wave to a nice person! 👋 ",
        options=[
            CommandOption(
                name=
                "person",  # this is the attribute assigned to the value passed.,
                description=
                "person to target",  # this describes the value to pass,
                required=True,
                type=OptionTypes.USER,
            )
        ],
    )
    with pytest.raises(TypeError):
        target_item.register(command_to_be_created, guild_only=True)