import asyncio # Libs import discord.ext.test as dpytest import pytest from discord.ext import commands # Own modules import KoalaBot from cogs import Verification from utils.KoalaDBManager import KoalaDBManager # Constants # Variables cog = None db_manager = KoalaDBManager("verifyTest.db", KoalaBot.DB_KEY) db_manager.create_base_tables() def setup_function(): """ setup any state specific to the execution of the given module.""" global cog bot = commands.Bot(command_prefix=KoalaBot.COMMAND_PREFIX) cog = Verification.Verification(bot, db_manager) bot.add_cog(cog) dpytest.configure(bot) db_manager.db_execute_commit("DROP TABLE verified_emails") db_manager.db_execute_commit("DROP TABLE non_verified_emails") db_manager.db_execute_commit("DROP TABLE to_re_verify") db_manager.db_execute_commit("DROP TABLE roles") db_manager.db_execute_commit("CREATE TABLE verified_emails (u_id, email)")
import mock import pytest from discord.ext import commands # Own modules import KoalaBot from cogs import IntroCog from tests.utils.TestUtilsCog import TestUtilsCog from utils.KoalaDBManager import KoalaDBManager # Constants fake_guild_id = 1000 non_existent_guild_id = 9999 # Variables DBManager = KoalaDBManager(KoalaBot.DATABASE_PATH, KoalaBot.DB_KEY) DBManager.create_base_tables() @pytest.fixture(autouse=True) def utils_cog(bot): utils_cog = TestUtilsCog(bot) bot.add_cog(utils_cog) dpytest.configure(bot) print("Tests starting") return utils_cog @pytest.fixture(autouse=True) def intro_cog(bot): intro_cog = IntroCog.IntroCog(bot) bot.add_cog(intro_cog)
PERMISSION_ERROR_TEXT = "This guild does not have this extension enabled, go to http://koalabot.uk, " \ "or use `k!help enableExt` to enable it" KOALA_IMAGE_URL = "https://cdn.discordapp.com/attachments/737280260541907015/752024535985029240/discord1.png" # Variables started = False if discord.__version__ != "1.3.4": logging.info("Intents Enabled") intent = discord.Intents.default() intent.members = True intent.guilds = True intent.messages = True client = commands.Bot(command_prefix=COMMAND_PREFIX, intents=intent) else: logging.info("discord.py v1.3.4: Intents Disabled") client = commands.Bot(command_prefix=COMMAND_PREFIX) database_manager = DBManager(DATABASE_PATH, DB_KEY) logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)-8s %(message)s') logger = logging.getLogger('discord') is_dpytest = False def is_owner(ctx): """ A command used to check if the user of a command is the owner, or the testing bot e.g. @commands.check(KoalaBot.is_owner) :param ctx: The context of the message :return: True if owner or test, False otherwise """ if is_dm_channel(ctx): return False