import sys

import pytest
from disnake.ext.commands.common_bot_base import CommonBotBase
from mock import mock

sys.path.append('src')
from integral_lib import CogsPrep


def test_cog_list():
    with mock.patch('integral_lib.CogsPrep.listdir') as MockClass:
        MockClass.return_value = ['cog1.py', 'cog2.py']
        result = CogsPrep.cog_list()
        assert result == ['cog1', 'cog2']


@pytest.mark.parametrize("cog", ["cog1.py", "cog2"])
@pytest.mark.parametrize("what_do", ['load', 'unload', 'reload', 'disable', 'enable'])
def test_work_with_cogs(what_do, cog):
    with mock.patch('integral_lib.CogsPrep.rename') as mock_rename:
        mock_rename.return_value = None
        mock_bot = mock.MagicMock(spec=CommonBotBase)
        result = CogsPrep.work_with_cogs(what_do, mock_bot, cog)
        if what_do in ['load', 'enable']:
            assert mock_bot.load_extension.called
        elif what_do in ['unload', 'disable']:
            assert mock_bot.unload_extension.called
        elif what_do == 'reload':
            assert mock_bot.reload_extension.called

