paper-dynasty-discord/tests/gameplay_models/test_team_model.py
Cal Corum ee80cd72ae fix: apply Black formatting and resolve ruff lint violations
Run Black formatter across 83 files and fix 1514 ruff violations:
- E722: bare except → typed exceptions (17 fixes)
- E711/E712/E721: comparison style fixes with noqa for SQLAlchemy (44 fixes)
- F841: unused variable assignments (70 fixes)
- F541/F401: f-string and import cleanup (1383 auto-fixes)

Remaining 925 errors are all F403/F405 (star imports) — structural,
requires converting to explicit imports in a separate effort.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-09 11:37:46 -05:00

51 lines
1.6 KiB
Python

import datetime
from sqlmodel import Session
from in_game.gameplay_models import Team, CACHE_LIMIT
from in_game.gameplay_queries import get_team_or_none
from tests.factory import create_incomplete_team, pytest
def test_create_team(session: Session):
team_31 = session.get(Team, 31)
team_400 = session.get(Team, 400)
team_69 = session.get(Team, 69)
team_420 = session.get(Team, 420)
team_3 = session.get(Team, 3)
assert team_31.abbrev == "NCB"
assert team_400.abbrev == "WV"
assert team_69.abbrev == "NCB3"
assert team_420.abbrev == "WV4"
assert team_3.abbrev == "BAL"
def test_create_incomplete_team(session: Session):
team_1 = create_incomplete_team(session)
session.add(team_1)
from sqlalchemy.exc import IntegrityError
with pytest.raises(IntegrityError) as exc_info:
session.commit()
# Check that it's a NOT NULL constraint violation for ranking field (database agnostic)
assert "ranking" in str(exc_info.value)
assert "null" in str(exc_info.value).lower()
async def test_team_cache(session: Session):
team_31 = session.get(Team, 31)
team_3 = session.get(Team, 3)
assert (datetime.datetime.now() - team_3.created).total_seconds() > CACHE_LIMIT
new_team_31 = await get_team_or_none(session, team_id=team_31.id)
new_team_3 = await get_team_or_none(session, team_id=team_3.id)
new_team_4 = await get_team_or_none(session, team_abbrev="NYY")
assert team_31.created == new_team_31.created
assert (datetime.datetime.now() - new_team_3.created).total_seconds() < CACHE_LIMIT
assert new_team_4.created is not None