mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 09:56:05 -05:00
[V3 Admin] Rewrite of Squid-Plugins Admin cog (#825)
* Add/remove roles * Announcement * Edit role stuff A bit of refactoring * Selfrole stuff * Add announce ignore capabilities * announce configurations Announcement fixes * Serverlock initial commit * Add some admin tests better test * Update for new config * Add user hierarchy checks * Fix tests * Update from rebase * Fix config getter * Fix async getters/selfrole
This commit is contained in:
0
tests/cogs/admin/__init__.py
Normal file
0
tests/cogs/admin/__init__.py
Normal file
57
tests/cogs/admin/test_admin.py
Normal file
57
tests/cogs/admin/test_admin.py
Normal file
@@ -0,0 +1,57 @@
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
import pytest
|
||||
|
||||
from redbot.cogs.admin import Admin
|
||||
from redbot.cogs.admin.announcer import Announcer
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def admin(config):
|
||||
return Admin(config)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def announcer(admin):
|
||||
a = Announcer(MagicMock(), "Some message", admin.conf)
|
||||
yield a
|
||||
a.cancel()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_serverlock_check(admin, coroutine):
|
||||
await admin.conf.serverlocked.set(True)
|
||||
guild = MagicMock()
|
||||
guild.leave = coroutine
|
||||
|
||||
# noinspection PyProtectedMember
|
||||
ret = await admin._serverlock_check(guild)
|
||||
|
||||
assert ret is True
|
||||
|
||||
|
||||
def test_announcer_initial_state(announcer):
|
||||
assert announcer.active is None
|
||||
|
||||
|
||||
def test_announcer_start(announcer):
|
||||
announcer.announcer = object
|
||||
announcer.start()
|
||||
|
||||
assert announcer.ctx.bot.loop.create_task.called
|
||||
assert announcer.active is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_announcer_ignore(announcer, empty_guild, empty_channel):
|
||||
await announcer.config.guild(empty_guild).announce_channel.set(empty_channel.id)
|
||||
|
||||
guild = MagicMock()
|
||||
guild.id = empty_guild.id
|
||||
|
||||
guild.get_channel.return_value = empty_channel
|
||||
|
||||
ret = await announcer._get_announce_channel(guild)
|
||||
|
||||
assert guild.get_channel.called
|
||||
assert ret == empty_channel
|
||||
@@ -24,6 +24,13 @@ def override_data_path(tmpdir):
|
||||
data_manager.basic_config['DATA_PATH'] = str(tmpdir)
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def coroutine():
|
||||
async def some_coro(*args, **kwargs):
|
||||
return args, kwargs
|
||||
return some_coro
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def json_driver(tmpdir_factory):
|
||||
import uuid
|
||||
|
||||
Reference in New Issue
Block a user