Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more tests #115

Draft
wants to merge 75 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
b851139
Add more tests, fix exception class properties & begin to split Env v…
CarrotManMatt Dec 24, 2023
a16e3b9
Fix database imports
CarrotManMatt Dec 24, 2023
f015de6
Improve config Env variable setup
CarrotManMatt Dec 24, 2023
1b28ba8
Fix exception repr
CarrotManMatt Dec 24, 2023
36f9f93
Fix testing exception repr
CarrotManMatt Dec 24, 2023
687ae06
Fix `SuppressTraceback` context manager exiting incorrectly after exc…
CarrotManMatt Dec 24, 2023
9855547
Fix exception names
CarrotManMatt Dec 25, 2023
fbfab83
Fix exception message generation
CarrotManMatt Dec 25, 2023
bc078a0
Add more exception tests
CarrotManMatt Dec 25, 2023
eacb9c2
Add config tests
CarrotManMatt Dec 26, 2023
45ae77c
Add more config tests & fix some variable's lifespan
CarrotManMatt Dec 26, 2023
b901d6f
Fix config test `test_cannot_setup_multiple_times`
CarrotManMatt Dec 26, 2023
7444492
Move `EnvVariableDeleter` context-manager to utils scope
CarrotManMatt Dec 27, 2023
8fabfa8
Fix single instance enforcement of `settings` for custom classes in t…
CarrotManMatt Dec 27, 2023
42ac671
Fix using root logger (moved to using name-spaced logger instead)
CarrotManMatt Dec 27, 2023
ebe46a2
Add more tests in `test_config.py`
CarrotManMatt Dec 27, 2023
7bfd734
Fix import errors
CarrotManMatt Dec 27, 2023
f7325b3
Fix ruff linting issues
CarrotManMatt Dec 27, 2023
18829b8
Add more config tests in `test_config.py`
CarrotManMatt Dec 28, 2023
1559de6
Merge branch 'main' into 57-add-tests
CarrotManMatt Dec 28, 2023
4c84d82
Merge remote-tracking branch 'origin/main' into 57-add-tests
CarrotManMatt Dec 28, 2023
4bf1aad
Fix import & name reference errors
CarrotManMatt Dec 28, 2023
750fb5c
Fix not every setup method called
CarrotManMatt Dec 28, 2023
901bf59
Fix small errors
CarrotManMatt Dec 28, 2023
7c4da00
Merge remote-tracking branch 'origin/main' into 57-add-tests
CarrotManMatt Jan 4, 2024
cab7819
Re-add 3rd party `classproperties library`
CarrotManMatt Jan 4, 2024
59dc29f
Merge remote-tracking branch 'origin/main' into 57-add-tests
CarrotManMatt Jan 5, 2024
84c65dd
Merge branch 'main' into 57-add-tests
CarrotManMatt Jan 5, 2024
b707d7f
Fix incorrect `.lock` file
CarrotManMatt Jan 5, 2024
a66e9db
Merge branch 'main' into 57-add-tests
CarrotManMatt Jan 5, 2024
794ec1b
Improve default Env variable values handling & extra whitespace
CarrotManMatt Jan 6, 2024
6513fed
Merge remote-tracking branch 'origin/main' into 57-add-tests
CarrotManMatt Jan 6, 2024
42d37b9
Fix unknown reference `argparse._SubParserAction`
CarrotManMatt Jan 6, 2024
04556c5
Fix import linting errors
CarrotManMatt Jan 6, 2024
d9d3f0d
Improve stripping whitespace from Env variables & default value guara…
CarrotManMatt Jan 7, 2024
2d92c06
Improve Env variables regex
CarrotManMatt Jan 7, 2024
1da1051
Add more tests & fix GROUP_NAME regex
CarrotManMatt Jan 8, 2024
067c66f
Add more tests & fix URL validation
CarrotManMatt Jan 9, 2024
51ff477
Add messages file tests
CarrotManMatt Jan 9, 2024
8871865
Add more tests
CarrotManMatt Jan 9, 2024
9423be1
Add more tests
CarrotManMatt Jan 9, 2024
53360e5
Add more tests
CarrotManMatt Jan 10, 2024
1921df1
Add more tests
CarrotManMatt Jan 11, 2024
f1f7ce7
Add final tests to `test_config.py`
CarrotManMatt Jan 12, 2024
17a88be
Merge branch 'main' into 57-add-tests
CarrotManMatt Jan 12, 2024
9b611d0
Merge remote-tracking branch 'origin/main' into 57-add-tests
CarrotManMatt Jan 13, 2024
a6a4569
Fix `.lock` file hash
CarrotManMatt Jan 13, 2024
161d239
Merge remote-tracking branch 'origin/main' into 57-add-tests
CarrotManMatt Jan 13, 2024
7373e7c
Fix `.lock` file
CarrotManMatt Jan 13, 2024
37c5c16
Merge remote-tracking branch 'origin/main' into 57-add-tests
CarrotManMatt Jan 14, 2024
2a6e410
Use runtime type constructor for settings class
CarrotManMatt Jan 14, 2024
c59c810
Merge branch 'main' into 57-add-tests
CarrotManMatt Jan 16, 2024
7e6f7b0
Add the first few stats test & some more config tests
CarrotManMatt Jan 16, 2024
1870eb8
Fix ruff linting issues
CarrotManMatt Jan 16, 2024
42c7c86
Add `BUG` note
CarrotManMatt Jan 16, 2024
348eed3
Add default Env variable values for tests
CarrotManMatt Jan 19, 2024
9773c56
Merge branch 'main' into 57-add-tests
CarrotManMatt Jan 19, 2024
45553d0
Add docstrings
CarrotManMatt Jan 20, 2024
deca470
Make cog commands executable in tests
CarrotManMatt Jan 20, 2024
5f9ae46
Fix typing & linting errors
CarrotManMatt Jan 20, 2024
0025728
Make command executable from abstract base class
CarrotManMatt Jan 21, 2024
2ea45d9
Fix asyncio event loop handling
CarrotManMatt Jan 22, 2024
890a1e7
Make application context instance creation a test fixture
CarrotManMatt Jan 23, 2024
cf0510d
Add handler to root logger rather than `texbot` logger
CarrotManMatt Jan 24, 2024
4949e9f
Fix unnecessary uses of `@staticmethod` & `@classmethod`
CarrotManMatt Jan 24, 2024
fcafba2
Improve logging format
CarrotManMatt Jan 25, 2024
b7d3f84
Merge branch 'main' into 57-add-tests
CarrotManMatt Feb 6, 2024
ce286bb
Merge remote-tracking branch 'refs/remotes/origin/main' into 57-add-t…
CarrotManMatt Apr 24, 2024
a30127d
Remove unnecessary tests & fix linting errors
CarrotManMatt Apr 24, 2024
329a675
Merge 'origin/main' into 57-add-tests
CarrotManMatt May 3, 2024
6008d7a
Merge remote-tracking branch 'refs/remotes/origin/main' into 57-add-t…
CarrotManMatt May 9, 2024
9fc6506
Merge branch 'main' into 57-add-tests
CarrotManMatt May 11, 2024
7de3ca9
Merge branch 'refs/heads/main' into 57-add-tests
CarrotManMatt May 11, 2024
09c4934
Merge remote-tracking branch 'refs/remotes/origin/main' into 57-add-t…
CarrotManMatt May 15, 2024
0da2fc2
Update dependencies
CarrotManMatt May 15, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,4 @@ local/
*.sqlite3
*.db
local_stubs/
*.*-invalid
4 changes: 2 additions & 2 deletions cogs/archive.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
class ArchiveCommandCog(TeXBotBaseCog):
"""Cog class that defines the "/archive" command and its call-back method."""

