fix: resolve 4 logic bugs found in code review
- utc_to_eastern: use zoneinfo instead of hardcoded EDT offset (-4) so start times are correct in both EST and EDT - standings: fetch before truncate so a failed API call doesn't wipe existing standings data - routes: call parse_games() once per request instead of three times - scheduler: wrap run_pending() in try/except so an unhandled exception doesn't kill the background thread Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -209,12 +209,25 @@ class TestRefreshStandings:
|
||||
assert count == 2
|
||||
|
||||
def test_does_not_insert_when_fetch_fails(self, mocker, tmp_path):
|
||||
mocker.patch("app.standings.fetch_standings", return_value=None)
|
||||
mocker.patch("app.standings.DB_PATH", str(tmp_path / "test.db"))
|
||||
db_path = str(tmp_path / "test.db")
|
||||
mocker.patch("app.standings.DB_PATH", db_path)
|
||||
|
||||
# Seed with existing data before the failed refresh
|
||||
seed = [
|
||||
{
|
||||
"team_common_name": "Bruins",
|
||||
"league_sequence": 1,
|
||||
"league_l10_sequence": 2,
|
||||
}
|
||||
]
|
||||
mocker.patch("app.standings.fetch_standings", return_value=seed)
|
||||
refresh_standings()
|
||||
|
||||
conn = sqlite3.connect(str(tmp_path / "test.db"))
|
||||
# Now simulate a fetch failure — existing data must be preserved
|
||||
mocker.patch("app.standings.fetch_standings", return_value=None)
|
||||
refresh_standings()
|
||||
|
||||
conn = sqlite3.connect(db_path)
|
||||
count = conn.execute("SELECT COUNT(*) FROM standings").fetchone()[0]
|
||||
conn.close()
|
||||
assert count == 0
|
||||
assert count == 1
|
||||
|
||||
Reference in New Issue
Block a user