diff --git a/src/helpers/verification.py b/src/helpers/verification.py index b3cf7d7..6a730cf 100644 --- a/src/helpers/verification.py +++ b/src/helpers/verification.py @@ -132,7 +132,7 @@ async def get_user_details(labs_id: int | str) -> dict: async def get_season_rank(htb_uid: int) -> str | None: """Get season rank from HTB.""" - season_api_url = f"{settings.API_V4_URL}/season/end/{settings.SEASON_ID}/{htb_uid}" + season_api_url = f"{settings.API_V4_URL}/user/achievement/season/{htb_uid}/{settings.SEASON_ID}" async with get_labs_session() as session: async with session.get(season_api_url) as r: diff --git a/tests/src/helpers/test_verification.py b/tests/src/helpers/test_verification.py index bb5810c..479d704 100644 --- a/tests/src/helpers/test_verification.py +++ b/tests/src/helpers/test_verification.py @@ -6,10 +6,40 @@ import pytest from src.core import settings -from src.helpers.verification import get_user_details, process_labs_identification +from src.helpers.verification import get_season_rank, get_user_details, process_labs_identification from tests.helpers import MockRoleManager +class TestGetSeasonRank(unittest.IsolatedAsyncioTestCase): + @pytest.mark.asyncio + async def test_get_season_rank_success(self): + htb_uid = 12345 + + with aioresponses.aioresponses() as m: + m.get( + f"{settings.API_V4_URL}/user/achievement/season/{htb_uid}/{settings.SEASON_ID}", + status=200, + payload={"data": {"season": {"tier": "Gold"}}}, + ) + + result = await get_season_rank(htb_uid) + self.assertEqual(result, "Gold") + + @pytest.mark.asyncio + async def test_get_season_rank_empty_data(self): + htb_uid = 12345 + + with aioresponses.aioresponses() as m: + m.get( + f"{settings.API_V4_URL}/user/achievement/season/{htb_uid}/{settings.SEASON_ID}", + status=200, + payload={"data": None}, + ) + + result = await get_season_rank(htb_uid) + self.assertIsNone(result) + + class TestGetUserDetails(unittest.IsolatedAsyncioTestCase): @pytest.mark.asyncio async def test_get_user_details_success(self):