Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 29 additions & 29 deletions tests/bot/cogs/test_information.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class InformationCogTests(unittest.TestCase):

@classmethod
def setUpClass(cls):
cls.moderator_role = helpers.MockRole(name="Moderator", role_id=constants.Roles.moderator)
cls.moderator_role = helpers.MockRole(name="Moderator", id=constants.Roles.moderator)

def setUp(self):
"""Sets up fresh objects for each test."""
Expand Down Expand Up @@ -54,7 +54,7 @@ def test_role_info_command(self):
"""Tests the `role info` command."""
dummy_role = helpers.MockRole(
name="Dummy",
role_id=112233445566778899,
id=112233445566778899,
colour=discord.Colour.blurple(),
position=10,
members=[self.ctx.author],
Expand All @@ -63,7 +63,7 @@ def test_role_info_command(self):

admin_role = helpers.MockRole(
name="Admins",
role_id=998877665544332211,
id=998877665544332211,
colour=discord.Colour.red(),
position=3,
members=[self.ctx.author],
Expand Down Expand Up @@ -176,7 +176,7 @@ def setUp(self):
self.bot = helpers.MockBot()
self.bot.api_client.get = helpers.AsyncMock()
self.cog = information.Information(self.bot)
self.member = helpers.MockMember(user_id=1234)
self.member = helpers.MockMember(id=1234)

def test_user_command_helper_method_get_requests(self):
"""The helper methods should form the correct get requests."""
Expand Down Expand Up @@ -351,7 +351,7 @@ def setUp(self):
@unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=helpers.AsyncMock(return_value=""))
def test_create_user_embed_uses_string_representation_of_user_in_title_if_nick_is_not_available(self):
"""The embed should use the string representation of the user if they don't have a nick."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(channel_id=1))
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=1))
user = helpers.MockMember()
user.nick = None
user.__str__ = unittest.mock.Mock(return_value="Mr. Hemlock")
Expand All @@ -363,7 +363,7 @@ def test_create_user_embed_uses_string_representation_of_user_in_title_if_nick_i
@unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=helpers.AsyncMock(return_value=""))
def test_create_user_embed_uses_nick_in_title_if_available(self):
"""The embed should use the nick if it's available."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(channel_id=1))
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=1))
user = helpers.MockMember()
user.nick = "Cat lover"
user.__str__ = unittest.mock.Mock(return_value="Mr. Hemlock")
Expand All @@ -375,8 +375,8 @@ def test_create_user_embed_uses_nick_in_title_if_available(self):
@unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new=helpers.AsyncMock(return_value=""))
def test_create_user_embed_ignores_everyone_role(self):
"""Created `!user` embeds should not contain mention of the @everyone-role."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(channel_id=1))
admins_role = helpers.MockRole('Admins')
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=1))
admins_role = helpers.MockRole(name='Admins')
admins_role.colour = 100

# A `MockMember` has the @Everyone role by default; we add the Admins to that.
Expand All @@ -391,15 +391,15 @@ def test_create_user_embed_ignores_everyone_role(self):
@unittest.mock.patch(f"{COG_PATH}.user_nomination_counts", new_callable=helpers.AsyncMock)
def test_create_user_embed_expanded_information_in_moderation_channels(self, nomination_counts, infraction_counts):
"""The embed should contain expanded infractions and nomination info in mod channels."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(channel_id=50))
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=50))

moderators_role = helpers.MockRole('Moderators')
moderators_role = helpers.MockRole(name='Moderators')
moderators_role.colour = 100

infraction_counts.return_value = "expanded infractions info"
nomination_counts.return_value = "nomination info"

user = helpers.MockMember(user_id=314, roles=[moderators_role], top_role=moderators_role)
user = helpers.MockMember(id=314, roles=[moderators_role], top_role=moderators_role)
embed = asyncio.run(self.cog.create_user_embed(ctx, user))

