feat: add database module with schema initialization
Made-with: Cursor
This commit is contained in:
30
tests/test_db.py
Normal file
30
tests/test_db.py
Normal file
@@ -0,0 +1,30 @@
|
||||
import sqlite3
|
||||
|
||||
import pytest
|
||||
|
||||
from ntr_fetcher.db import Database
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def db(tmp_path):
|
||||
db_path = str(tmp_path / "test.db")
|
||||
database = Database(db_path)
|
||||
database.initialize()
|
||||
return database
|
||||
|
||||
|
||||
def test_tables_created(db):
|
||||
conn = sqlite3.connect(db.path)
|
||||
cursor = conn.execute(
|
||||
"SELECT name FROM sqlite_master WHERE type='table' ORDER BY name"
|
||||
)
|
||||
tables = [row[0] for row in cursor.fetchall()]
|
||||
conn.close()
|
||||
assert "tracks" in tables
|
||||
assert "shows" in tables
|
||||
assert "show_tracks" in tables
|
||||
|
||||
|
||||
def test_initialize_idempotent(db):
|
||||
"""Calling initialize twice doesn't raise."""
|
||||
db.initialize()
|
||||
Reference in New Issue
Block a user