Skip to content

Commit

Permalink
Accommodate sqlalchemy changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BlackYps committed Jun 4, 2024
1 parent 419d9f0 commit b1eb9be
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
19 changes: 8 additions & 11 deletions service/league_service/league_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,11 @@ async def update_data(self):
async with self._db.acquire() as conn:
sql = (
select(
[
league_season,
league,
league_season_division,
league_season_division_subdivision,
leaderboard,
],
use_labels=True,
league_season,
league,
league_season_division,
league_season_division_subdivision,
leaderboard,
)
.select_from(
league_season_division_subdivision.outerjoin(league_season_division)
Expand Down Expand Up @@ -148,7 +145,7 @@ async def _rate_single_league(self, league: League, request: LeagueRatingRequest

async def _load_score(self, player_id: PlayerID, league: League) -> LeagueScore:
async with self._db.acquire() as conn:
sql = select([league_season_score]).where(
sql = select(league_season_score).where(
and_(
league_season_score.c.login_id == player_id,
league_season_score.c.league_season_id == league.current_season_id,
Expand All @@ -170,7 +167,7 @@ async def _load_score(self, player_id: PlayerID, league: League) -> LeagueScore:
async def is_returning_player(self, player_id: PlayerID, rating_type: str) -> bool:
async with self._db.acquire() as conn:
sql = (
select([league_season_score])
select(league_season_score)
.select_from(
league_season_score.outerjoin(league_season)
.outerjoin(leaderboard))
Expand Down Expand Up @@ -203,7 +200,7 @@ async def _persist_score(
raise InvalidScoreError("Missing score for non-null division.")

select_season_id = (
select([league_season_division.c.league_season_id])
select(league_season_division.c.league_season_id)
.select_from(
league_season_division_subdivision.outerjoin(
league_season_division
Expand Down
14 changes: 7 additions & 7 deletions service/season_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def initialize(self):
async def check_season_end(self):
self._logger.debug("Checking if latest season ends soon.")
async with self._db.acquire() as conn:
sql = select([league_season])
sql = select(league_season)
result = await conn.execute(sql)
rows = await result.fetchall()

Expand All @@ -43,7 +43,7 @@ async def check_season_end(self):
async def generate_season(self):
self._logger.info("Generating new season...")
async with self._db.acquire() as conn:
sql = select([league]).where(league.c.enabled == True)
sql = select(league).where(league.c.enabled == True)
result = await conn.execute(sql)
rows = await result.fetchall()

Expand All @@ -57,7 +57,7 @@ async def generate_season(self):

async def update_db(self, conn, league_row, start_date, end_date):
season_sql = (
select([league_season])
select(league_season)
.where(league_season.c.league_id == league_row[league.c.id])
.order_by(desc(league_season.c.season_number))
.limit(1)
Expand All @@ -70,7 +70,7 @@ async def update_db(self, conn, league_row, start_date, end_date):
league_row[league.c.technical_name]
)
return
result = await conn.execute(select([func.max(league_season.c.id)]))
result = await conn.execute(select(func.max(league_season.c.id)))
season_id = await result.scalar() + 1
season_number = season_row[league_season.c.season_number] + 1
season_insert_sql = (
Expand All @@ -89,7 +89,7 @@ async def update_db(self, conn, league_row, start_date, end_date):
await conn.execute(season_insert_sql)

division_sql = (
select([league_season_division])
select(league_season_division)
.where(league_season_division.c.league_season_id == season_row[league_season.c.id])
)
result = await conn.execute(division_sql)
Expand All @@ -102,7 +102,7 @@ async def update_db(self, conn, league_row, start_date, end_date):
season_id
)
return
result = await conn.execute(select([func.max(league_season_division.c.id)]))
result = await conn.execute(select(func.max(league_season_division.c.id)))
division_id = await result.scalar()
for division_row in season_division_rows:
division_index = division_row[league_season_division.c.division_index]
Expand All @@ -122,7 +122,7 @@ async def update_db(self, conn, league_row, start_date, end_date):
await conn.execute(division_insert_sql)

subdivision_sql = (
select([league_season_division_subdivision])
select(league_season_division_subdivision)
.where(league_season_division_subdivision.c.league_season_division_id ==
division_row[league_season_division.c.id])
)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_league_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ async def test_persist_score_new_player(league_service, database):
assert loaded_score == new_score

async with database.acquire() as conn:
result = await conn.execute(select([league_score_journal]))
result = await conn.execute(select(league_score_journal))
rows = await result.fetchall()
assert len(rows) == 1
for row in rows:
Expand Down Expand Up @@ -215,7 +215,7 @@ async def test_persist_score_old_player(league_service, database):
assert loaded_score == new_score

async with database.acquire() as conn:
result = await conn.execute(select([league_score_journal]))
result = await conn.execute(select(league_score_journal))
rows = await result.fetchall()
assert len(rows) == 1
for row in rows:
Expand Down
4 changes: 2 additions & 2 deletions tests/unit_tests/test_season_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ async def test_season_check_after_season_end(season_generator):
async def test_generate_season(season_generator, database):
await season_generator.generate_season()
async with database.acquire() as conn:
seasons = await conn.execute(select([league_season]))
seasons = await conn.execute(select(league_season))
rows = await seasons.fetchall()
assert len(rows) == 6
assert max(row[league_season.c.season_number] for row in rows) == 4
Expand Down Expand Up @@ -77,7 +77,7 @@ async def test_generate_season_only_once(season_generator, database):
await season_generator.check_season_end()
await season_generator.check_season_end()
async with database.acquire() as conn:
seasons = await conn.execute(select([league_season]))
seasons = await conn.execute(select(league_season))
rows = await seasons.fetchall()
assert len(rows) == 6
assert max(row[league_season.c.season_number] for row in rows) == 4

0 comments on commit b1eb9be

Please sign in to comment.