feat(stock-lab): screener 스키마 7테이블 + 디폴트 설정 시드
This commit is contained in:
37
stock-lab/app/test_screener_schema.py
Normal file
37
stock-lab/app/test_screener_schema.py
Normal file
@@ -0,0 +1,37 @@
|
||||
import sqlite3
|
||||
from app.screener.schema import ensure_screener_schema
|
||||
|
||||
|
||||
def test_creates_all_tables(tmp_path):
|
||||
db_path = tmp_path / "test.db"
|
||||
conn = sqlite3.connect(db_path)
|
||||
ensure_screener_schema(conn)
|
||||
|
||||
tables = {r[0] for r in conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table'"
|
||||
).fetchall()}
|
||||
|
||||
expected = {
|
||||
"krx_master", "krx_daily_prices", "krx_flow",
|
||||
"screener_settings", "screener_runs", "screener_results",
|
||||
}
|
||||
assert expected.issubset(tables)
|
||||
|
||||
|
||||
def test_settings_seeded_with_singleton_row(tmp_path):
|
||||
db_path = tmp_path / "test.db"
|
||||
conn = sqlite3.connect(db_path)
|
||||
ensure_screener_schema(conn)
|
||||
|
||||
rows = conn.execute("SELECT id FROM screener_settings").fetchall()
|
||||
assert rows == [(1,)]
|
||||
|
||||
|
||||
def test_idempotent(tmp_path):
|
||||
db_path = tmp_path / "test.db"
|
||||
conn = sqlite3.connect(db_path)
|
||||
ensure_screener_schema(conn)
|
||||
ensure_screener_schema(conn) # 두 번 호출해도 에러 없어야 함
|
||||
|
||||
rows = conn.execute("SELECT count(*) FROM screener_settings").fetchall()
|
||||
assert rows == [(1,)]
|
||||
Reference in New Issue
Block a user