Пример #1
0
def test_response_with_embed():
    _created_content = DiscordResponse(content="test")
    _created_embed = Embed(title="Test")
    _created_embed.add_field(name="test", value="test")
    _created_content.add_new_embed(_created_embed)

    assert _created_content.embeds[0] == _created_embed
Пример #2
0
def test_response_with_embed():
    _created_content = DiscordResponse(content="test")
    _created_embed = Embed(title="Test")
    _created_embed.add_field(name="test", value="test")
    _created_content.add_new_embed(_created_embed)

    assert isinstance(_created_content.embeds[0], dict) == True
    assert _created_content.embeds[0] != {}
Пример #3
0
def test_invalid_content():
    with pytest.raises(TypeError):
        _created_content = DiscordResponse(content=False)

    _created_content = DiscordResponse(content="")
    assert _created_content.content == None

    with pytest.raises(TypeError):
        _created_content = DiscordResponse(content="Test", tts="invalid")
Пример #4
0
async def test_send_defer_message_failed(dispike_object: Dispike, ):
    route = respx.patch(
        "https://discord.com/api/v8/webhooks/APPID/FAKETOKEN/messages/@original",
    ).mock(return_value=Response(500, ), )
    _sample_interaction = IncomingDiscordSlashInteraction(
        **{
            "channel_id": "123123",
            "data": {
                "id": "12312312",
                "name": "sample",
                "options": [{
                    "name": "message",
                    "value": "test"
                }],
            },
            "guild_id": "123123",
            "id": "123123123132",
            "member": {
                "deaf":
                False,
                "is_pending":
                False,
                "joined_at":
                "2019-05-12T18:36:16.878000+00:00",
                "mute":
                False,
                "nick":
                None,
                "pending":
                False,
                "permissions":
                "2147483647",
                "premium_since":
                None,
                "roles": [
                    "123123",
                    "123123",
                    "1231233",
                    "1231233133",
                    "12412412414",
                ],
                "user": {
                    "avatar": "b723979992a56",
                    "discriminator": "3333",
                    "id": "234234213122123",
                    "public_flags": 768,
                    "username": "******",
                },
            },
            "token": "FAKETOKEN",
            "type": 2,
            "version": 1,
        })
    with pytest.raises(httpx.HTTPError):
        await dispike_object.send_deferred_message(
            original_context=_sample_interaction,
            new_message=DiscordResponse(content="working"),
        )
Пример #5
0
async def handle_secret(ctx: IncomingDiscordInteraction) -> DiscordResponse:
    return DiscordResponse(
        content=f"""
        
        Hello {ctx.member.user.username}..
        
        Only you can see this message. **Do not share this key with anyone!**.

        Your key: || {uuid.uuid4()} ||

        """,
        empherical=True,
    )
Пример #6
0
def test_response_with_allowed_mentions():
    _created_response = DiscordResponse(
        content="test",
        allowed_mentions=AllowedMentions(
            parse=[AllowedMentionTypes.ROLE_MENTIONS], roles=[11111], replied_user=True
        ),
    )
    assert json.loads(json.dumps(_created_response.response))["allowed_mentions"] == {
        "parse": ["roles"],
        "roles": ["11111"],
        "users": [],
        "replied_user": True,
    }
    assert _created_response.response["data"]["content"] == "test"
Пример #7
0
def test_response_with_button():
    _created_button = Button(
        label="test",
        custom_id="test_id",
        disabled=True,
        emoji=PartialEmoji(name="test_emoji", id="123123123132", animated=True),
    )
    _created_link_button = LinkButton(
        label="test", disabled=True, url="https://github.com/"
    )
    _created_content = DiscordResponse(
        content="test",
        action_row=ActionRow(components=[_created_button, _created_link_button]),
    )

    assert _created_content.action_row == ActionRow(
        components=[_created_button, _created_link_button]
    )
Пример #8
0
def test_string_response_with_empherical():
    _created_content = DiscordResponse(content="test", empherical=True)
    assert _created_content.content == "test", _created_content.content
    assert (_created_content.response["data"]["content"] == "test"
            ), _created_content.content

    _created_content = DiscordResponse(content="test", tts=True)
    assert _created_content.content == "test"
    assert _created_content.tts == True

    _created_content.content = "test2"
    assert _created_content.content == "test2"
    assert _created_content.response["data"]["content"] == "test2"

    _created_content.tts = False
    assert _created_content.tts == False
    assert _created_content.response["data"]["tts"] == False

    _created_content = DiscordResponse(content="test", empherical=True)
    assert (_created_content.response["data"]["flags"] == 1 <<
            6), _created_content.response
