Red-DiscordBot/tests/cogs/test_mod.py
Dav 7c7e5edb19
[Modlog]Raise error instead of failing silently on invalid arguments (#5386)
Co-authored-by: Dav <dav@mail.stopdavabuse.de>
Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Flame442 <34169552+Flame442@users.noreply.github.com>
2023-03-18 17:31:28 -04:00

42 lines
1.5 KiB
Python

from collections import namedtuple
import pytest
from redbot.pytest.mod import *
async def test_modlog_register_casetype(mod):
ct = {"name": "ban", "default_setting": True, "image": ":hammer:", "case_str": "Ban"}
casetype = await mod.register_casetype(**ct)
assert casetype is not None
async def test_modlog_case_create(mod, ctx, monkeypatch, member_factory, empty_user):
from datetime import datetime, timezone
# Run casetype register test to register casetype in this test too
await test_modlog_register_casetype(mod)
usr = member_factory.get()
guild = ctx.guild
bot = ctx.bot
case_type = "ban"
moderator = ctx.author
reason = "Test 12345"
created_at = datetime.now(timezone.utc)
# mod.create_case needs bot to have a user object. Without a connection to discord it would be none by default.
# due to the implementation of bot.user we need to set the user as part of bot._connection
mock_connection = namedtuple("Connection", "user")
monkeypatch.setattr(bot, "_connection", mock_connection(empty_user))
case = await mod.create_case(bot, guild, created_at, case_type, usr, moderator, reason)
assert case is not None
assert case.user == usr
assert case.action_type == case_type
assert case.moderator == moderator
assert case.reason == reason
assert case.created_at == int(created_at.timestamp())
async def test_modlog_set_modlog_channel(mod, ctx):
await mod.set_modlog_channel(ctx.guild, ctx.channel)
assert await mod.get_modlog_channel(ctx.guild) == ctx.channel.id