test_commands.py 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. import pytest
  2. import discord
  3. import myanimebot.commands as commands
  4. import myanimebot.globals as globals
  5. from myanimebot.discord import MyAnimeBot
  6. import discord.ext.test as dpytest
  7. @pytest.fixture
  8. def client(event_loop):
  9. ''' Create our mock client to be used for testing purposes '''
  10. intents = discord.Intents.default()
  11. intents.members = True
  12. c = MyAnimeBot(loop=event_loop, intents=intents)
  13. dpytest.configure(c)
  14. return c
  15. @pytest.mark.asyncio
  16. async def test_about_cmd(client):
  17. guild = client.guilds[0]
  18. channel = guild.text_channels[0]
  19. await commands.about_cmd(channel)
  20. embed = discord.Embed(title="***MyAnimeBot Commands***", colour=0xEED000)
  21. embed.title = "MyAnimeBot version {} by Penta & lulu".format(globals.VERSION)
  22. embed.colour = 0xEED000
  23. embed.description = """MyAnimeBot checks MyAnimeList and Anilist profiles for specified users, and send a message for every new activities found.
  24. More help with the **{} help** command.
  25. Check our GitHub page for more informations: https://github.com/Penta/MyAnimeBot
  26. """.format(globals.prefix)
  27. dpytest.verify_embed(embed=embed)
  28. await dpytest.empty_queue()
  29. @pytest.mark.asyncio
  30. async def test_help_cmd(client):
  31. guild = client.guilds[0]
  32. channel = guild.text_channels[0]
  33. await commands.help_cmd(channel)
  34. embed = discord.Embed(title="***MyAnimeBot Commands***", colour=0xEED000)
  35. embed.add_field(name="`here`", value="Register this channel. The bot will send new activities on registered channels.")
  36. embed.add_field(name="`stop`", value="Un-register this channel. The bot will now stop sending new activities for this channel.")
  37. embed.add_field(name="`info [mal|ani]`", value="Get the registered users for this server. Users can be filtered by specifying a service.")
  38. embed.add_field(name="`add {mal|ani} <user>`", value="Register a user for a specific service.\nEx: `add mal MyUser`")
  39. embed.add_field(name="`delete {mal|ani} <user>`", value="Remove a user for a specific service.\nEx: `delete ani MyUser`")
  40. embed.add_field(name="`role <@discord_role>`", value="Specify a role that is able to manage the bot.\nEx: `role @Moderator`, `role @everyone`")
  41. embed.add_field(name="`top`", value="Show statistics for this server.")
  42. embed.add_field(name="`ping`", value="Ping the bot.")
  43. embed.add_field(name="`about`", value="Get some information about this bot")
  44. dpytest.verify_embed(embed=embed)
  45. await dpytest.empty_queue()
  46. @pytest.mark.asyncio
  47. async def test_ping_cmd(client):
  48. guild = client.guilds[0]
  49. channel = guild.text_channels[0]
  50. message = await channel.send("Test Message")
  51. await dpytest.empty_queue()
  52. await commands.ping_cmd(message, channel)
  53. dpytest.verify_message(text="pong", contains=True)
  54. await dpytest.empty_queue()