import pytest
from disnake.ext.commands import Bot
from mock import mock

from ..lib.CogsPrep import cog_list, work_with_cogs


@pytest.mark.asyncio
@mock.patch('discord_bot.lib.CogsPrep.cog_list')
async def test_cog_list(mock_cog_list):
    with mock.patch('discord_bot.lib.CogsPrep.listdir') as MockClass:
        MockClass.return_value = ['cog1.py', 'cog2.py']
        result = await cog_list()
        assert result == ['cog1', 'cog2']


# @pytest.mark.skip(reason=None)

@pytest.mark.asyncio
@pytest.mark.parametrize("cog", ["cog1.py", "cog2"])
@pytest.mark.parametrize("what_do", ['load', 'unload', 'reload', 'disable', 'enable'])
async def test_work_with_cogs(what_do, cog):
    mock_logger = mock.MagicMock()
    with mock.patch('discord_bot.lib.CogsPrep.logger.info') as mocked_logger:
        mock_bot = mock.MagicMock(spec=Bot)
        with mock.patch('discord_bot.lib.CogsPrep.rename') as mock_rename:
            mock_rename.return_value = True
            result = await work_with_cogs(what_do, mock_bot, cog)
            assert len(mocked_logger.call_args_list) == 1, f"Not listed what_do {what_do}"
