From 2bd376ae4ab79539e42e1881265813eccbb33046 Mon Sep 17 00:00:00 2001 From: chanomkaimuk <22185824+chanomkaimuk@users.noreply.github.com> Date: Thu, 10 Aug 2023 02:06:40 +0200 Subject: [PATCH] added tests for shiba --- commands/shiba/random_shiba.py | 30 ++++++++++++++++++++++++++++++ tests/test_shiba.py | 12 ++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 commands/shiba/random_shiba.py create mode 100644 tests/test_shiba.py diff --git a/commands/shiba/random_shiba.py b/commands/shiba/random_shiba.py new file mode 100644 index 0000000..5c552c3 --- /dev/null +++ b/commands/shiba/random_shiba.py @@ -0,0 +1,30 @@ +import discord +from ..modules.async_utils import _async_get_json +from random import choice + +POSSIBLE_BREEDS = ( + "https://dog.ceo/api/breed/shiba/images/random", + "https://dog.ceo/api/breed/akita/images/random", +) + + +async def get_shiba(link): + return await _async_get_json(link) + + +def register_commands(tree, this_guild: discord.Object): + @tree.command( + name="doge", + description="Random Shiba or Akita image", + guild=this_guild, + ) + async def random_shiba( + interaction: discord.Interaction, + ): + link = choice(POSSIBLE_BREEDS) + shiba_json = await get_shiba(link) + if shiba_json is None or shiba_json["status"] != "success": # ): + return await interaction.response.send_message( + "Sorry, we couldn't find any dogs ):" + ) + await interaction.response.send_message(shiba_json["message"]) diff --git a/tests/test_shiba.py b/tests/test_shiba.py new file mode 100644 index 0000000..e9c2f80 --- /dev/null +++ b/tests/test_shiba.py @@ -0,0 +1,12 @@ +from commands.shiba import random_shiba +import requests + + +async def test_dog_api(): + """ + If something is wrong with their API, we either need + to adjust it or get rid of it entirely. + """ + for link in random_shiba.POSSIBLE_BREEDS: + result = await random_shiba.get_shiba(link) + assert result["status"] == "success"