Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_get_main_url_with_extension_and_page():
assert (
utils.get_main_url(utils.BASE_URL, "anime", 2, extension="episodes", page=2)
== "https://api.jikan.moe/v3/anime/2/episodes/2"
)
async def test_wrap_response(aio_jikan):
anime_info = await aio_jikan.anime(MUSHISHI_ID)
mushishi_url = utils.get_main_url(
aio_jikan.base, "anime", MUSHISHI_ID, extension=None, page=None
)
assert isinstance(anime_info, dict)
assert "jikan_url" in anime_info
assert "headers" in anime_info
assert isinstance(anime_info["headers"], dict)
assert mushishi_url == anime_info["jikan_url"]
await aio_jikan.close()
def test_wrap_response(header_keys, jikan):
anime_info = jikan.anime(MUSHISHI_ID)
mushishi_url = utils.get_main_url(
jikan.base, "anime", MUSHISHI_ID, extension=None, page=None
)
assert isinstance(anime_info, dict)
assert "jikan_url" in anime_info
assert "headers" in anime_info
assert isinstance(anime_info["headers"], dict)
assert mushishi_url == anime_info["jikan_url"]
# Test against headers mentioned in documentation
# https://jikan.docs.apiary.io/#introduction/information/caching
assert header_keys.issubset(anime_info["headers"].keys())
async def test_empty_response_json(aio_jikan, aio_response_mock):
with pytest.raises(APIException) as err_info:
await aio_jikan._wrap_response(aio_response_mock, url=utils.BASE_URL, param=1)
err = err_info.value
err_text = await aio_response_mock.text()
assert err.status_code == aio_response_mock.status
assert isinstance(err.error_json, dict)
assert "error" in err.error_json
assert err.error_json["error"] == err_text
assert isinstance(err.relevant_params, dict)
assert "param" in err.relevant_params
assert err.relevant_params["param"] == 1
assert str(err) == f"HTTP {aio_response_mock.status} - error={err_text} for param=1"
assert repr(err).startswith(
f"APIException(status_code={aio_response_mock.status}, error_json={{'error': '"
)
assert repr(err).endswith("'}, relevant_params={'param': 1})")
def test_get_main_url():
assert (
utils.get_main_url(utils.BASE_URL, "anime", 2, extension=None, page=None)
== "https://api.jikan.moe/v3/anime/2"
)
def test_get_url_with_page():
assert utils.get_url_with_page(utils.BASE_URL, 2) == "https://api.jikan.moe/v3/2"
def test_get_user_url_with_friends_and_page():
assert (
utils.get_user_url(
utils.BASE_URL,
"Xinil",
request="friends",
argument=None,
page=2,
parameters=None,
)
== "https://api.jikan.moe/v3/user/xinil/friends/2"
)
def test_get_user_url_with_anime_history():
assert (
utils.get_user_url(
utils.BASE_URL,
"Xinil",
request="history",
argument="anime",
page=None,
parameters=None,
)
== "https://api.jikan.moe/v3/user/xinil/history/anime"
)
def test_get_user_url():
assert (
utils.get_user_url(
utils.BASE_URL,
"Xinil",
request=None,
argument=None,
page=None,
parameters=None,
)
== "https://api.jikan.moe/v3/user/xinil"
)
def test_get_user_url_with_animelist_and_page_parameter():
assert (
utils.get_user_url(
utils.BASE_URL,
"Xinil",
request="animelist",
argument="completed",
page=None,
parameters={"page": 2},
)
== "https://api.jikan.moe/v3/user/xinil/animelist/completed?page=2"
)