mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 09:56:05 -05:00
Added Alias cog (#780)
This commit is contained in:
@@ -27,7 +27,7 @@ def patch_relative_to(monkeysession):
|
||||
monkeysession.setattr("pathlib.Path.relative_to", fake_relative_to)
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@pytest.fixture
|
||||
def repo_manager(tmpdir_factory, config):
|
||||
config.register_global(repos={})
|
||||
rm = RepoManager(config)
|
||||
|
||||
64
tests/cogs/test_alias.py
Normal file
64
tests/cogs/test_alias.py
Normal file
@@ -0,0 +1,64 @@
|
||||
from cogs.alias import Alias
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def alias(monkeysession, config):
|
||||
def get_mock_conf(*args, **kwargs):
|
||||
return config
|
||||
|
||||
monkeysession.setattr("core.config.Config.get_conf", get_mock_conf)
|
||||
|
||||
return Alias(None)
|
||||
|
||||
|
||||
def test_is_valid_alias_name(alias):
|
||||
assert alias.is_valid_alias_name("valid") is True
|
||||
assert alias.is_valid_alias_name("not valid name") is False
|
||||
|
||||
|
||||
def test_empty_guild_aliases(alias, empty_guild):
|
||||
assert list(alias.unloaded_aliases(empty_guild)) == []
|
||||
|
||||
|
||||
def test_empty_global_aliases(alias):
|
||||
assert list(alias.unloaded_global_aliases()) == []
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_guild_alias(alias, ctx):
|
||||
await alias.add_alias(ctx, "test", "ping", global_=False)
|
||||
|
||||
is_alias, alias_obj = alias.is_alias(ctx.guild, "test")
|
||||
assert is_alias is True
|
||||
assert alias_obj.global_ is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_guild_alias(alias, ctx):
|
||||
is_alias, _ = alias.is_alias(ctx.guild, "test")
|
||||
assert is_alias is True
|
||||
|
||||
await alias.delete_alias(ctx, "test")
|
||||
|
||||
is_alias, _ = alias.is_alias(ctx.guild, "test")
|
||||
assert is_alias is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_add_global_alias(alias, ctx):
|
||||
await alias.add_alias(ctx, "test", "ping", global_=True)
|
||||
is_alias, alias_obj = alias.is_alias(ctx.guild, "test")
|
||||
|
||||
assert is_alias is True
|
||||
assert alias_obj.global_ is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_delete_global_alias(alias, ctx):
|
||||
is_alias, alias_obj = alias.is_alias(ctx.guild, "test")
|
||||
assert is_alias is True
|
||||
assert alias_obj.global_ is True
|
||||
|
||||
did_delete = await alias.delete_alias(ctx, alias_name="test", global_=True)
|
||||
assert did_delete is True
|
||||
@@ -84,7 +84,7 @@ def empty_message():
|
||||
return mock_msg("No content.")
|
||||
|
||||
|
||||
@pytest.fixture(scope="module")
|
||||
@pytest.fixture
|
||||
def ctx(empty_member, empty_channel, red):
|
||||
mock_ctx = namedtuple("Context", "author guild channel message bot")
|
||||
return mock_ctx(empty_member, empty_member.guild, empty_channel,
|
||||
@@ -94,16 +94,18 @@ def ctx(empty_member, empty_channel, red):
|
||||
|
||||
#region Red Mock
|
||||
@pytest.fixture
|
||||
def red(monkeypatch, config_fr, event_loop):
|
||||
def red(monkeysession, config_fr):
|
||||
from core.cli import parse_cli_flags
|
||||
cli_flags = parse_cli_flags()
|
||||
|
||||
description = "Red v3 - Alpha"
|
||||
|
||||
monkeypatch.setattr("core.config.Config.get_core_conf",
|
||||
lambda *args, **kwargs: config_fr)
|
||||
monkeysession.setattr("core.config.Config.get_core_conf",
|
||||
lambda *args, **kwargs: config_fr)
|
||||
|
||||
red = Red(cli_flags, description=description, pm_help=None,
|
||||
loop=event_loop)
|
||||
return red
|
||||
red = Red(cli_flags, description=description, pm_help=None)
|
||||
|
||||
yield red
|
||||
|
||||
red.http._session.close()
|
||||
#endregion
|
||||
Reference in New Issue
Block a user