@staticmethod
async def autocomplete_get_categories(ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
@classmethod
async def autocomplete_get_categories(cls, ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
"""
Autocomplete callable that generates the set of available selectable categories.

Expand Down
4 changes: 2 additions & 2 deletions cogs/delete_all.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ class DeleteAllCommandsCog(TeXBotBaseCog):
"Delete all instances of the selected object type from the backend database",
)

@staticmethod
async def _delete_all(ctx: TeXBotApplicationContext, delete_model: type[AsyncBaseModel]) -> None: # noqa: E501
@classmethod
async def _delete_all(cls, ctx: TeXBotApplicationContext, delete_model: type[AsyncBaseModel]) -> None: # noqa: E501
"""Perform the actual deletion process of all instances of the given model class."""
# noinspection PyProtectedMember
await delete_model._default_manager.all().adelete()
Expand Down
4 changes: 2 additions & 2 deletions cogs/edit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class EditMessageCommandCog(TeXBotBaseCog):
# noinspection SpellCheckingInspection
"""Cog class that defines the "/editmessage" command and its call-back method."""

@staticmethod
async def autocomplete_get_text_channels(ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
@classmethod
async def autocomplete_get_text_channels(cls, ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
"""
Autocomplete callable that generates the set of available selectable channels.

Expand Down
19 changes: 17 additions & 2 deletions cogs/induct.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@


import contextlib
import logging
import random
import re
from logging import Logger
from typing import Literal

import discord
Expand All @@ -36,6 +38,8 @@
)
from utils.error_capture_decorators import capture_guild_does_not_exist_error

logger: Logger = logging.getLogger("texbot")


class InductSendMessageCog(TeXBotBaseCog):
"""Cog class that defines the "/induct" command and its call-back method."""
Expand Down Expand Up @@ -143,6 +147,8 @@ async def get_random_welcome_message(self, induction_member: discord.User | disc

if "<User>" in random_welcome_message:
if not induction_member:
logger.warning("No user provided, when retrieving a random welcome message.")

return await self.get_random_welcome_message(induction_member)

random_welcome_message = random_welcome_message.replace(
Expand All @@ -154,6 +160,10 @@ async def get_random_welcome_message(self, induction_member: discord.User | disc
try:
committee_role_mention: str = (await self.bot.committee_role).mention
except CommitteeRoleDoesNotExistError:
logger.warning(
"Committee role does not exist, when retrieving a random welcome message.",
)

return await self.get_random_welcome_message(induction_member)
else:
random_welcome_message = random_welcome_message.replace(
Expand All @@ -163,6 +173,11 @@ async def get_random_welcome_message(self, induction_member: discord.User | disc

if "<Purchase_Membership_URL>" in random_welcome_message:
if not settings["PURCHASE_MEMBERSHIP_URL"]:
logger.warning(
"Env variable `PURCHASE_MEMBERSHIP_URL` is not set, "
"when retrieving a random welcome message.",
)

return await self.get_random_welcome_message(induction_member)

random_welcome_message = random_welcome_message.replace(
Expand Down Expand Up @@ -263,8 +278,8 @@ async def _perform_induction(self, ctx: TeXBotApplicationContext, induction_memb
class InductCommandCog(BaseInductCog):
"""Cog class that defines the "/induct" command and its call-back method."""

@staticmethod
async def autocomplete_get_members(ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
@classmethod
async def autocomplete_get_members(cls, ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
"""
Autocomplete callable that generates the set of available selectable members.

Expand Down
4 changes: 2 additions & 2 deletions cogs/remind_me.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
class RemindMeCommandCog(TeXBotBaseCog):
"""Cog class that defines the "/remindme" command and its call-back method."""

@staticmethod
async def autocomplete_get_delays(ctx: TeXBotAutocompleteContext) -> set[str]: # noqa: C901, PLR0912, PLR0915
@classmethod
async def autocomplete_get_delays(cls, ctx: TeXBotAutocompleteContext) -> set[str]: # noqa: C901, PLR0912, PLR0915
"""
Autocomplete callable that generates the common delay input values.

Expand Down
16 changes: 8 additions & 8 deletions cogs/stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ def plot_bar_chart(data: dict[str, int], x_label: str, y_label: str, title: str,
class StatsCommandsCog(TeXBotBaseCog):
"""Cog class that defines the "/stats" command group and its command call-back methods."""

_DISCORD_SERVER_NAME: Final[str] = f"""{
_DISCORD_GUILD_NAME: Final[str] = f"""{
"the " if (
settings["_GROUP_SHORT_NAME"] is not None
and (
Expand All @@ -161,7 +161,7 @@ class StatsCommandsCog(TeXBotBaseCog):

stats: discord.SlashCommandGroup = discord.SlashCommandGroup(
"stats",
f"Various statistics about {_DISCORD_SERVER_NAME}",
f"Various statistics about {_DISCORD_GUILD_NAME}",
)

# noinspection SpellCheckingInspection
Expand All @@ -188,15 +188,15 @@ async def channel_stats(self, ctx: TeXBotApplicationContext, str_channel_id: str
"""
channel_id: int = ctx.channel_id

if str_channel_id:
if not re.match(r"\A\d{17,20}\Z", str_channel_id):
if str_channel_id.strip():
if not re.match(r"\A\d{17,20}\Z", str_channel_id.strip()):
await self.command_send_error(
ctx,
message=f"{str_channel_id!r} is not a valid channel ID.",
message=f"{str_channel_id.strip()!r} is not a valid channel ID.",
)
return

channel_id = int(str_channel_id)
channel_id = int(str_channel_id.strip())

# NOTE: Shortcut accessors are placed at the top of the function, so that the exceptions they raise are displayed before any further errors may be sent
guild: discord.Guild = self.bot.main_guild
Expand Down Expand Up @@ -289,7 +289,7 @@ async def channel_stats(self, ctx: TeXBotApplicationContext, str_channel_id: str

@stats.command(
name="server",
description=f"Displays the stats for the whole of {_DISCORD_SERVER_NAME}",
description=f"Displays the stats for the whole of {_DISCORD_GUILD_NAME}",
)
async def server_stats(self, ctx: TeXBotApplicationContext) -> None:
"""
Expand Down Expand Up @@ -509,7 +509,7 @@ async def user_stats(self, ctx: TeXBotApplicationContext) -> None:
# noinspection SpellCheckingInspection
@stats.command(
name="leftmembers",
description=f"Displays the stats about members that have left {_DISCORD_SERVER_NAME}",
description=f"Displays the stats about members that have left {_DISCORD_GUILD_NAME}",
)
async def left_member_stats(self, ctx: TeXBotApplicationContext) -> None:
"""
Expand Down
4 changes: 2 additions & 2 deletions cogs/strike.py
Original file line number Diff line number Diff line change
Expand Up @@ -716,8 +716,8 @@ async def on_member_ban(self, guild: discord.Guild, user: discord.User | discord
class StrikeCommandCog(BaseStrikeCog):
"""Cog class that defines the "/strike" command and its call-back method."""

@staticmethod
async def strike_autocomplete_get_members(ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
@classmethod
async def strike_autocomplete_get_members(cls, ctx: TeXBotAutocompleteContext) -> set[discord.OptionChoice]: # noqa: E501
"""
Autocomplete callable that generates the set of available selectable members.

Expand Down
Loading
Loading