Exemplo n.º 1
0
def test_mock_create_followup_message_sync(
    followup_message_object: FollowUpMessages, create_example_response
):
    respx.post(f"https://discord.com/api/v8/webhooks/APPID/exampleToken").mock(
        return_value=Response(200, json={"id": "exampleIncomingToken"})
    )

    assert (
        followup_message_object.create_follow_up_message(
            message=create_example_response
        )
        == True
    )
    with pytest.raises(TypeError):
        followup_message_object.create_follow_up_message(
            message=create_example_response
        )

    respx.post(f"https://discord.com/api/v8/webhooks/APPID/exampleToken").mock(
        return_value=Response(404, json={"id": "exampleIncomingToken"})
    )

    with pytest.raises(TypeError):
        followup_message_object.create_follow_up_message(
            message=create_example_response
        )
Exemplo n.º 2
0
def test_mock_delete_followup_message_fail_sync(
    followup_object_with_already_set_id: FollowUpMessages, ):
    respx.delete(
        f"https://discord.com/api/v8/webhooks/APPID/exampleToken/messages/SampleMessageId"
    ).mock(return_value=Response(404, json={"id": "exampleIncomingToken"}))

    with pytest.raises(DiscordAPIError):
        followup_object_with_already_set_id.delete_follow_up_message()
Exemplo n.º 3
0
def test_mock_delete_followup_message_sync(
    followup_object_with_already_set_id: FollowUpMessages, ):
    respx.delete(
        f"https://discord.com/api/v8/webhooks/APPID/exampleToken/messages/SampleMessageId"
    ).mock(return_value=Response(200, json={"id": "exampleIncomingToken"}))

    assert followup_object_with_already_set_id.delete_follow_up_message(
    ) == True
    assert followup_object_with_already_set_id._message_id == None

    with pytest.raises(TypeError):
        followup_object_with_already_set_id.delete_follow_up_message()
Exemplo n.º 4
0
def test_mock_edit_followup_message_sync(
        followup_object_with_already_set_id: FollowUpMessages,
        create_example_response):
    respx.patch(
        f"https://discord.com/api/v8/webhooks/APPID/exampleToken/messages/SampleMessageId"
    ).mock(return_value=Response(200, json={"id": "exampleIncomingToken"}))

    assert (followup_object_with_already_set_id.edit_follow_up_message(
        updated_message=create_example_response) == True)

    with pytest.raises(TypeError):
        followup_object_with_already_set_id._message_id = None
        followup_object_with_already_set_id.edit_follow_up_message(
            updated_message=create_example_response)
Exemplo n.º 5
0
async def test_async_follow_up_message_only_once(
    create_example_response,
    example_incoming_response,
    dispike_object,
):
    respx.post(f"https://discord.com/api/v8/webhooks/APPID/exampleToken").mock(
        return_value=Response(200, json={"id": "exampleIncomingToken"}))

    with pytest.raises(TypeError):
        throwaway_object = FollowUpMessages(
            bot=dispike_object, interaction=example_incoming_response)
        throwaway_object._message_id = "1212"
        ff = await throwaway_object.async_create_follow_up_message(
            message=create_example_response)
Exemplo n.º 6
0
def test_initalization_of_object(
        dispike_object: "Dispike",
        example_incoming_response: "IncomingDiscordSlashInteraction"):
    _create_object = FollowUpMessages(dispike_object,
                                      example_incoming_response)
    assert _create_object._application_id == "APPID"
    assert _create_object._interaction_token == "exampleToken"
Exemplo n.º 7
0
def test_invalid_type_passed_to_followup_functions(
    followup_message_object: FollowUpMessages, ):
    with pytest.raises(TypeError):
        followup_message_object.create_follow_up_message(message="Invalid")
    with pytest.raises(TypeError):
        followup_message_object.edit_follow_up_message(message="Invalid")
    with pytest.raises(TypeError):
        followup_message_object.delete_follow_up_message(message="Invalid")
Exemplo n.º 8
0
def followup_message_object(dispike_object: "Dispike",
                            example_incoming_response):
    return FollowUpMessages(bot=dispike_object,
                            interaction=example_incoming_response)
Exemplo n.º 9
0
def followup_object_with_already_set_id(
        followup_message_object: FollowUpMessages):
    followup_message_object._message_id = "SampleMessageId"
    return followup_message_object