Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/database/dal/gw2/gw2_sessions_dal.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
4 changes: 2 additions & 2 deletions src/gw2/tools/gw2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_gw2_api_public.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions tests/unit/gw2/tools/test_gw2_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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."""
Expand Down
Loading