Beispiel #1
0
def test_from_manage_list_command_event():
    # Given
    event_body = {
        "channel_id": "1001",
        "data": {
            "id":
            "2001",
            "name":
            "eternal-guess",
            "options": [{
                "name":
                "manage",
                "options": [{
                    "name": "list-games",
                    "options": [
                        {
                            "name": "closed",
                            "value": True
                        },
                    ]
                }]
            }]
        },
        "guild_id": "4001",
        "id": "5001",
        "member": {
            "deaf": False,
            "is_pending": False,
            "joined_at": "2021-01-16T20:21:19.053000+00:00",
            "mute": False,
            "nick": None,
            "pending": False,
            "permissions": "2147483647",
            "premium_since": None,
            "roles": [],
            "user": {
                "avatar": "abcdefghijklmop",
                "discriminator": "5",
                "id": "9001",
                "public_flags": 0,
                "username": "******"
            }
        },
        "token": "whfjwhfukwynexfl823yflwf9wauf928fh82e",
        "type": 2,
        "version": 1
    }

    # When
    event = discord_event.from_event(event_body)

    # Then
    assert event.channel_id == 1001
    assert event.guild_id == 4001

    command = event.command
    assert command.command_id == 2001
    assert command.command_name == "manage"
    assert command.subcommand_name == "list-games"
    assert command.options['closed']
    def handle(self, event) -> Dict:
        result, response = self.api_authorizer.authorize(event)
        if result == AuthorizationResult.PASS:
            body_json = json.loads(event['body'])
            event = discord_event.from_event(body_json)

            response = asyncio.get_event_loop() \
                .run_until_complete(self.router.route(event))

        return response.json()
Beispiel #3
0
def test_member_from_event():
    # Given
    event_body = {
        "channel_id": "1001",
        "data": {
            "id":
            "2001",
            "name":
            "guess",
            "options": [{
                "name": "game-id",
                "value": "test"
            }, {
                "name": "guess",
                "value": "1000"
            }]
        },
        "guild_id": "4001",
        "id": "5001",
        "member": {
            "deaf": False,
            "is_pending": False,
            "joined_at": "2021-01-16T20:21:19.053000+00:00",
            "mute": False,
            "nick": "User-Nickname",
            "pending": False,
            "permissions": "2147483647",
            "premium_since": None,
            "roles": [
                "9999",
            ],
            "user": {
                "avatar": "abcdefghijklmop",
                "discriminator": "5",
                "id": "9001",
                "public_flags": 0,
                "username": "******"
            }
        },
        "token": "whfjwhfukwynexfl823yflwf9wauf928fh82e",
        "type": 2,
        "version": 1
    }

    # When
    event = discord_event.from_event(event_body)

    # Then
    assert event.member.username == "User-Name"
    assert event.member.nickname == "User-Nickname"
    assert event.member.user_id == 9001
    assert event.member.roles == [9999]
Beispiel #4
0
def test_from_ping_event():
    # Given
    event_body = {
        "id": "5002",
        "token": "whfjwhfukwynexfl823yflwf9wauf928fh82d",
        "type": 1,
        "version": 1
    }

    # When
    event = discord_event.from_event(event_body)

    # Then
    assert event.command.command_name == "ping"
Beispiel #5
0
def test_from_create_without_options_command_event():
    # Given
    event_body = {
        "channel_id": "1001",
        "data": {
            "id": "2001",
            "name": "eternal-guess",
            "options": [{
                "name": "create",
            }]
        },
        "guild_id": "3001",
        "id": "4001",
        "member": {
            "deaf": False,
            "is_pending": False,
            "joined_at": "2021-01-16T20:21:19.053000+00:00",
            "mute": False,
            "nick": None,
            "pending": False,
            "permissions": "2147483647",
            "premium_since": None,
            "roles": [],
            "user": {
                "avatar": "abcdefghijklmop",
                "discriminator": "5",
                "id": "9001",
                "public_flags": 0,
                "username": "******"
            }
        },
        "token": "whfjwhfukwynexfl823yflwf9wauf928fh82e",
        "type": 2,
        "version": 1
    }

    # When
    event = discord_event.from_event(event_body)

    # Then
    command = event.command
    assert command.options == {}