def setUp(self): self.bot = MockBot() self.mod = MockMember(top_role=10) self.user = MockMember(top_role=1, roles=[MockRole(id=123456)]) self.guild = MockGuild() self.ctx = MockContext(bot=self.bot, author=self.mod) self.cog = Infractions(self.bot)
def setUp(self): self.bot = MockBot() self.admin_role = MockRole(name="Admins", id=Roles.admins) self.command_user = MockMember([self.admin_role]) self.guild = MockGuild([self.admin_role]) self.ctx = MockContext(bot=self.bot, author=self.command_user, guild=self.guild) self.cog = jams.CodeJams(self.bot)
def setUp(self): self.bot = MockBot() self.cog = Infractions(self.bot) self.user = MockMember(id=1234, top_role=MockRole(id=3577, position=10)) self.target = MockMember(id=1265, top_role=MockRole(id=9876, position=0)) self.guild = MockGuild(id=4567) self.ctx = MockContext(bot=self.bot, author=self.user, guild=self.guild)
async def test_handle_unexpected_error(self, log_mock, push_scope_mock): """Should `ctx.send` this error, error log this and sent to Sentry.""" for case in (None, MockGuild()): with self.subTest(guild=case): self.ctx.reset_mock() log_mock.reset_mock() push_scope_mock.reset_mock() self.ctx.guild = case await self.cog.handle_unexpected_error(self.ctx, errors.CommandError()) self.ctx.send.assert_awaited_once() log_mock.error.assert_called_once() push_scope_mock.assert_called_once() set_tag_calls = [ call("command", self.ctx.command.qualified_name), call("message_id", self.ctx.message.id), call("channel_id", self.ctx.channel.id), ] set_extra_calls = [ call("full_message", self.ctx.message.content) ] if case: url = ( f"https://discordapp.com/channels/" f"{self.ctx.guild.id}/{self.ctx.channel.id}/{self.ctx.message.id}" ) set_extra_calls.append(call("jump_to", url)) push_scope_mock.set_tag.has_calls(set_tag_calls) push_scope_mock.set_extra.has_calls(set_extra_calls)
def setUp(self): self.bot = MockBot() self.mod = MockMember(roles=[MockRole(id=7890123, position=10)]) self.user = MockMember(roles=[MockRole(id=123456, position=1)]) self.guild = MockGuild() self.ctx = MockContext(bot=self.bot, author=self.mod) self.cog = Infractions(self.bot)
def setUp(self): self.me = MockMember(id=7890, roles=[MockRole(id=7890, position=5)]) self.bot = MockBot() self.cog = Infractions(self.bot) self.user = MockMember(id=1234, roles=[MockRole(id=3577, position=10)]) self.target = MockMember(id=1265, roles=[MockRole(id=9876, position=1)]) self.guild = MockGuild(id=4567) self.ctx = MockContext(me=self.me, bot=self.bot, author=self.user, guild=self.guild)
async def test_force_voice_sync_no_channel(self): """Test to ensure _force_voice_sync can create its own voice channel if one is not available.""" await self.cog._async_init() channel = MockVoiceChannel(guild=MockGuild(afk_channel=None)) new_channel = MockVoiceChannel(delete=AsyncMock()) channel.guild.create_voice_channel.return_value = new_channel await self.cog._force_voice_sync(channel) # Check channel creation overwrites = { channel.guild.default_role: PermissionOverwrite(speak=False, connect=False, view_channel=False) } channel.guild.create_voice_channel.assert_awaited_once_with("mute-temp", overwrites=overwrites) # Check bot deleted channel new_channel.delete.assert_awaited_once()
def test_server_info_command(self, time_since_patch): time_since_patch.return_value = '2 days ago' self.ctx.guild = MockGuild( features=('lemons', 'apples'), region="The Moon", roles=[self.moderator_role], channels=[ discord.TextChannel(state={}, guild=self.ctx.guild, data={ 'id': 42, 'name': 'lemons-offering', 'position': 22, 'type': 'text' }), discord.CategoryChannel(state={}, guild=self.ctx.guild, data={ 'id': 5125, 'name': 'the-lemon-collection', 'position': 22, 'type': 'category' }), discord.VoiceChannel(state={}, guild=self.ctx.guild, data={ 'id': 15290, 'name': 'listen-to-lemon', 'position': 22, 'type': 'voice' }) ], members=[ *(MockMember(status='online') for _ in range(2)), *(MockMember(status='idle') for _ in range(1)), *(MockMember(status='dnd') for _ in range(4)), *(MockMember(status='offline') for _ in range(3)), ], member_count=1_234, icon_url='a-lemon.jpg', ) coroutine = self.cog.server_info.callback(self.cog, self.ctx) self.assertIsNone(asyncio.run(coroutine)) time_since_patch.assert_called_once_with(self.ctx.guild.created_at, precision='days') _, kwargs = self.ctx.send.call_args embed = kwargs.pop('embed') self.assertEqual(embed.colour, discord.Colour.blurple()) self.assertEqual( embed.description, textwrap.dedent(f""" **Server information** Created: {time_since_patch.return_value} Voice region: {self.ctx.guild.region} Features: {', '.join(self.ctx.guild.features)} **Counts** Members: {self.ctx.guild.member_count:,} Roles: {len(self.ctx.guild.roles)} Text: 1 Voice: 1 Channel categories: 1 **Members** {constants.Emojis.status_online} 2 {constants.Emojis.status_idle} 1 {constants.Emojis.status_dnd} 4 {constants.Emojis.status_offline} 3 """)) self.assertEqual(embed.thumbnail.url, 'a-lemon.jpg')