infraction_counts.assert_called_once_with(user)
Expand All @@ -426,14 +426,14 @@ def test_create_user_embed_expanded_information_in_moderation_channels(self, nom
@unittest.mock.patch(f"{COG_PATH}.basic_user_infraction_counts", new_callable=helpers.AsyncMock)
def test_create_user_embed_basic_information_outside_of_moderation_channels(self, infraction_counts):
"""The embed should contain only basic infraction data outside of mod channels."""
ctx = helpers.MockContext(channel=helpers.MockTextChannel(channel_id=100))
ctx = helpers.MockContext(channel=helpers.MockTextChannel(id=100))

moderators_role = helpers.MockRole('Moderators')
moderators_role = helpers.MockRole(name='Moderators')
moderators_role.colour = 100

infraction_counts.return_value = "basic infractions info"

user = helpers.MockMember(user_id=314, roles=[moderators_role], top_role=moderators_role)
user = helpers.MockMember(id=314, roles=[moderators_role], top_role=moderators_role)
embed = asyncio.run(self.cog.create_user_embed(ctx, user))

infraction_counts.assert_called_once_with(user)
Expand All @@ -459,10 +459,10 @@ def test_create_user_embed_uses_top_role_colour_when_user_has_roles(self):
"""The embed should be created with the colour of the top role, if a top role is available."""
ctx = helpers.MockContext()

moderators_role = helpers.MockRole('Moderators')
moderators_role = helpers.MockRole(name='Moderators')
moderators_role.colour = 100

user = helpers.MockMember(user_id=314, roles=[moderators_role], top_role=moderators_role)
user = helpers.MockMember(id=314, roles=[moderators_role], top_role=moderators_role)
embed = asyncio.run(self.cog.create_user_embed(ctx, user))

self.assertEqual(embed.colour, discord.Colour(moderators_role.colour))
Expand All @@ -472,7 +472,7 @@ def test_create_user_embed_uses_blurple_colour_when_user_has_no_roles(self):
"""The embed should be created with a blurple colour if the user has no assigned roles."""
ctx = helpers.MockContext()

user = helpers.MockMember(user_id=217)
user = helpers.MockMember(id=217)
embed = asyncio.run(self.cog.create_user_embed(ctx, user))

self.assertEqual(embed.colour, discord.Colour.blurple())
Expand All @@ -482,7 +482,7 @@ def test_create_user_embed_uses_png_format_of_user_avatar_as_thumbnail(self):
"""The embed thumbnail should be set to the user's avatar in `png` format."""
ctx = helpers.MockContext()

user = helpers.MockMember(user_id=217)
user = helpers.MockMember(id=217)
user.avatar_url_as.return_value = "avatar url"
embed = asyncio.run(self.cog.create_user_embed(ctx, user))

Expand All @@ -499,13 +499,13 @@ def setUp(self):
self.bot = helpers.MockBot()
self.cog = information.Information(self.bot)

self.moderator_role = helpers.MockRole("Moderators", role_id=2, position=10)
self.flautist_role = helpers.MockRole("Flautists", role_id=3, position=2)
self.bassist_role = helpers.MockRole("Bassists", role_id=4, position=3)
self.moderator_role = helpers.MockRole(name="Moderators", id=2, position=10)
self.flautist_role = helpers.MockRole(name="Flautists", id=3, position=2)
self.bassist_role = helpers.MockRole(name="Bassists", id=4, position=3)

self.author = helpers.MockMember(user_id=1, name="syntaxaire")
self.moderator = helpers.MockMember(user_id=2, name="riffautae", roles=[self.moderator_role])
self.target = helpers.MockMember(user_id=3, name="__fluzz__")
self.author = helpers.MockMember(id=1, name="syntaxaire")
self.moderator = helpers.MockMember(id=2, name="riffautae", roles=[self.moderator_role])
self.target = helpers.MockMember(id=3, name="__fluzz__")

def test_regular_member_cannot_target_another_member(self, constants):
"""A regular user should not be able to use `!user` targeting another user."""
Expand All @@ -523,7 +523,7 @@ def test_regular_member_cannot_use_command_outside_of_bot_commands(self, constan
constants.STAFF_ROLES = [self.moderator_role.id]
constants.Channels.bot = 50

ctx = helpers.MockContext(author=self.author, channel=helpers.MockTextChannel(channel_id=100))
ctx = helpers.MockContext(author=self.author, channel=helpers.MockTextChannel(id=100))

msg = "Sorry, but you may only use this command within <#50>."
with self.assertRaises(InChannelCheckFailure, msg=msg):
Expand All @@ -535,7 +535,7 @@ def test_regular_user_may_use_command_in_bot_commands_channel(self, create_embed
constants.STAFF_ROLES = [self.moderator_role.id]
constants.Channels.bot = 50

ctx = helpers.MockContext(author=self.author, channel=helpers.MockTextChannel(channel_id=50))
ctx = helpers.MockContext(author=self.author, channel=helpers.MockTextChannel(id=50))

asyncio.run(self.cog.user_info.callback(self.cog, ctx))

Expand All @@ -548,7 +548,7 @@ def test_regular_user_can_explicitly_target_themselves(self, create_embed, const
constants.STAFF_ROLES = [self.moderator_role.id]
constants.Channels.bot = 50

ctx = helpers.MockContext(author=self.author, channel=helpers.MockTextChannel(channel_id=50))
ctx = helpers.MockContext(author=self.author, channel=helpers.MockTextChannel(id=50))

asyncio.run(self.cog.user_info.callback(self.cog, ctx, self.author))

Expand All @@ -561,7 +561,7 @@ def test_staff_members_can_bypass_channel_restriction(self, create_embed, consta
constants.STAFF_ROLES = [self.moderator_role.id]
constants.Channels.bot = 50

ctx = helpers.MockContext(author=self.moderator, channel=helpers.MockTextChannel(channel_id=200))
ctx = helpers.MockContext(author=self.moderator, channel=helpers.MockTextChannel(id=200))

asyncio.run(self.cog.user_info.callback(self.cog, ctx))

Expand All @@ -574,7 +574,7 @@ def test_moderators_can_target_another_member(self, create_embed, constants):
constants.MODERATION_ROLES = [self.moderator_role.id]
constants.STAFF_ROLES = [self.moderator_role.id]

ctx = helpers.MockContext(author=self.moderator, channel=helpers.MockTextChannel(channel_id=50))
ctx = helpers.MockContext(author=self.moderator, channel=helpers.MockTextChannel(id=50))

asyncio.run(self.cog.user_info.callback(self.cog, ctx, self.target))

Expand Down
2 changes: 1 addition & 1 deletion tests/bot/cogs/test_token_remover.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def setUp(self):
self.bot.get_cog.return_value.send_log_message = AsyncMock()
self.cog = TokenRemover(bot=self.bot)

self.msg = MockMessage(message_id=555, content='')
self.msg = MockMessage(id=555, content='')
self.msg.author.__str__ = MagicMock()
self.msg.author.__str__.return_value = 'lemon'
self.msg.author.bot = False
Expand Down
4 changes: 3 additions & 1 deletion tests/bot/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,9 @@ def test_schedule_queued_tasks_for_empty_queue(self):

def test_schedule_queued_tasks_for_nonempty_queue(self):
"""`APILoggingHandler` should schedule logs when the queue is not empty."""
with self.assertLogs(level=logging.DEBUG) as logs, patch('asyncio.create_task') as create_task:
log = logging.getLogger("bot.api")

with self.assertLogs(logger=log, level=logging.DEBUG) as logs, patch('asyncio.create_task') as create_task:
self.log_handler.queue = [555]
self.log_handler.schedule_queued_tasks()
self.assertListEqual(self.log_handler.queue, [])
Expand Down
6 changes: 3 additions & 3 deletions tests/bot/utils/test_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_with_role_check_without_required_roles(self):

def test_with_role_check_with_guild_and_required_role(self):
"""`with_role_check` returns `True` if `Context.author` has the required role."""
self.ctx.author.roles.append(MockRole(role_id=10))
self.ctx.author.roles.append(MockRole(id=10))
self.assertTrue(checks.with_role_check(self.ctx, 10))

def test_without_role_check_without_guild(self):
Expand All @@ -33,13 +33,13 @@ def test_without_role_check_without_guild(self):
def test_without_role_check_returns_false_with_unwanted_role(self):
"""`without_role_check` returns `False` if `Context.author` has unwanted role."""
role_id = 42
self.ctx.author.roles.append(MockRole(role_id=role_id))
self.ctx.author.roles.append(MockRole(id=role_id))
self.assertFalse(checks.without_role_check(self.ctx, role_id))

def test_without_role_check_returns_true_without_unwanted_role(self):
"""`without_role_check` returns `True` if `Context.author` does not have unwanted role."""
role_id = 42
self.ctx.author.roles.append(MockRole(role_id=role_id))
self.ctx.author.roles.append(MockRole(id=role_id))
self.assertTrue(checks.without_role_check(self.ctx, role_id + 10))

def test_in_channel_check_for_correct_channel(self):
Expand Down
Loading