From 57f7dff3841ad33cf777b5aa1c990aff30ae3a2d Mon Sep 17 00:00:00 2001 From: Navis <83245135+NavisGames@users.noreply.github.com> Date: Sat, 18 Jan 2025 19:01:38 +0100 Subject: [PATCH] Add Account V2 --- tests/e2e/test_account_details.py | 4 ++-- .../mock_responses/account_details_v2.json | 16 ++++++++++++++++ tests/unit/endpoints/test_account_details.py | 8 ++++---- valo_api/endpoints_config.py | 8 +++++--- valo_api/responses/account_details.py | 6 ++++-- 5 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 tests/unit/endpoints/mock_responses/account_details_v2.json diff --git a/tests/e2e/test_account_details.py b/tests/e2e/test_account_details.py index 5d1cf0b3..e84a2f24 100644 --- a/tests/e2e/test_account_details.py +++ b/tests/e2e/test_account_details.py @@ -10,7 +10,7 @@ @settings(deadline=None, max_examples=15) @given( - version=st.sampled_from(["v1"]), + version=st.sampled_from(["v1", "v2"]), id=st.sampled_from(["ManuelHexe#5777", "jasminaxrose#7024"]), force_update=st.booleans(), ) @@ -34,7 +34,7 @@ async def test_get_account_details_by_name(version: str, id: str, force_update: @settings(deadline=None, max_examples=15) @given( - version=st.sampled_from(["v1"]), + version=st.sampled_from(["v1", "v2"]), puuid=st.sampled_from( ["ee89b4d9-13d0-5832-8dd7-eb5d8806d918", "930bb0d3-c914-5394-bcf6-0bc81f465bd7"] ), diff --git a/tests/unit/endpoints/mock_responses/account_details_v2.json b/tests/unit/endpoints/mock_responses/account_details_v2.json new file mode 100644 index 00000000..f935d496 --- /dev/null +++ b/tests/unit/endpoints/mock_responses/account_details_v2.json @@ -0,0 +1,16 @@ +{ + "status": 200, + "data": { + "puuid": "ee89b4d9-13d0-5832-8dd7-eb5d8806d918", + "region": "eu", + "account_level": 137, + "name": "ManuelHexe", + "tag": "5777", + "card": "6f39b789-4318-f79e-14e9-0a872f6ba6a2", + "title": "bc6a30d8-4d83-82aa-dfe9-7389c776f312", + "platforms": [ + "PC" + ], + "updated_at": "2024-07-13T15:39:34.015Z" + } +} diff --git a/tests/unit/endpoints/test_account_details.py b/tests/unit/endpoints/test_account_details.py index 1f3cae8d..a765b23d 100644 --- a/tests/unit/endpoints/test_account_details.py +++ b/tests/unit/endpoints/test_account_details.py @@ -18,7 +18,7 @@ @given( - version=st.sampled_from(["v1"]), + version=st.sampled_from(["v1", "v2"]), name=st.text(), tag=st.text(), force_update=st.booleans(), @@ -78,7 +78,7 @@ async def test_get_account_details_by_name( @given( - version=st.sampled_from(["v1"]), + version=st.sampled_from(["v1", "v2"]), name=st.text(), tag=st.text(), force_update=st.booleans(), @@ -149,7 +149,7 @@ async def test_get_account_details_by_name_error( @given( - version=st.sampled_from(["v1"]), + version=st.sampled_from(["v1", "v2"]), puuid=st.uuids(), force_update=st.booleans(), ) @@ -208,7 +208,7 @@ async def test_get_account_details_by_puuid( @given( - version=st.sampled_from(["v1"]), + version=st.sampled_from(["v1", "v2"]), puuid=st.uuids(), force_update=st.booleans(), error_response=st.sampled_from(get_error_responses("account_details")), diff --git a/valo_api/endpoints_config.py b/valo_api/endpoints_config.py index 2f430b86..acdf3d6e 100644 --- a/valo_api/endpoints_config.py +++ b/valo_api/endpoints_config.py @@ -6,7 +6,7 @@ from PIL import Image from valo_api.endpoint import Endpoint -from valo_api.responses.account_details import AccountDetailsV1 +from valo_api.responses.account_details import AccountDetails from valo_api.responses.competitive_updates_raw import CompetitiveUpdatesRawV1 from valo_api.responses.content import ContentV1 from valo_api.responses.leaderboard import LeaderboardPlayerV1, LeaderboardV2 @@ -187,7 +187,8 @@ class EndpointsConfig(Enum): ACCOUNT_BY_NAME = Endpoint( path="/valorant/{version}/account/{name}/{tag}", f_name="get_account_details_by_name", - return_type=AccountDetailsV1, + versions=["v1", "v2"], + return_type=AccountDetails, kwargs=OrderedDict( [("version", str), ("name", str), ("tag", str), ("force_update", bool)] ), @@ -196,7 +197,8 @@ class EndpointsConfig(Enum): ACCOUNT_BY_PUUID = Endpoint( path="/valorant/{version}/by-puuid/account/{puuid}", f_name="get_account_details_by_puuid", - return_type=AccountDetailsV1, + versions=["v1", "v2"], + return_type=AccountDetails, kwargs=OrderedDict([("version", str), ("puuid", str), ("force_update", bool)]), query_args=OrderedDict([("force", "{force_update}")]), ) diff --git a/valo_api/responses/account_details.py b/valo_api/responses/account_details.py index 719ebe44..79cc154c 100644 --- a/valo_api/responses/account_details.py +++ b/valo_api/responses/account_details.py @@ -10,12 +10,14 @@ class AccountCardV1(DictStruct): wide: str -class AccountDetailsV1(DictStruct): +class AccountDetails(DictStruct): puuid: str region: str account_level: int name: str tag: str - card: Optional[AccountCardV1] = None + card: Optional[AccountCardV1 | str] = None + title: Optional[str] = None + updated_at: Optional[str] = None last_update: Optional[str] = None last_update_raw: Optional[int] = None