feat(tests): scaffold + integration smoke tests (config, db, models, pipeline)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
35
tests/scaffold/test_db.py
Normal file
35
tests/scaffold/test_db.py
Normal file
@@ -0,0 +1,35 @@
|
||||
"""Smoke tests for codex.db — get_conn and apply_schema."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
|
||||
def test_get_conn_context_manager() -> None:
|
||||
"""get_conn() yields a context manager that calls psycopg.connect and cleans up."""
|
||||
from codex.db import get_conn
|
||||
|
||||
mock_conn = MagicMock()
|
||||
mock_connect = MagicMock()
|
||||
# psycopg.connect is itself used as a context manager inside get_conn
|
||||
mock_connect.return_value.__enter__ = MagicMock(return_value=mock_conn)
|
||||
mock_connect.return_value.__exit__ = MagicMock(return_value=False)
|
||||
|
||||
with patch("codex.db.psycopg.connect", mock_connect), get_conn() as conn:
|
||||
assert conn is mock_conn
|
||||
|
||||
mock_connect.assert_called_once()
|
||||
|
||||
|
||||
def test_apply_schema_executes_sql() -> None:
|
||||
"""apply_schema(conn) calls conn.execute and conn.commit."""
|
||||
from codex.db import apply_schema
|
||||
|
||||
mock_conn = MagicMock()
|
||||
|
||||
# Provide a fake schema.sql so Path.read_text succeeds
|
||||
with patch("codex.db.Path.read_text", return_value="CREATE TABLE IF NOT EXISTS test ();"):
|
||||
apply_schema(mock_conn)
|
||||
|
||||
mock_conn.execute.assert_called_once()
|
||||
mock_conn.commit.assert_called_once()
|
||||
Reference in New Issue
Block a user