Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add showdown field to pokemon api resource #978

Merged
merged 2 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions data/v2/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1388,6 +1388,7 @@ def csv_record_to_objects(info):
dream_world = "other/dream-world/"
home = "other/home/"
official_art = "other/official-artwork/"
showdown = "other/showdown/"
gen_i = "versions/generation-i/"
gen_ii = "versions/generation-ii/"
gen_iii = "versions/generation-iii/"
Expand Down Expand Up @@ -1438,6 +1439,32 @@ def csv_record_to_objects(info):
poke_sprites + official_art + "shiny/", info, "png"
),
},
"showdown": {
"front_default": try_image_names(
poke_sprites + showdown, info, "gif"
),
"front_shiny": try_image_names(
poke_sprites + showdown + "shiny/", info, "gif"
),
"front_female": try_image_names(
poke_sprites + showdown + "female/", info, "gif"
),
"front_shiny_female": try_image_names(
poke_sprites + showdown + "shiny/female/", info, "gif"
),
"back_default": try_image_names(
poke_sprites + showdown + "back/", info, "gif"
),
"back_shiny": try_image_names(
poke_sprites + showdown + "back/shiny/", info, "gif"
),
"back_female": try_image_names(
poke_sprites + showdown + "back/female/", info, "gif"
),
"back_shiny_female": try_image_names(
poke_sprites + showdown + "back/shiny/female", info, "gif"
),
},
},
"versions": {
"generation-i": {
Expand Down
39 changes: 38 additions & 1 deletion pokemon_v2/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -1675,6 +1675,32 @@ def setup_pokemon_sprites_data(
back_shiny_female=False,
):
sprite_path = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/%s.png"
showdown_path = "https://raw.githubusercontent.com/PokeAPI/sprites/master/sprites/pokemon/other/showdown/%s.png"

showdown = {
"front_default": showdown_path % pokemon.id if front_default else None,
"front_female": showdown_path % f"female/{pokemon.id}"
if front_female
else None,
"front_shiny": showdown_path % f"shiny/{pokemon.id}"
if front_shiny
else None,
"front_shiny_female": showdown_path % f"shiny/female/{pokemon.id}"
if front_shiny_female
else None,
"back_default": showdown_path % f"back/{pokemon.id}"
if back_default
else None,
"back_female": showdown_path % f"back/female/{pokemon.id}"
if back_female
else None,
"back_shiny": showdown_path % f"back/shiny/{pokemon.id}"
if back_shiny
else None,
"back_shiny_female": showdown_path % f"back/shiny/female/{pokemon.id}"
if back_shiny_female
else None,
}

sprites = {
"front_default": sprite_path % pokemon.id if front_default else None,
Expand All @@ -1692,7 +1718,8 @@ def setup_pokemon_sprites_data(
}

pokemon_sprites = PokemonSprites.objects.create(
pokemon=pokemon, sprites=json.dumps(sprites)
pokemon=pokemon,
sprites=json.dumps(sprites | {"other": {"showdown": showdown}}),
)
pokemon_sprites.save()

Expand Down Expand Up @@ -5025,6 +5052,7 @@ def test_pokemon_api(self):
)

sprites_data = json.loads(pokemon_sprites.sprites)
response_sprites_data = json.loads(response.data["sprites"])

# sprite params
self.assertEqual(
Expand All @@ -5033,6 +5061,15 @@ def test_pokemon_api(self):
)
self.assertEqual(sprites_data["back_default"], None)

self.assertEqual(
sprites_data["other"]["showdown"]["front_default"],
response_sprites_data["other"]["showdown"]["front_default"],
)
self.assertEqual(
sprites_data["other"]["showdown"]["back_default"],
response_sprites_data["other"]["showdown"]["back_default"],
)

def test_pokemon_form_api(self):
pokemon_species = self.setup_pokemon_species_data()
pokemon = self.setup_pokemon_data(pokemon_species=pokemon_species)
Expand Down