feat: add SQLAlchemy models for Category, CategoryWord, Game, Word

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Mathew Sir Guest the best
2026-05-06 22:36:35 -06:00
co-authored by Claude Opus 4.6
parent 2930adb51d
commit 041b768cd4
5 changed files with 166 additions and 0 deletions
+74
View File
@@ -0,0 +1,74 @@
from models.category import Category, CategoryWord
from models.game import Game, Word
def test_create_category(db_session):
cat = Category(name="animals")
db_session.add(cat)
db_session.commit()
assert cat.id is not None
assert cat.name == "animals"
def test_create_category_word(db_session):
cat = Category(name="animals")
db_session.add(cat)
db_session.flush()
word = CategoryWord(category_id=cat.id, word="TIGER")
db_session.add(word)
db_session.commit()
assert word.category_id == cat.id
assert word.word == "TIGER"
def test_create_game(db_session):
cat = Category(name="animals")
db_session.add(cat)
db_session.flush()
game = Game(
category_id=cat.id,
board_size=10,
grid=[["A"] * 10 for _ in range(10)],
)
db_session.add(game)
db_session.commit()
assert game.id is not None
assert len(game.id) == 36 # UUID
assert game.status == "in_progress"
assert game.started_at is not None
assert game.completed_at is None
def test_create_word(db_session):
cat = Category(name="animals")
db_session.add(cat)
db_session.flush()
game = Game(category_id=cat.id, board_size=10, grid=[])
db_session.add(game)
db_session.flush()
word = Word(
game_id=game.id,
text="TIGER",
start_row=0,
start_col=0,
direction="E",
)
db_session.add(word)
db_session.commit()
assert word.found is False
assert word.found_at is None
def test_game_words_relationship(db_session):
cat = Category(name="animals")
db_session.add(cat)
db_session.flush()
game = Game(category_id=cat.id, board_size=10, grid=[])
db_session.add(game)
db_session.flush()
w1 = Word(game_id=game.id, text="TIGER", start_row=0, start_col=0, direction="E")
w2 = Word(game_id=game.id, text="LION", start_row=1, start_col=0, direction="S")
db_session.add_all([w1, w2])
db_session.commit()
db_session.refresh(game)
assert len(game.words) == 2