From 545e1a08265351c6f9e155da3b86fd48341ad983 Mon Sep 17 00:00:00 2001 From: FallenDeity <61227305+FallenDeity@users.noreply.github.com> Date: Sat, 16 Dec 2023 09:56:19 +0530 Subject: [PATCH] feat: Add showdown field to pokemon api resource --- data/v2/build.py | 27 +++++++++++++++++++++++++++ pokemon_v2/tests.py | 39 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 65 insertions(+), 1 deletion(-) diff --git a/data/v2/build.py b/data/v2/build.py index a9b7e5e17..76561b22f 100644 --- a/data/v2/build.py +++ b/data/v2/build.py @@ -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/" @@ -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": { diff --git a/pokemon_v2/tests.py b/pokemon_v2/tests.py index 32d406d2c..57ef4a14b 100644 --- a/pokemon_v2/tests.py +++ b/pokemon_v2/tests.py @@ -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, @@ -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() @@ -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( @@ -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)