def test_after_message():
    """
    Scenario: Webhook.clear is called after Webhook.message
        When Webhook.clear is called after Webhook.message
        Then Webhook.clear should ignore channel_id & token Instance Variables
        Then Webhook.clear should set the tts Instance Variable to False
        Then Webhook.clear should set the embeds Instance Variable to []
        Then Webhook.clear should set all other Instance Variables to None
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message(content=content,
                 username=username,
                 avatar_url=avatar_url,
                 tts=True)

    hook.clear()

    assert hook.channel_id is not None
    assert hook.token is not None
    assert hook.tts is False
    assert hook.content is None
    assert hook.username is None
    assert hook.avatar_url is None
    assert len(hook.embeds) == 0
def test_after_multiple_embed():
    """
    Scenario: Webhook.clear is called after multiple Webhook.embed
        When Webhook.clear is called after multiple Webhook.embed
        Then Webhook.clear should ignore channel_id & token Instance Variables
        Then Webhook.clear should set the tts Instance Variable to False
        Then Webhook.clear should set the embeds Instance Variable to []
        Then Webhook.clear should set all other Instance Variables to None
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.embed(title="test_after_multiple_embed_1",
               description=content,
               url=avatar_url,
               color="ff8800")

    hook.embed(title="test_after_multiple_embed_2",
               description=content,
               url=avatar_url,
               color="88ff00")

    hook.clear()

    assert hook.channel_id is not None
    assert hook.token is not None
    assert hook.tts is False
    assert hook.content is None
    assert hook.username is None
    assert hook.avatar_url is None
    assert len(hook.embeds) == 0
def test_blank_call():
    """
    Scenario: discord.Webhook() is called without arguments
        When discord.Webhook() is called without arguments
        Then WhPy should alert the developer to missing required arguments
    """
    with pytest.raises(TypeError) as exception_info:

        hook = discord.Webhook()

    assert "Missing required arguments" in str(exception_info.value)
def test_content_empty():
    """
    Scenario: Webhook.message() is called without content argument set
        When Webhook.message() is called without content argument set
        Then WhPy should set content to None
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message()

    assert not hook.content
def test_message_tts():
    """
    Scenario: Webhook.message() is called with the tts argument set as True
        When Webhook.message() is called with the tts argument set as True
        Then WhPy should store the tts flag as True
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message(content=content[0], tts=True)

    assert hook.tts is True
def test_token_stored_as_string():
    """
    Scenario: discord.Webhook() is successfully called with channel_id & token
        When discord.Webhook() is successfully called with channel_id and token
        Then discord.Webhook() should store token as a string
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    assert hook.token is not None
    assert type(hook.token) is str
    assert hook.token == str(token)
def test_token_invalid():
    """
    Scenario: discord.Webhook() is called with an invalid token
        When discord.Webhook() is called with an invalid token
        Then WhPy should alert the developer to an Invalid Webhook Token
    """
    with pytest.raises(ValueError) as exception_info:

        hook = discord.Webhook(channel_id=channel_id, token=bad_token)

    assert "Invalid Webhook Token" in str(exception_info.value)
def test_token_blank():
    """
    Scenario: discord.Webhook() is called without token assigned
        When discord.Webhook() is called without the token assigned
        Then WhPy should alert the developer to missing required arguments
    """
    with pytest.raises(TypeError) as exception_info:

        hook = discord.Webhook(channel_id=channel_id)

    assert "Missing required arguments" in str(exception_info.value)
def test_channel_id_invalid():
    """
    Scenario: discord.Webhook() is called with an invalid channel_id
        When discord.Webhook() is called with an invalid channel_id
        Then why should alert the developer to an unknown webhook
    """
    with pytest.raises(ValueError) as exception_info:

        hook = discord.Webhook(channel_id=bad_channel_id, token=token)

    assert "Unknown Webhook" in str(exception_info.value)
def test_avatar_url_empty():
    """
    Scenario: Webhook.message() is called without avatar_url argument set
    When Webhook.message() is called without avatar_url argument set
    Then WhPy should set username to None
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message()

    assert not hook.avatar_url
def test_url_decodes():
    """
    Scenario: discord.Webhook() is successfully called with url
        When discord.Webhook() is successfully called with url
        Then discord.Webhook() will decode the url into channel_id and token
    """
    hook = discord.Webhook(url=url)

    assert hook.channel_id is not None
    assert hook.channel_id == url.split("/")[5]
    assert hook.token == url.split("/")[6]
def test_content_stored_as_string(content):
    """
    Scenario: Webhook.message() is called with content argument set
        When Webhook.message() is called with content argument set
        Then Webhook.message() should store content as a string
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message(content=content)

    assert hook.content is not None
    assert type(hook.content) is str
    assert hook.content == str(content)
def test_username_stored_as_string(username):
    """
    Scenario: Webhook.message() is called with username argument set
        When Webhook.message() is called with username argument set
        Then Webhook.message() should store username as a string
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message(username=username)

    assert hook.username is not None
    assert type(hook.username) is str
    assert hook.username == str(username)
Example #14
0
def test_message_not_called():
    """
    Scenario: Webhook.execute() is called without calling Webhook.message()
        When Webhook.execute() is called without calling Webhook.message()
        Then WhPy should alert the developer to a missing required argument
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    with pytest.raises(TypeError) as exception_info:

        hook.execute()

    assert "Missing required arguments:" in str(exception_info.value)
def test_avatar_url_stored_as_string(avatar_url):
    """
    Scenario: Webhook.message() is called with avatar_url argument set
        When Webhook.message() is called with avatar_url argument set
        Then Webhook.message() should store avatar_url as a string
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message(avatar_url=avatar_url)

    assert hook.avatar_url is not None
    assert type(hook.avatar_url) is str
    assert hook.avatar_url == str(avatar_url)
Example #16
0
def test_wait():
    """
    Scenario: Webhook.execute() is called with wait=True
        When Webhook.execute() is called with wait=True
        Then WhPy should get JSON data by adding query parameter 'wait=true'
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message(content=content)

    response = hook.execute(wait=True)

    assert response.status_code == 200
    assert response.json()
Example #17
0
def test_message_data():
    """
    Scenario: Webhook.execute() is called with Webhook.message() populated
        When Webhook.execute() is called with Webhook.message() populated
        Then WhPy should execute the message with stored values
    """
    hook = discord.Webhook(channel_id=channel_id, token=token)

    hook.message(content=content,
                 username=username,
                 avatar_url=avatar_url,
                 tts=True)

    response = hook.execute(wait=True)

    print(response.json())

    assert response.json()["content"] == content
    assert response.json()["author"]["username"] == username
    assert response.json()["author"]["avatar"] is not None
    assert response.json()["tts"] is True