Skip to content

Commit

Permalink
Merge pull request #18 from placeTW/11-add-more-tests
Browse files Browse the repository at this point in the history
Added test for shiba
  • Loading branch information
chanomkaimuk authored Aug 10, 2023
2 parents d841ec7 + 33e35c8 commit e113d77
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 26 deletions.
56 changes: 30 additions & 26 deletions commands/shiba/random_shiba.py
Original file line number Diff line number Diff line change
@@ -1,26 +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",
)


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 _async_get_json(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"])
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"])
12 changes: 12 additions & 0 deletions tests/test_shiba.py
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit e113d77

Please sign in to comment.