From 9e67a44a31680e34ffb19405c98cb9e538c6bcd6 Mon Sep 17 00:00:00 2001 From: Amari Bolmer Date: Tue, 22 Oct 2024 10:40:00 -0700 Subject: [PATCH] Updated Readme for correctness of interactive_test name. Adding IDE Project files Created an interactive_test_poke_api.py file that takes user input as an example. --- .idea/inspectionProfiles/Project_Default.xml | 15 ++++++ .../inspectionProfiles/profiles_settings.xml | 6 +++ .idea/misc.xml | 7 +++ .idea/modules.xml | 8 +++ .idea/pokemonAPI-Amari.iml | 14 +++++ .idea/vcs.xml | 6 +++ README.md | 2 +- tests/interactive_test_poke_api.py | 54 +++++++++++++++++++ 8 files changed, 111 insertions(+), 1 deletion(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/pokemonAPI-Amari.iml create mode 100644 .idea/vcs.xml create mode 100644 tests/interactive_test_poke_api.py diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..1093661 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,15 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0365f1f --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..46328a0 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/pokemonAPI-Amari.iml b/.idea/pokemonAPI-Amari.iml new file mode 100644 index 0000000..8e5446a --- /dev/null +++ b/.idea/pokemonAPI-Amari.iml @@ -0,0 +1,14 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 0022b85..f8470b0 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ This will demonstrate how to fetch Pokémon and generation data using the SDK. To run the interactive test that allows you to input a generation ID and output Pokémon in that generation, execute: ```bash -python tests/interactive_test_generation_pokemon.py +python tests/interactive_test_poke_api.py ``` When prompted, enter a generation ID (e.g., "1") to see the Pokémon in that generation. diff --git a/tests/interactive_test_poke_api.py b/tests/interactive_test_poke_api.py new file mode 100644 index 0000000..7d482a9 --- /dev/null +++ b/tests/interactive_test_poke_api.py @@ -0,0 +1,54 @@ +import unittest +from poke_sdk.PokeAPI import PokeAPI +from poke_sdk.exceptions import APIError + + +class InteractiveTestPokeAPI(unittest.TestCase): + + @classmethod + def setUpClass(cls): + """Set up the API client for testing.""" + cls.api = PokeAPI() + + def test_get_pokemon_with_user_input(self): + """Test retrieving a Pokémon based on user input. Will return Pokémon Type and generation""" + pokemon_name = input("Enter the Pokémon name (e.g., pikachu, charizard, blastoise): ") + try: + response = self.api.get_pokemon(pokemon_name) + print(f"Retrieved Pokémon: {response.name}, ID: {response.id}, Types: {response.types}") + self.assertEqual(response.name, pokemon_name) + except APIError as e: + self.fail(f"APIError occurred: {e}") + except Exception as e: + print(f"An unexpected error occurred: {e}") + + def test_get_pokemon_in_generation(self): + """Test retrieving Pokémon in a specified generation based on user input. Returns all Pokémon in generation""" + generation_id = input("Enter the generation ID (e.g., 1): ") + try: + response = self.api.get_generation(generation_id) + print(f"Retrieved Generation: {response.name}, ID: {response.id}") + print("Pokémon in this generation:") + for pokemon in response.pokemon_species: + print(f"- {pokemon}") + except APIError as e: + self.fail(f"APIError occurred: {e}") + except Exception as e: + print(f"An unexpected error occurred: {e}") + + #Test generation is a valid Pokémon Generation based on user input + def test_get_generation_with_user_input(self): + """Test retrieving a generation based on user input. Will validate Pokémon generation is a valid Gen""" + generation_id = input("Enter the generation ID, will validate if gen is available(e.g., 1): ") + try: + response = self.api.get_generation(generation_id) + print(f"Retrieved Generation: {response.name}, ID: {response.id}") + self.assertEqual(response.id, int(generation_id)) + except APIError as e: + self.fail(f"APIError occurred: {e}") + except Exception as e: + print(f"An unexpected error occurred: {e}") + + +if __name__ == "__main__": + unittest.main()