lotto-lab: DB 스키마 확장 — purchase_history ALTER + strategy 테이블 추가
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
69
backend/tests/test_purchase_manager.py
Normal file
69
backend/tests/test_purchase_manager.py
Normal file
@@ -0,0 +1,69 @@
|
||||
# backend/tests/test_purchase_manager.py
|
||||
import sys, os
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), "..", "app"))
|
||||
|
||||
import sqlite3
|
||||
import pytest
|
||||
from unittest.mock import patch, MagicMock
|
||||
|
||||
# ":memory:" 공유 커넥션 — 각 테스트에서 독립적으로 생성
|
||||
def _make_mem_conn():
|
||||
conn = sqlite3.connect(":memory:")
|
||||
conn.row_factory = sqlite3.Row
|
||||
return conn
|
||||
|
||||
|
||||
def test_purchase_history_has_new_columns():
|
||||
"""purchase_history 테이블에 신규 컬럼이 존재하는지 검증"""
|
||||
import db
|
||||
mem = _make_mem_conn()
|
||||
with patch("db._conn", return_value=mem):
|
||||
db.init_db()
|
||||
|
||||
cols = {r["name"] for r in mem.execute("PRAGMA table_info(purchase_history)").fetchall()}
|
||||
assert "numbers" in cols
|
||||
assert "is_real" in cols
|
||||
assert "source_strategy" in cols
|
||||
assert "source_detail" in cols
|
||||
assert "checked" in cols
|
||||
assert "results" in cols
|
||||
assert "total_prize" in cols
|
||||
# 기존 컬럼도 유지
|
||||
assert "draw_no" in cols
|
||||
assert "amount" in cols
|
||||
assert "sets" in cols
|
||||
assert "prize" in cols
|
||||
assert "note" in cols
|
||||
mem.close()
|
||||
|
||||
|
||||
def test_strategy_performance_table_exists():
|
||||
"""strategy_performance 테이블이 생성되는지 검증"""
|
||||
import db
|
||||
mem = _make_mem_conn()
|
||||
with patch("db._conn", return_value=mem):
|
||||
db.init_db()
|
||||
|
||||
cols = {r["name"] for r in mem.execute("PRAGMA table_info(strategy_performance)").fetchall()}
|
||||
assert "strategy" in cols
|
||||
assert "draw_no" in cols
|
||||
assert "sets_count" in cols
|
||||
assert "total_correct" in cols
|
||||
assert "avg_score" in cols
|
||||
mem.close()
|
||||
|
||||
|
||||
def test_strategy_weights_table_exists():
|
||||
"""strategy_weights 테이블이 생성되고 초기값이 있는지 검증"""
|
||||
import db
|
||||
mem = _make_mem_conn()
|
||||
with patch("db._conn", return_value=mem):
|
||||
db.init_db()
|
||||
|
||||
rows = mem.execute("SELECT * FROM strategy_weights ORDER BY strategy").fetchall()
|
||||
strategies = {r["strategy"] for r in rows}
|
||||
assert strategies == {"combined", "simulation", "heatmap", "manual", "custom"}
|
||||
# 가중치 합이 1.0
|
||||
total_weight = sum(r["weight"] for r in rows)
|
||||
assert abs(total_weight - 1.0) < 0.01
|
||||
mem.close()
|
||||
Reference in New Issue
Block a user