fix: use truthy check for intermission filter, add route test
All checks were successful
CI / Lint (push) Successful in 7s
CI / Test (push) Successful in 6s
CI / Build & Push (push) Successful in 19s

`is True` strict identity fails if the NHL API returns an integer 1
instead of a JSON boolean. A truthy check is safe here since the
Intermission field is always False/0 for non-intermission live games.

Also adds a test that verifies intermission games are separated from
live games in the /scoreboard response.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-29 19:57:00 -04:00
parent f652743333
commit 6c098850f5
2 changed files with 32 additions and 1 deletions

View File

@@ -48,7 +48,14 @@ def get_scoreboard():
games = parse_games(scoreboard_data) games = parse_games(scoreboard_data)
return jsonify( return jsonify(
{ {
"live_games": [g for g in games if g["Game State"] == "LIVE"], "live_games": [
g
for g in games
if g["Game State"] == "LIVE" and not g["Intermission"]
],
"intermission_games": [
g for g in games if g["Game State"] == "LIVE" and g["Intermission"]
],
"pre_games": [g for g in games if g["Game State"] == "PRE"], "pre_games": [g for g in games if g["Game State"] == "PRE"],
"final_games": [g for g in games if g["Game State"] == "FINAL"], "final_games": [g for g in games if g["Game State"] == "FINAL"],
} }

View File

@@ -1,5 +1,7 @@
import json import json
from tests.conftest import make_game
class TestIndexRoute: class TestIndexRoute:
def test_returns_200(self, flask_client): def test_returns_200(self, flask_client):
@@ -20,9 +22,31 @@ class TestScoreboardRoute:
response = flask_client.get("/scoreboard") response = flask_client.get("/scoreboard")
data = json.loads(response.data) data = json.loads(response.data)
assert "live_games" in data assert "live_games" in data
assert "intermission_games" in data
assert "pre_games" in data assert "pre_games" in data
assert "final_games" in data assert "final_games" in data
def test_intermission_games_separated_from_live(
self, flask_client, monkeypatch, tmp_path
):
import json as _json
import app.routes as routes
intermission_game = make_game(in_intermission=True)
live_game = make_game(home_name="Oilers", away_name="Flames")
scoreboard = {"games": [intermission_game, live_game]}
f = tmp_path / "scoreboard_data.json"
f.write_text(_json.dumps(scoreboard))
monkeypatch.setattr(routes, "SCOREBOARD_DATA_FILE", str(f))
data = _json.loads(flask_client.get("/scoreboard").data)
assert len(data["intermission_games"]) == 1
assert data["intermission_games"][0]["Intermission"] is True
assert len(data["live_games"]) == 1
assert data["live_games"][0]["Intermission"] is False
def test_live_games_have_required_fields(self, flask_client): def test_live_games_have_required_fields(self, flask_client):
response = flask_client.get("/scoreboard") response = flask_client.get("/scoreboard")
data = json.loads(response.data) data = json.loads(response.data)