Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gbtami committed Jan 11, 2025
1 parent 9bb7761 commit 83ed04f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions server/tournament.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
T_ABORTED,
T_FINISHED,
T_ARCHIVED,
SHIELD,
TFreq,
variant_display_name,
MAX_CHAT_LINES,
)
Expand Down Expand Up @@ -1196,7 +1196,7 @@ async def save(self):
for user in self.leaderboard:
await self.db_update_player(user, self.players[user])

if self.frequency == SHIELD:
if self.frequency == TFreq.SHIELD:
variant_name = self.variant + ("960" if self.chess960 else "")
self.app_state.shield[variant_name].append((winner, self.starts_at, self.id))
self.app_state.shield_owners[variant_name] = winner
Expand Down
8 changes: 4 additions & 4 deletions server/tournaments.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
T_ABORTED,
T_FINISHED,
T_ARCHIVED,
SHIELD,
TFreq,
VARIANTS,
MAX_CHAT_LINES,
CATEGORIES,
Expand Down Expand Up @@ -49,7 +49,7 @@ async def create_or_update_tournament(
base = float(form["clockTime"])
inc = int(form["clockIncrement"])
bp = int(form["byoyomiPeriod"])
frequency = SHIELD if form.get("shield", "") == "true" else ""
frequency = TFreq.SHIELD if form.get("shield", "") == "true" else ""

if form["startDate"]:
start_date = datetime.fromisoformat(form["startDate"].rstrip("Z")).replace(
Expand All @@ -63,7 +63,7 @@ async def create_or_update_tournament(
if name == "":
name = "%s Arena" % variant_display_name(variant).title()

if frequency == SHIELD:
if frequency == TFreq.SHIELD:
name = "%s Shield Arena" % variant_display_name(variant).title()
else:
description = form["description"]
Expand Down Expand Up @@ -201,7 +201,7 @@ async def get_winners(app_state: PychessGlobalAppState, shield, variant: str = N

filter_cond = {"v": V2C[v], "z": z, "status": {"$in": [T_FINISHED, T_ARCHIVED]}}
if shield:
filter_cond["fr"] = SHIELD
filter_cond["fr"] = TFreq.SHIELD

winners = []
cursor = app_state.db.tournament.find(filter_cond, sort=[("startsAt", -1)], limit=limit)
Expand Down
4 changes: 2 additions & 2 deletions server/wst.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from admin import silence
from chat import chat_response
from const import ANON_PREFIX, STARTED, SHIELD
from const import ANON_PREFIX, STARTED, TFreq
from const import TYPE_CHECKING

if TYPE_CHECKING:
Expand Down Expand Up @@ -173,7 +173,7 @@ async def handle_user_connected(app_state: PychessGlobalAppState, ws, user, data
),
"chatClosed": (now - tournament.ends_at).total_seconds() > 60 * 60,
}
if tournament.frequency == SHIELD:
if tournament.frequency == TFreq.SHIELD:
variant_name = tournament.variant + ("960" if tournament.chess960 else "")
defender = await app_state.users.get(app_state.shield_owners[variant_name])
response["defender_title"] = defender.title
Expand Down
24 changes: 12 additions & 12 deletions tests/test_scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,42 +3,42 @@
import unittest
import datetime as dt

from const import SHIELD, SCHEDULE_MAX_DAYS
from const import SCHEDULE_MAX_DAYS, TFreq
from scheduler import new_scheduled_tournaments, MONTHLY_VARIANTS, SHIELDS, Scheduler

MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY, SUNDAY = range(7)

# Crazhouse960 Shield scheduled at second MONDAY of month
SHIELD_ZH_2021_09 = (
SHIELD,
TFreq.SHIELD,
"crazyhouse",
True,
dt.datetime(2021, 9, 13, 18, tzinfo=dt.timezone.utc),
180,
)
SHIELD_ZH_2021_10 = (
SHIELD,
TFreq.SHIELD,
"crazyhouse",
True,
dt.datetime(2021, 10, 11, 18, tzinfo=dt.timezone.utc),
180,
)
SHIELD_ZH_2021_11 = (
SHIELD,
TFreq.SHIELD,
"crazyhouse",
True,
dt.datetime(2021, 11, 8, 18, tzinfo=dt.timezone.utc),
180,
)
SHIELD_ZH_2021_12 = (
SHIELD,
TFreq.SHIELD,
"crazyhouse",
True,
dt.datetime(2021, 12, 13, 18, tzinfo=dt.timezone.utc),
180,
)
SHIELD_ZH_2022_01 = (
SHIELD,
TFreq.SHIELD,
"crazyhouse",
True,
dt.datetime(2022, 1, 10, 18, tzinfo=dt.timezone.utc),
Expand All @@ -47,44 +47,44 @@

# Atomic960 Shield scheduled at third SUNDAY of month
SHIELD_ATOMIC_2021_10 = (
SHIELD,
TFreq.SHIELD,
"atomic",
True,
dt.datetime(2021, 10, 17, 12, tzinfo=dt.timezone.utc),
180,
)
SHIELD_ATOMIC_2021_11 = (
SHIELD,
TFreq.SHIELD,
"atomic",
True,
dt.datetime(2021, 11, 14, 12, tzinfo=dt.timezone.utc),
180,
)
SHIELD_ATOMIC_2021_12 = (
SHIELD,
TFreq.SHIELD,
"atomic",
True,
dt.datetime(2021, 12, 19, 12, tzinfo=dt.timezone.utc),
180,
)
SHIELD_ATOMIC_2022_01 = (
SHIELD,
TFreq.SHIELD,
"atomic",
True,
dt.datetime(2022, 1, 16, 12, tzinfo=dt.timezone.utc),
180,
)

SHIELD_KOTH_2024_10 = (
SHIELD,
TFreq.SHIELD,
"kingofthehill",
True,
dt.datetime(2024, 10, 7, 18, tzinfo=dt.timezone.utc),
180,
)

SHIELD_KOTH_2024_11 = (
SHIELD,
TFreq.SHIELD,
"kingofthehill",
True,
dt.datetime(2024, 11, 4, 19, tzinfo=dt.timezone.utc),
Expand Down

0 comments on commit 83ed04f

Please sign in to comment.