Пример #9
0
def test_response_with_select_menu():
    _created_select_menu = SelectMenu(
        custom_id="test_id",
        disabled=True,
        max_values=1,
        min_values=1,
        options=[
            SelectMenu.SelectMenuOption(
                label="test",
                emoji=PartialEmoji(name="test_emoji", id="123123123132", animated=True),
                description="desc",
                value="test",
                default=True,
            )
        ],
        placeholder="Test",
    )
    _created_content = DiscordResponse(
        content="test", action_row=ActionRow(components=[_created_select_menu])
    )

    assert _created_content.action_row == ActionRow(components=[_created_select_menu])
Пример #10
0
def test_string_response():
    _created_content = DiscordResponse(content="test")
    assert _created_content.content == "test", _created_content.content
    assert (_created_content.response["data"]["content"] == "test"
            ), _created_content.content

    _created_content = DiscordResponse(content="test", tts=True)
    assert _created_content.content == "test"
    assert _created_content.tts == True

    _created_content.content = "test2"
    assert _created_content.content == "test2"
    assert _created_content.response["data"]["content"] == "test2"

    _created_content.tts = False
    assert _created_content.tts == False
    assert _created_content.response["data"]["tts"] == False
Пример #11
0
def test_if_call_function_returns_response():
    _sample = DiscordResponse(content="test")
    assert _sample.__call__() == _sample.response
Пример #12
0
 async def return_event_no_hinting(*args, **kwargs):
     logger.info("called no_hint_return_discord_response")
     return DiscordResponse(content="sample")
Пример #13
0
 async def return_event_hint(*args, **kwargs) -> DiscordResponse:
     logger.info("hint_return_discord_response")
     return DiscordResponse(content="sample")
Пример #14
0
def test_interactions_endpoint():
    # enable testing mode
    # add callback manually (for some reason there is an error with pytest -- throws "this event loop is already running"
    bot.callbacks = {
        "command": {
            "hint_return_discord_response": {
                "settings": {},
                "function": sample_function,
            }
        },
        "component": {},
    }
    bot._internal_application.middleware_stack.app._skip_verification_of_key = True
    _incoming_interaction = {
        "channel_id": "123123",
        "data": {
            "id": "12312312",
            "name": "hint_return_discord_response",
            "options": [{"name": "message", "value": "test"}],
            "type": 1,
        },
        "guild_id": "123123",
        "id": "123123123132",
        "member": {
            "deaf": False,
            "is_pending": False,
            "joined_at": "2019-05-12T18:36:16.878000+00:00",
            "mute": False,
            "nick": None,
            "pending": False,
            "permissions": "2147483647",
            "premium_since": None,
            "roles": [
                "123123",
                "123123",
                "1231233",
                "1231233133",
                "12412412414",
            ],
            "user": {
                "avatar": "b723979992a56",
                "discriminator": "3333",
                "id": "234234213122123",
                "public_flags": 768,
                "username": "******",
            },
        },
        "token": "Null",
        "type": 2,
        "version": 1,
    }

    response = client.post(
        "/interactions",
        headers={
            "X-Signature-Ed25519": signed_value.signature.decode(),
            "x-Signature-Timestamp": _created_timestamp,
        },
        json=_incoming_interaction,
    )
    assert response.status_code == 200
    assert response.json() == DiscordResponse(content="sample").response
    bot._internal_application.middleware_stack.app._skip_verification_of_key = False
    bot.clear_all_event_callbacks()
Пример #15
0
async def sample_function(*args, **kwargs):
    return DiscordResponse(content="sample")
Пример #16
0
def create_example_response():
    from dispike.response import DiscordResponse

    return DiscordResponse(content="not needed.")
Пример #17
0
def test_invalid_embed_object():
    _created_content = DiscordResponse(content="test")
    with pytest.raises(TypeError):
        _created_content.add_new_embed(False)
Пример #18
0
def sample_discord_response():
    return DiscordResponse(content="test")
Пример #19
0
def test_type_response_update_message():
    _sample = DiscordResponse(content="test", update_message=True)
    assert _sample._type_response == 7
Пример #20
0
def test_type_response_update():
    _sample = DiscordResponse(content="test")
    _sample.set_type_response = 4
    assert _sample._type_response == 4