aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar MarkKoz <[email protected]>2020-08-12 14:31:56 -0700
committerGravatar MarkKoz <[email protected]>2020-08-14 09:28:29 -0700
commitb224d46d68699ece3382cd333df7ede9e9a62e02 (patch)
tree19fd922392df349fb3d5412a3baeaf03fe57b70c
parentMove extensions into sub-directories (diff)
Restructure tests and fix broken tests
The cog tests structure should mirror the structure of the cogs folder. Fix some import/patch paths which broke due to the restructure.
-rw-r--r--tests/bot/cogs/backend/__init__.py (renamed from tests/bot/cogs/sync/__init__.py)0
-rw-r--r--tests/bot/cogs/backend/sync/__init__.py0
-rw-r--r--tests/bot/cogs/backend/sync/test_base.py (renamed from tests/bot/cogs/sync/test_base.py)2
-rw-r--r--tests/bot/cogs/backend/sync/test_cog.py (renamed from tests/bot/cogs/sync/test_cog.py)8
-rw-r--r--tests/bot/cogs/backend/sync/test_roles.py (renamed from tests/bot/cogs/sync/test_roles.py)2
-rw-r--r--tests/bot/cogs/backend/sync/test_users.py (renamed from tests/bot/cogs/sync/test_users.py)2
-rw-r--r--tests/bot/cogs/backend/test_logging.py (renamed from tests/bot/cogs/test_logging.py)6
-rw-r--r--tests/bot/cogs/filters/__init__.py0
-rw-r--r--tests/bot/cogs/filters/test_antimalware.py (renamed from tests/bot/cogs/test_antimalware.py)0
-rw-r--r--tests/bot/cogs/filters/test_antispam.py (renamed from tests/bot/cogs/test_antispam.py)0
-rw-r--r--tests/bot/cogs/filters/test_security.py (renamed from tests/bot/cogs/test_security.py)0
-rw-r--r--tests/bot/cogs/filters/test_token_remover.py (renamed from tests/bot/cogs/test_token_remover.py)16
-rw-r--r--tests/bot/cogs/info/__init__.py0
-rw-r--r--tests/bot/cogs/info/test_information.py (renamed from tests/bot/cogs/test_information.py)18
-rw-r--r--tests/bot/cogs/moderation/infraction/__init__.py0
-rw-r--r--tests/bot/cogs/moderation/infraction/test_infractions.py (renamed from tests/bot/cogs/moderation/test_infractions.py)6
-rw-r--r--tests/bot/cogs/moderation/test_incidents.py4
-rw-r--r--tests/bot/cogs/moderation/test_slowmode.py (renamed from tests/bot/cogs/test_slowmode.py)0
-rw-r--r--tests/bot/cogs/utils/__init__.py0
-rw-r--r--tests/bot/cogs/utils/test_jams.py (renamed from tests/bot/cogs/test_jams.py)2
-rw-r--r--tests/bot/cogs/utils/test_snekbox.py (renamed from tests/bot/cogs/test_snekbox.py)8
21 files changed, 37 insertions, 37 deletions
diff --git a/tests/bot/cogs/sync/__init__.py b/tests/bot/cogs/backend/__init__.py
index e69de29bb..e69de29bb 100644
--- a/tests/bot/cogs/sync/__init__.py
+++ b/tests/bot/cogs/backend/__init__.py
diff --git a/tests/bot/cogs/backend/sync/__init__.py b/tests/bot/cogs/backend/sync/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/bot/cogs/backend/sync/__init__.py
diff --git a/tests/bot/cogs/sync/test_base.py b/tests/bot/cogs/backend/sync/test_base.py
index 84d036405..0d0a8299d 100644
--- a/tests/bot/cogs/sync/test_base.py
+++ b/tests/bot/cogs/backend/sync/test_base.py
@@ -6,7 +6,7 @@ import discord
from bot import constants
from bot.api import ResponseCodeError
-from bot.cogs.backend.sync import Syncer, _Diff
+from bot.cogs.backend.sync.syncers import Syncer, _Diff
from tests import helpers
diff --git a/tests/bot/cogs/sync/test_cog.py b/tests/bot/cogs/backend/sync/test_cog.py
index ea7d090ba..199747051 100644
--- a/tests/bot/cogs/sync/test_cog.py
+++ b/tests/bot/cogs/backend/sync/test_cog.py
@@ -6,7 +6,7 @@ import discord
from bot import constants
from bot.api import ResponseCodeError
from bot.cogs.backend import sync
-from bot.cogs.backend.sync import Syncer
+from bot.cogs.backend.sync.syncers import Syncer
from tests import helpers
from tests.base import CommandTestCase
@@ -29,12 +29,12 @@ class SyncCogTestCase(unittest.IsolatedAsyncioTestCase):
self.bot = helpers.MockBot()
self.role_syncer_patcher = mock.patch(
- "bot.cogs.sync.syncers.RoleSyncer",
+ "bot.cogs.backend.sync.syncers.RoleSyncer",
autospec=Syncer,
spec_set=True
)
self.user_syncer_patcher = mock.patch(
- "bot.cogs.sync.syncers.UserSyncer",
+ "bot.cogs.backend.sync.syncers.UserSyncer",
autospec=Syncer,
spec_set=True
)
@@ -131,7 +131,7 @@ class SyncCogListenerTests(SyncCogTestCase):
super().setUp()
self.cog.patch_user = mock.AsyncMock(spec_set=self.cog.patch_user)
- self.guild_id_patcher = mock.patch("bot.cogs.sync.cog.constants.Guild.id", 5)
+ self.guild_id_patcher = mock.patch("bot.cogs.backend.sync.cog.constants.Guild.id", 5)
self.guild_id = self.guild_id_patcher.start()
self.guild = helpers.MockGuild(id=self.guild_id)
diff --git a/tests/bot/cogs/sync/test_roles.py b/tests/bot/cogs/backend/sync/test_roles.py
index 888c49ca8..cc2e51c7f 100644
--- a/tests/bot/cogs/sync/test_roles.py
+++ b/tests/bot/cogs/backend/sync/test_roles.py
@@ -3,7 +3,7 @@ from unittest import mock
import discord
-from bot.cogs.backend.sync import RoleSyncer, _Diff, _Role
+from bot.cogs.backend.sync.syncers import RoleSyncer, _Diff, _Role
from tests import helpers
diff --git a/tests/bot/cogs/sync/test_users.py b/tests/bot/cogs/backend/sync/test_users.py
index 71f4b134c..490ea9e06 100644
--- a/tests/bot/cogs/sync/test_users.py
+++ b/tests/bot/cogs/backend/sync/test_users.py
@@ -1,7 +1,7 @@
import unittest
from unittest import mock
-from bot.cogs.backend.sync import UserSyncer, _Diff, _User
+from bot.cogs.backend.sync.syncers import UserSyncer, _Diff, _User
from tests import helpers
diff --git a/tests/bot/cogs/test_logging.py b/tests/bot/cogs/backend/test_logging.py
index 8a18fdcd6..c867773e2 100644
--- a/tests/bot/cogs/test_logging.py
+++ b/tests/bot/cogs/backend/test_logging.py
@@ -2,7 +2,7 @@ import unittest
from unittest.mock import patch
from bot import constants
-from bot.cogs.logging import Logging
+from bot.cogs.backend.logging import Logging
from tests.helpers import MockBot, MockTextChannel
@@ -14,7 +14,7 @@ class LoggingTests(unittest.IsolatedAsyncioTestCase):
self.cog = Logging(self.bot)
self.dev_log = MockTextChannel(id=1234, name="dev-log")
- @patch("bot.cogs.logging.DEBUG_MODE", False)
+ @patch("bot.cogs.backend.logging.DEBUG_MODE", False)
async def test_debug_mode_false(self):
"""Should send connected message to dev-log."""
self.bot.get_channel.return_value = self.dev_log
@@ -24,7 +24,7 @@ class LoggingTests(unittest.IsolatedAsyncioTestCase):
self.bot.get_channel.assert_called_once_with(constants.Channels.dev_log)
self.dev_log.send.assert_awaited_once()
- @patch("bot.cogs.logging.DEBUG_MODE", True)
+ @patch("bot.cogs.backend.logging.DEBUG_MODE", True)
async def test_debug_mode_true(self):
"""Should not send anything to dev-log."""
await self.cog.startup_greeting()
diff --git a/tests/bot/cogs/filters/__init__.py b/tests/bot/cogs/filters/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/bot/cogs/filters/__init__.py
diff --git a/tests/bot/cogs/test_antimalware.py b/tests/bot/cogs/filters/test_antimalware.py
index b00211f47..b00211f47 100644
--- a/tests/bot/cogs/test_antimalware.py
+++ b/tests/bot/cogs/filters/test_antimalware.py
diff --git a/tests/bot/cogs/test_antispam.py b/tests/bot/cogs/filters/test_antispam.py
index 8a3d8d02e..8a3d8d02e 100644
--- a/tests/bot/cogs/test_antispam.py
+++ b/tests/bot/cogs/filters/test_antispam.py
diff --git a/tests/bot/cogs/test_security.py b/tests/bot/cogs/filters/test_security.py
index 82679f69c..82679f69c 100644
--- a/tests/bot/cogs/test_security.py
+++ b/tests/bot/cogs/filters/test_security.py
diff --git a/tests/bot/cogs/test_token_remover.py b/tests/bot/cogs/filters/test_token_remover.py
index e33f3af38..5c527ed94 100644
--- a/tests/bot/cogs/test_token_remover.py
+++ b/tests/bot/cogs/filters/test_token_remover.py
@@ -132,7 +132,7 @@ class TokenRemoverTests(unittest.IsolatedAsyncioTestCase):
await cog.on_message(msg)
find_token_in_message.assert_not_called()
- @autospec("bot.cogs.token_remover", "TOKEN_RE")
+ @autospec("bot.cogs.filters.token_remover", "TOKEN_RE")
def test_find_token_no_matches(self, token_re):
"""None should be returned if the regex matches no tokens in a message."""
token_re.finditer.return_value = ()
@@ -143,8 +143,8 @@ class TokenRemoverTests(unittest.IsolatedAsyncioTestCase):
token_re.finditer.assert_called_once_with(self.msg.content)
@autospec(TokenRemover, "is_valid_user_id", "is_valid_timestamp")
- @autospec("bot.cogs.token_remover", "Token")
- @autospec("bot.cogs.token_remover", "TOKEN_RE")
+ @autospec("bot.cogs.filters.token_remover", "Token")
+ @autospec("bot.cogs.filters.token_remover", "TOKEN_RE")
def test_find_token_valid_match(self, token_re, token_cls, is_valid_id, is_valid_timestamp):
"""The first match with a valid user ID and timestamp should be returned as a `Token`."""
matches = [
@@ -167,8 +167,8 @@ class TokenRemoverTests(unittest.IsolatedAsyncioTestCase):
token_re.finditer.assert_called_once_with(self.msg.content)
@autospec(TokenRemover, "is_valid_user_id", "is_valid_timestamp")
- @autospec("bot.cogs.token_remover", "Token")
- @autospec("bot.cogs.token_remover", "TOKEN_RE")
+ @autospec("bot.cogs.filters.token_remover", "Token")
+ @autospec("bot.cogs.filters.token_remover", "TOKEN_RE")
def test_find_token_invalid_matches(self, token_re, token_cls, is_valid_id, is_valid_timestamp):
"""None should be returned if no matches have valid user IDs or timestamps."""
token_re.finditer.return_value = [mock.create_autospec(Match, spec_set=True, instance=True)]
@@ -230,7 +230,7 @@ class TokenRemoverTests(unittest.IsolatedAsyncioTestCase):
results = [match[0] for match in results]
self.assertCountEqual((token_1, token_2), results)
- @autospec("bot.cogs.token_remover", "LOG_MESSAGE")
+ @autospec("bot.cogs.filters.token_remover", "LOG_MESSAGE")
def test_format_log_message(self, log_message):
"""Should correctly format the log message with info from the message and token."""
token = Token("NDY3MjIzMjMwNjUwNzc3NjQx", "XsySD_", "s45jqDV_Iisn-symw0yDRrk_jf4")
@@ -249,7 +249,7 @@ class TokenRemoverTests(unittest.IsolatedAsyncioTestCase):
)
@mock.patch.object(TokenRemover, "mod_log", new_callable=mock.PropertyMock)
- @autospec("bot.cogs.token_remover", "log")
+ @autospec("bot.cogs.filters.token_remover", "log")
@autospec(TokenRemover, "format_log_message")
async def test_take_action(self, format_log_message, logger, mod_log_property):
"""Should delete the message and send a mod log."""
@@ -299,7 +299,7 @@ class TokenRemoverTests(unittest.IsolatedAsyncioTestCase):
class TokenRemoverExtensionTests(unittest.TestCase):
"""Tests for the token_remover extension."""
- @autospec("bot.cogs.token_remover", "TokenRemover")
+ @autospec("bot.cogs.filters.token_remover", "TokenRemover")
def test_extension_setup(self, cog):
"""The TokenRemover cog should be added."""
bot = MockBot()
diff --git a/tests/bot/cogs/info/__init__.py b/tests/bot/cogs/info/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/bot/cogs/info/__init__.py
diff --git a/tests/bot/cogs/test_information.py b/tests/bot/cogs/info/test_information.py
index 305a2bad9..895a8328e 100644
--- a/tests/bot/cogs/test_information.py
+++ b/tests/bot/cogs/info/test_information.py
@@ -10,7 +10,7 @@ from bot.cogs.info import information
from bot.utils.checks import InWhitelistCheckFailure
from tests import helpers
-COG_PATH = "bot.cogs.information.Information"
+COG_PATH = "bot.cogs.info.information.Information"
class InformationCogTests(unittest.TestCase):
@@ -97,7 +97,7 @@ class InformationCogTests(unittest.TestCase):
self.assertEqual(admin_embed.title, "Admins info")
self.assertEqual(admin_embed.colour, discord.Colour.red())
- @unittest.mock.patch('bot.cogs.information.time_since')
+ @unittest.mock.patch('bot.cogs.info.information.time_since')
def test_server_info_command(self, time_since_patch):
time_since_patch.return_value = '2 days ago'
@@ -339,8 +339,8 @@ class UserInfractionHelperMethodTests(unittest.TestCase):
self._method_subtests(self.cog.user_nomination_counts, test_values, header)
[email protected]("bot.cogs.information.time_since", new=unittest.mock.MagicMock(return_value="1 year ago"))
[email protected]("bot.cogs.information.constants.MODERATION_CHANNELS", new=[50])
[email protected]("bot.cogs.info.information.time_since", new=unittest.mock.MagicMock(return_value="1 year ago"))
[email protected]("bot.cogs.info.information.constants.MODERATION_CHANNELS", new=[50])
class UserEmbedTests(unittest.TestCase):
"""Tests for the creation of the `!user` embed."""
@@ -492,7 +492,7 @@ class UserEmbedTests(unittest.TestCase):
self.assertEqual(embed.thumbnail.url, "avatar url")
[email protected]("bot.cogs.information.constants")
[email protected]("bot.cogs.info.information.constants")
class UserCommandTests(unittest.TestCase):
"""Tests for the `!user` command."""
@@ -531,7 +531,7 @@ class UserCommandTests(unittest.TestCase):
with self.assertRaises(InWhitelistCheckFailure, msg=msg):
asyncio.run(self.cog.user_info.callback(self.cog, ctx))
- @unittest.mock.patch("bot.cogs.information.Information.create_user_embed", new_callable=unittest.mock.AsyncMock)
+ @unittest.mock.patch("bot.cogs.info.information.Information.create_user_embed")
def test_regular_user_may_use_command_in_bot_commands_channel(self, create_embed, constants):
"""A regular user should be allowed to use `!user` targeting themselves in bot-commands."""
constants.STAFF_ROLES = [self.moderator_role.id]
@@ -544,7 +544,7 @@ class UserCommandTests(unittest.TestCase):
create_embed.assert_called_once_with(ctx, self.author)
ctx.send.assert_called_once()
- @unittest.mock.patch("bot.cogs.information.Information.create_user_embed", new_callable=unittest.mock.AsyncMock)
+ @unittest.mock.patch("bot.cogs.info.information.Information.create_user_embed")
def test_regular_user_can_explicitly_target_themselves(self, create_embed, constants):
"""A user should target itself with `!user` when a `user` argument was not provided."""
constants.STAFF_ROLES = [self.moderator_role.id]
@@ -557,7 +557,7 @@ class UserCommandTests(unittest.TestCase):
create_embed.assert_called_once_with(ctx, self.author)
ctx.send.assert_called_once()
- @unittest.mock.patch("bot.cogs.information.Information.create_user_embed", new_callable=unittest.mock.AsyncMock)
+ @unittest.mock.patch("bot.cogs.info.information.Information.create_user_embed")
def test_staff_members_can_bypass_channel_restriction(self, create_embed, constants):
"""Staff members should be able to bypass the bot-commands channel restriction."""
constants.STAFF_ROLES = [self.moderator_role.id]
@@ -570,7 +570,7 @@ class UserCommandTests(unittest.TestCase):
create_embed.assert_called_once_with(ctx, self.moderator)
ctx.send.assert_called_once()
- @unittest.mock.patch("bot.cogs.information.Information.create_user_embed", new_callable=unittest.mock.AsyncMock)
+ @unittest.mock.patch("bot.cogs.info.information.Information.create_user_embed")
def test_moderators_can_target_another_member(self, create_embed, constants):
"""A moderator should be able to use `!user` targeting another user."""
constants.MODERATION_ROLES = [self.moderator_role.id]
diff --git a/tests/bot/cogs/moderation/infraction/__init__.py b/tests/bot/cogs/moderation/infraction/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/bot/cogs/moderation/infraction/__init__.py
diff --git a/tests/bot/cogs/moderation/test_infractions.py b/tests/bot/cogs/moderation/infraction/test_infractions.py
index df38090fb..a79042557 100644
--- a/tests/bot/cogs/moderation/test_infractions.py
+++ b/tests/bot/cogs/moderation/infraction/test_infractions.py
@@ -17,8 +17,8 @@ class TruncationTests(unittest.IsolatedAsyncioTestCase):
self.guild = MockGuild(id=4567)
self.ctx = MockContext(bot=self.bot, author=self.user, guild=self.guild)
- @patch("bot.cogs.moderation.utils.get_active_infraction")
- @patch("bot.cogs.moderation.utils.post_infraction")
+ @patch("bot.cogs.moderation.infraction.utils.get_active_infraction")
+ @patch("bot.cogs.moderation.infraction.utils.post_infraction")
async def test_apply_ban_reason_truncation(self, post_infraction_mock, get_active_mock):
"""Should truncate reason for `ctx.guild.ban`."""
get_active_mock.return_value = None
@@ -39,7 +39,7 @@ class TruncationTests(unittest.IsolatedAsyncioTestCase):
self.ctx, {"foo": "bar"}, self.target, self.ctx.guild.ban.return_value
)
- @patch("bot.cogs.moderation.utils.post_infraction")
+ @patch("bot.cogs.moderation.infraction.utils.post_infraction")
async def test_apply_kick_reason_truncation(self, post_infraction_mock):
"""Should truncate reason for `Member.kick`."""
post_infraction_mock.return_value = {"foo": "bar"}
diff --git a/tests/bot/cogs/moderation/test_incidents.py b/tests/bot/cogs/moderation/test_incidents.py
index 435a1cd51..5e4d90251 100644
--- a/tests/bot/cogs/moderation/test_incidents.py
+++ b/tests/bot/cogs/moderation/test_incidents.py
@@ -8,7 +8,7 @@ from unittest.mock import AsyncMock, MagicMock, call, patch
import aiohttp
import discord
-from bot.cogs.moderation import Incidents, incidents
+from bot.cogs.moderation import incidents
from bot.constants import Colours
from tests.helpers import (
MockAsyncWebhook,
@@ -290,7 +290,7 @@ class TestIncidents(unittest.IsolatedAsyncioTestCase):
Note that this will not schedule `crawl_incidents` in the background, as everything
is being mocked. The `crawl_task` attribute will end up being None.
"""
- self.cog_instance = Incidents(MockBot())
+ self.cog_instance = incidents.Incidents(MockBot())
@patch("asyncio.sleep", AsyncMock()) # Prevent the coro from sleeping to speed up the test
diff --git a/tests/bot/cogs/test_slowmode.py b/tests/bot/cogs/moderation/test_slowmode.py
index f442814c8..f442814c8 100644
--- a/tests/bot/cogs/test_slowmode.py
+++ b/tests/bot/cogs/moderation/test_slowmode.py
diff --git a/tests/bot/cogs/utils/__init__.py b/tests/bot/cogs/utils/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/tests/bot/cogs/utils/__init__.py
diff --git a/tests/bot/cogs/test_jams.py b/tests/bot/cogs/utils/test_jams.py
index b4ad8535f..299f436ba 100644
--- a/tests/bot/cogs/test_jams.py
+++ b/tests/bot/cogs/utils/test_jams.py
@@ -3,7 +3,7 @@ from unittest.mock import AsyncMock, MagicMock, create_autospec
from discord import CategoryChannel
-from bot.cogs import jams
+from bot.cogs.utils import jams
from bot.constants import Roles
from tests.helpers import MockBot, MockContext, MockGuild, MockMember, MockRole, MockTextChannel
diff --git a/tests/bot/cogs/test_snekbox.py b/tests/bot/cogs/utils/test_snekbox.py
index c7bac3ab3..3e447f319 100644
--- a/tests/bot/cogs/test_snekbox.py
+++ b/tests/bot/cogs/utils/test_snekbox.py
@@ -68,7 +68,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
context_manager.__aenter__.return_value = resp
self.bot.http_session.post.return_value = context_manager
- log = logging.getLogger("bot.cogs.snekbox")
+ log = logging.getLogger("bot.cogs.utils.snekbox")
with self.assertLogs(logger=log, level='ERROR'):
await self.cog.upload_output('My awesome output!')
@@ -99,14 +99,14 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
actual = self.cog.get_results_message({'stdout': stdout, 'returncode': returncode})
self.assertEqual(actual, expected)
- @patch('bot.cogs.snekbox.Signals', side_effect=ValueError)
+ @patch('bot.cogs.utils.snekbox.Signals', side_effect=ValueError)
def test_get_results_message_invalid_signal(self, mock_signals: Mock):
self.assertEqual(
self.cog.get_results_message({'stdout': '', 'returncode': 127}),
('Your eval job has completed with return code 127', '')
)
- @patch('bot.cogs.snekbox.Signals')
+ @patch('bot.cogs.utils.snekbox.Signals')
def test_get_results_message_valid_signal(self, mock_signals: Mock):
mock_signals.return_value.name = 'SIGTEST'
self.assertEqual(
@@ -296,7 +296,7 @@ class SnekboxTests(unittest.IsolatedAsyncioTestCase):
self.cog.get_results_message.assert_called_once_with({'stdout': 'ERROR', 'returncode': 127})
self.cog.format_output.assert_not_called()
- @patch("bot.cogs.snekbox.partial")
+ @patch("bot.cogs.utils.snekbox.partial")
async def test_continue_eval_does_continue(self, partial_mock):
"""Test that the continue_eval function does continue if required conditions are met."""
ctx = MockContext(message=MockMessage(add_reaction=AsyncMock(), clear_reactions=AsyncMock()))