def test_sync_failed_get_command_permission_for_guild( dispike_object: Dispike, ): respx.get( "https://discord.com/api/v8/applications/APPID/guilds/1111/commands/1234/permissions" ).mock(return_value=Response( 500, json={ "id": "1123123123123", "application_id": "0000", "guild_id": "1111", "permissions": [{ "id": "1234", "type": 2, "permission": True, }], }, )) dispike_object._application_id == "0000" with pytest.raises(DiscordAPIError): _get_commands = dispike_object.get_command_permission_in_guild( command_id="1234", guild_id=1111) dispike_object._application_id = "APPID"
def test_sync_get_command_permission_for_guild(dispike_object: Dispike, ): respx.get( "https://discord.com/api/v8/applications/APPID/guilds/1111/commands/1234/permissions" ).mock(return_value=Response( 200, json={ "id": "1123123123123", "application_id": "0000", "guild_id": "1111", "permissions": [{ "id": "1234", "type": 2, "permission": True, }], }, )) dispike_object._application_id == "0000" _get_commands = dispike_object.get_command_permission_in_guild( command_id="1234", guild_id=1111) assert isinstance(_get_commands, GuildApplicationCommandPermissions) _get_commands: GuildApplicationCommandPermissions assert _get_commands.id == 1123123123123 assert _get_commands.application_id == 0000 assert len(_get_commands.permissions) == 1 assert _get_commands.permissions[0].id == 1234 assert _get_commands.permissions[0].type == 2 assert _get_commands.permissions[0].permission == True dispike_object._application_id = "APPID"
def test_sync_get_all_command_permission_for_guild(dispike_object: Dispike, ): respx.get( "https://discord.com/api/v8/applications/APPID/guilds/1111/commands/permissions" ).mock(return_value=Response( 200, json=[ { "id": "1111", "application_id": "0000", "guild_id": "00", "permissions": [{ "id": "1234", "type": 2, "permission": True, }], }, { "id": "2222", "application_id": "0000", "guild_id": "00", "permissions": [{ "id": "1234", "type": 2, "permission": True, }], }, { "id": "3333", "application_id": "0000", "guild_id": "00", "permissions": [{ "id": "1234", "type": 2, "permission": True, }], }, ], )) dispike_object._application_id == "0000" _get_commands = dispike_object.get_all_command_permissions_in_guild( guild_id=1111) assert len(_get_commands) == 3 for command in _get_commands: assert isinstance(command, GuildApplicationCommandPermissions) command: GuildApplicationCommandPermissions assert command.id in [1111, 2222, 3333] assert command.application_id == 0000 assert len(command.permissions) == 1 assert command.permissions[0].id == 1234 assert command.permissions[0].type == 2 assert command.permissions[0].permission == True dispike_object._application_id = "APPID"
def test_sync_not_found_get_command_permission_for_guild( dispike_object: Dispike, ): respx.get( "https://discord.com/api/v8/applications/APPID/guilds/1111/commands/1234/permissions" ).mock(return_value=Response(404, )) dispike_object._application_id == "0000" _get_commands = dispike_object.get_command_permission_in_guild( command_id="1234", guild_id=1111) assert _get_commands == None dispike_object._application_id = "APPID"
async def test_no_permissions_get_all_command_permission_for_guild( dispike_object: Dispike, ): respx.get( "https://discord.com/api/v8/applications/APPID/guilds/1111/commands/permissions" ).mock(return_value=Response( 200, json=[], )) dispike_object._application_id == "0000" _get_commands = await dispike_object.async_get_all_command_permissions_in_guild( guild_id=1111) assert len(_get_commands) == 0 dispike_object._application_id = "APPID"