コード例 #1
0
def test_requests_errors(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        body=requests.exceptions.RequestException("Some error"),
    )

    with pytest.raises(PyPokedexError):
        pypokedex.get(name="sample")
コード例 #2
0
def test_404_pokemon_not_found(responses):
    responses.add(responses.GET,
                  "https://pokeapi.co/api/v2/pokemon/sample",
                  json={},
                  status=404)

    with pytest.raises(PyPokedexHTTPError) as not_found:
        pypokedex.get(name="sample")

    assert not_found.value.http_code == 404
コード例 #3
0
def test_other_HTTP_errors(responses):
    responses.add(responses.GET,
                  "https://pokeapi.co/api/v2/pokemon/sample",
                  json={},
                  status=408)

    with pytest.raises(PyPokedexHTTPError) as other_http_error:
        pypokedex.get(name="sample")

    assert other_http_error.value.http_code == 408
コード例 #4
0
def test_pokemon_str_function(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")
    assert str(pokemon) == "Pokemon(dex=999, name='sample')"
コード例 #5
0
def test_pokemon_existence_in_games(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    assert pokemon.exists_in("game_1")
コード例 #6
0
def test_get_pokemon_by_dex(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(dex=999)

    assert _is_properly_initialized_pokemon(pokemon)
コード例 #7
0
def test_get_pokemon_by_name(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    assert _is_properly_initialized_pokemon(pokemon)
コード例 #8
0
def test_pokemon_does_not_learn_move(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    assert not pokemon.learns("random move", "game_1")
コード例 #9
0
def test_missing_data_keys_for_pokemon(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    del cloned_sample_pokemon["weight"]
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=cloned_sample_pokemon,
        status=200,
    )

    with pytest.raises(PyPokedexError):
        pypokedex.get(name="sample")
コード例 #10
0
def test_pokemon_does_not_learn_move_because_it_is_not_in_the_specified_game(
        responses):  # noqa
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )

    pokemon = pypokedex.get(name="sample")

    with pytest.raises(PyPokedexError):
        pokemon.learns("random move", "random game")
コード例 #11
0
def test_pokemon_equality(responses):
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/sample",
        json=SAMPLE_POKEMON,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(name="sample")
    second_pokemon = pypokedex.get(dex=999)
    assert first_pokemon == second_pokemon
コード例 #12
0
def test_pokemon_inequality(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    cloned_sample_pokemon["id"] = 998
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/998",
        json=cloned_sample_pokemon,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(dex=998)
    second_pokemon = pypokedex.get(dex=999)
    assert first_pokemon != second_pokemon
コード例 #13
0
def test_pokemon_greater_than(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    cloned_sample_pokemon["id"] = 998
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/998",
        json=cloned_sample_pokemon,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(dex=998)
    second_pokemon = pypokedex.get(dex=999)
    assert second_pokemon > first_pokemon
    assert not second_pokemon == first_pokemon
    assert not second_pokemon < first_pokemon
コード例 #14
0
def test_pokemon_less_than_or_equal_to(responses):
    cloned_sample_pokemon = deepcopy(SAMPLE_POKEMON)
    cloned_sample_pokemon["id"] = 998
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/998",
        json=cloned_sample_pokemon,
        status=200,
    )
    responses.add(
        responses.GET,
        "https://pokeapi.co/api/v2/pokemon/999",
        json=SAMPLE_POKEMON,
        status=200,
    )

    first_pokemon = pypokedex.get(dex=998)
    second_pokemon = pypokedex.get(dex=999)
    third_pokemon = pypokedex.get(dex=999)
    assert first_pokemon <= second_pokemon
    assert second_pokemon <= third_pokemon
    assert not third_pokemon <= first_pokemon