mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 09:56:05 -05:00
[V3 DataConverter] Fix past nicks conversion for mod (#1840)
* Fix existing tests permanently modifying attributes * Add dataconverter tests file * Fix past nicks spec converter * Update gitignore for dataconverter data files * Add data file for dataconverter test * Simplify fix
This commit is contained in:
0
tests/cogs/dataconverter/__init__.py
Normal file
0
tests/cogs/dataconverter/__init__.py
Normal file
26
tests/cogs/dataconverter/data/mod/past_nicknames.json
Normal file
26
tests/cogs/dataconverter/data/mod/past_nicknames.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"1" : {
|
||||
"1" : [
|
||||
"Test",
|
||||
"Test2",
|
||||
"TEST3"
|
||||
],
|
||||
"2" : [
|
||||
"Test4",
|
||||
"Test5",
|
||||
"TEST6"
|
||||
]
|
||||
},
|
||||
"2" : {
|
||||
"1" : [
|
||||
"Test",
|
||||
"Test2",
|
||||
"TEST3"
|
||||
],
|
||||
"2" : [
|
||||
"Test4",
|
||||
"Test5",
|
||||
"TEST6"
|
||||
]
|
||||
}
|
||||
}
|
||||
39
tests/cogs/dataconverter/test_dataconverter.py
Normal file
39
tests/cogs/dataconverter/test_dataconverter.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import pytest
|
||||
from pathlib import Path
|
||||
from collections import namedtuple
|
||||
|
||||
from redbot.cogs.dataconverter import core_specs
|
||||
from redbot.core.utils.data_converter import DataConverter
|
||||
|
||||
|
||||
def mock_dpy_object(id_):
|
||||
return namedtuple("DPYObject", "id")(int(id_))
|
||||
|
||||
|
||||
def mock_dpy_member(guildid, userid):
|
||||
return namedtuple("Member", "id guild")(int(userid), mock_dpy_object(guildid))
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def specresolver():
|
||||
here = Path(__file__)
|
||||
|
||||
resolver = core_specs.SpecResolver(here.parent)
|
||||
return resolver
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_mod_nicknames(red, specresolver: core_specs.SpecResolver):
|
||||
filepath, converter, cogname, attr, _id = specresolver.get_conversion_info("Past Nicknames")
|
||||
conf = specresolver.get_config_object(red, cogname, attr, _id)
|
||||
|
||||
v2data = DataConverter.json_load(filepath)
|
||||
|
||||
await specresolver.convert(red, "Past Nicknames", config=conf)
|
||||
|
||||
for guildid, guild_data in v2data.items():
|
||||
guild = mock_dpy_object(guildid)
|
||||
for userid, user_data in guild_data.items():
|
||||
member = mock_dpy_member(guildid, userid)
|
||||
|
||||
assert await conf.member(member).past_nicks() == user_data
|
||||
@@ -1,15 +1,14 @@
|
||||
import pytest
|
||||
|
||||
from redbot.cogs.alias import Alias
|
||||
from redbot.core import Config
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def alias(config):
|
||||
import redbot.cogs.alias.alias
|
||||
|
||||
redbot.cogs.alias.alias.Config.get_conf = lambda *args, **kwargs: config
|
||||
|
||||
return Alias(None)
|
||||
def alias(config, monkeypatch):
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr(Config, "get_conf", lambda *args, **kwargs: config)
|
||||
return Alias(None)
|
||||
|
||||
|
||||
def test_is_valid_alias_name(alias):
|
||||
|
||||
@@ -2,15 +2,15 @@ import pytest
|
||||
|
||||
|
||||
@pytest.fixture()
|
||||
def bank(config):
|
||||
def bank(config, monkeypatch):
|
||||
from redbot.core import Config
|
||||
|
||||
Config.get_conf = lambda *args, **kwargs: config
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr(Config, "get_conf", lambda *args, **kwargs: config)
|
||||
from redbot.core import bank
|
||||
|
||||
from redbot.core import bank
|
||||
|
||||
bank._register_defaults()
|
||||
return bank
|
||||
bank._register_defaults()
|
||||
return bank
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
@@ -2,15 +2,15 @@ import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def mod(config):
|
||||
def mod(config, monkeypatch):
|
||||
from redbot.core import Config
|
||||
|
||||
Config.get_conf = lambda *args, **kwargs: config
|
||||
with monkeypatch.context() as m:
|
||||
m.setattr(Config, "get_conf", lambda *args, **kwargs: config)
|
||||
from redbot.core import modlog
|
||||
|
||||
from redbot.core import modlog
|
||||
|
||||
modlog._register_defaults()
|
||||
return modlog
|
||||
modlog._register_defaults()
|
||||
return modlog
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user