async def twitch_cog(bot): """ setup any state specific to the execution of the given module.""" twitch_cog = TwitchAlert.TwitchAlert(bot) bot.add_cog(twitch_cog) await dpytest.empty_queue() dpytest.configure(bot) return twitch_cog
async def twitch_cog(): """ setup any state specific to the execution of the given module.""" bot = commands.Bot(command_prefix=KoalaBot.COMMAND_PREFIX) database_manager = KoalaDBManager.KoalaDBManager(DB_PATH, KoalaBot.DB_KEY) twitch_cog = TwitchAlert.TwitchAlert(bot, database_manager=database_manager) bot.add_cog(twitch_cog) await dpytest.empty_queue() dpytest.configure(bot) print("Tests starting") return twitch_cog
async def test_remove_team_from_twitch_alert_wrong_guild(twitch_cog): guild = dpytest.backend.make_guild(name="TestGuild") channel = dpytest.backend.make_text_channel(name="TestChannel", guild=guild) dpytest.get_config().guilds.append(guild) dpytest.get_config().channels.append(channel) member = await dpytest.member_join(1, name="TestUser", discrim=1) await dpytest.member_join(1, dpytest.get_config().client.user) await dpytest.message( f"{KoalaBot.COMMAND_PREFIX}remove_team_from_twitch_alert {dpytest.get_config().channels[0].id} monstercat", channel=-1, member=member) dpytest.verify_embed( embed=TwitchAlert.error_embed("The channel ID provided is either invalid, or not in this server."))
async def test_add_team_to_twitch_alert_wrong_guild(twitch_cog): # Creates guild and channels and adds user and bot guild = dpytest.backend.make_guild(name="TestGuild") channel = dpytest.backend.make_text_channel(name="TestChannel", guild=guild) dpytest.get_config().guilds.append(guild) dpytest.get_config().channels.append(channel) member = await dpytest.member_join(-1, name="TestUser", discrim=1) await dpytest.member_join(-1, dpytest.get_config().client.user) # Creates Twitch Alert await dpytest.message( f"{KoalaBot.COMMAND_PREFIX}add_team_to_twitch_alert {dpytest.get_config().channels[0].id} faze ", channel=-1, member=member) dpytest.verify_embed( embed=TwitchAlert.error_embed("The channel ID provided is either invalid, or not in this server."))
def test_create_live_embed_with_message(): # Create the expected embed with information required expected = discord.Embed(colour=KOALA_GREEN, title="https://twitch.tv/test", description="Hello Message") expected.set_author(name="Test is now streaming!", icon_url=TwitchAlert.TWITCH_ICON) expected.add_field(name="Stream Title", value="Test Title") expected.add_field(name="Playing", value="TestGame") expected.set_thumbnail(url="http://koalabot.uk") # Create JSON required to pass to method stream_info = {'user_name': "Test", 'title': "Test Title"} user_info = {'profile_image_url': "http://koalabot.uk"} game_info = {'name': "TestGame"} # Get response and assert equal result = TwitchAlert.create_live_embed(stream_info, user_info, game_info, "Hello Message") assert dpytest.embed_eq(result, expected)
async def test_setup(): with mock.patch.object(discord.ext.commands.bot.Bot, 'add_cog') as mock1: TwitchAlert.setup(KoalaBot.client) mock1.assert_called()
def twitch_alert_db_manager(twitch_cog): return TwitchAlert.TwitchAlertDBManager( KoalaDBManager.KoalaDBManager(DB_PATH, KoalaBot.DB_KEY), twitch_cog.bot)
def twitch_api_handler(): return TwitchAlert.TwitchAPIHandler(TwitchAlert.TWITCH_CLIENT_ID, TwitchAlert.TWITCH_SECRET)