From 80ca5d6d801020b6d72cc2a135f7806b13e730ba Mon Sep 17 00:00:00 2001 From: ddc <34492089+ddc@users.noreply.github.com> Date: Wed, 25 Feb 2026 17:36:06 -0300 Subject: [PATCH] v3.0.6 --- src/database/dal/gw2/gw2_sessions_dal.py | 8 ++++---- src/gw2/tools/gw2_utils.py | 4 ++-- tests/integration/test_gw2_api_public.py | 2 +- tests/unit/gw2/tools/test_gw2_utils.py | 16 ++++++++-------- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/database/dal/gw2/gw2_sessions_dal.py b/src/database/dal/gw2/gw2_sessions_dal.py index 6a765ee..f788086 100644 --- a/src/database/dal/gw2/gw2_sessions_dal.py +++ b/src/database/dal/gw2/gw2_sessions_dal.py @@ -11,13 +11,13 @@ def __init__(self, db_session, log): self.log = log async def insert_start_session(self, session: dict): - stmt = sa.delete(Gw2Sessions).where( - Gw2Sessions.user_id == session["user_id"], + stmt = sa.delete(Gw2SessionChars).where( + Gw2SessionChars.user_id == session["user_id"], ) await self.db_utils.execute(stmt) - stmt = sa.delete(Gw2SessionChars).where( - Gw2SessionChars.user_id == session["user_id"], + stmt = sa.delete(Gw2Sessions).where( + Gw2Sessions.user_id == session["user_id"], ) await self.db_utils.execute(stmt) diff --git a/src/gw2/tools/gw2_utils.py b/src/gw2/tools/gw2_utils.py index dfa0fdb..01cd8cf 100644 --- a/src/gw2/tools/gw2_utils.py +++ b/src/gw2/tools/gw2_utils.py @@ -454,7 +454,8 @@ async def get_user_stats(bot: Bot, api_key: str) -> dict | None: # Fetch data from multiple endpoints account_data = await gw2_api.call_api("account", api_key) wallet_data = await gw2_api.call_api("account/wallet", api_key) - achievements_data = await gw2_api.call_api("account/achievements", api_key) + achievement_ids = ",".join(str(k) for k in ACHIEVEMENT_MAPPING) + achievements_data = await gw2_api.call_api(f"account/achievements?ids={achievement_ids}", api_key) except Exception as e: bot.log.error(f"Error fetching user stats: {e}") @@ -472,7 +473,6 @@ def _create_initial_user_stats(account_data: dict) -> dict: wvw_rank = account_data.get("wvw", {}).get("rank") or account_data.get("wvw_rank", 0) stats = { "acc_name": account_data["name"], - "age": account_data.get("age", 0), "wvw_rank": wvw_rank, "players": 0, "yaks_scorted": 0, diff --git a/tests/integration/test_gw2_api_public.py b/tests/integration/test_gw2_api_public.py index 60e407f..5911600 100644 --- a/tests/integration/test_gw2_api_public.py +++ b/tests/integration/test_gw2_api_public.py @@ -10,7 +10,7 @@ from src.gw2.constants.gw2_currencies import ACHIEVEMENT_MAPPING, WALLET_MAPPING GW2_API_BASE = "https://api.guildwars2.com/v2" -REQUEST_TIMEOUT = 30 +REQUEST_TIMEOUT = 60 def _fetch_json(url: str) -> dict | list: diff --git a/tests/unit/gw2/tools/test_gw2_utils.py b/tests/unit/gw2/tools/test_gw2_utils.py index 5cabbeb..5ea7e67 100644 --- a/tests/unit/gw2/tools/test_gw2_utils.py +++ b/tests/unit/gw2/tools/test_gw2_utils.py @@ -954,7 +954,7 @@ async def test_api_exception_returns_none(self, mock_bot): @pytest.mark.asyncio async def test_successful_stats_retrieval(self, mock_bot): """Test successful user stats retrieval with legacy wvw_rank.""" - account_data = {"name": "TestUser.1234", "wvw_rank": 50, "age": 5000000} + account_data = {"name": "TestUser.1234", "wvw_rank": 50} wallet_data = [ {"id": 1, "value": 50000}, # gold {"id": 2, "value": 100000}, # karma @@ -973,7 +973,7 @@ async def test_successful_stats_retrieval(self, mock_bot): assert result is not None assert result["acc_name"] == "TestUser.1234" - assert result["age"] == 5000000 + assert "age" not in result assert result["wvw_rank"] == 50 assert result["gold"] == 50000 assert result["karma"] == 100000 @@ -1737,12 +1737,12 @@ class TestCreateInitialUserStats: def test_creates_correct_structure(self): """Test that initial stats structure is correct with legacy wvw_rank.""" - account_data = {"name": "TestUser.1234", "wvw_rank": 75, "age": 5000000} + account_data = {"name": "TestUser.1234", "wvw_rank": 75} result = _create_initial_user_stats(account_data) assert result["acc_name"] == "TestUser.1234" - assert result["age"] == 5000000 + assert "age" not in result assert result["wvw_rank"] == 75 assert result["gold"] == 0 assert result["karma"] == 0 @@ -1773,11 +1773,11 @@ def test_all_wallet_currencies_initialized(self): for stat_name in WALLET_MAPPING.values(): assert result[stat_name] == 0, f"{stat_name} should be initialized to 0" - def test_age_defaults_to_zero(self): - """Test that age defaults to 0 when not in account data.""" - account_data = {"name": "TestUser.1234", "wvw_rank": 0} + def test_age_not_included_in_session_stats(self): + """Test that age is not included in session stats.""" + account_data = {"name": "TestUser.1234", "wvw_rank": 0, "age": 5000000} result = _create_initial_user_stats(account_data) - assert result["age"] == 0 + assert "age" not in result def test_new_wvw_rank_format(self): """Test that wvw.rank (new API format) is preferred over wvw_rank."""