Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
75 lines
2.0 KiB
Python
75 lines
2.0 KiB
Python
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
|