- decnet/agent/app.py /health: drop leftover 'push-test-2' canary planted during live VM push verification and never cleaned up; test_health_endpoint asserts the exact dict shape. - tests/test_factory.py: switch the lazy-engine check from mysql+aiomysql (not in pyproject) to mysql+asyncmy (the driver the project actually ships). The test does not hit the wire so the dialect swap is safe. Both were red on `pytest tests/` before any config/auto-spawn work began; fixing them here so the upcoming commits land on a green full-suite baseline.
45 lines
1.6 KiB
Python
45 lines
1.6 KiB
Python
"""
|
|
Unit tests for the repository factory — dispatch on DECNET_DB_TYPE.
|
|
"""
|
|
import pytest
|
|
|
|
from decnet.web.db.factory import get_repository
|
|
from decnet.web.db.sqlite.repository import SQLiteRepository
|
|
from decnet.web.db.mysql.repository import MySQLRepository
|
|
|
|
|
|
def test_factory_defaults_to_sqlite(monkeypatch, tmp_path):
|
|
monkeypatch.delenv("DECNET_DB_TYPE", raising=False)
|
|
repo = get_repository(db_path=str(tmp_path / "t.db"))
|
|
assert isinstance(repo, SQLiteRepository)
|
|
|
|
|
|
def test_factory_sqlite_explicit(monkeypatch, tmp_path):
|
|
monkeypatch.setenv("DECNET_DB_TYPE", "sqlite")
|
|
repo = get_repository(db_path=str(tmp_path / "t.db"))
|
|
assert isinstance(repo, SQLiteRepository)
|
|
|
|
|
|
def test_factory_mysql_branch(monkeypatch):
|
|
"""MySQL branch must import and instantiate without a live server.
|
|
|
|
Engine creation is lazy in SQLAlchemy — no socket is opened until the
|
|
first query — so the repository constructs cleanly here.
|
|
"""
|
|
monkeypatch.setenv("DECNET_DB_TYPE", "mysql")
|
|
monkeypatch.setenv("DECNET_DB_URL", "mysql+asyncmy://u:p@127.0.0.1:3306/x")
|
|
repo = get_repository()
|
|
assert isinstance(repo, MySQLRepository)
|
|
|
|
|
|
def test_factory_is_case_insensitive(monkeypatch, tmp_path):
|
|
monkeypatch.setenv("DECNET_DB_TYPE", "SQLite")
|
|
repo = get_repository(db_path=str(tmp_path / "t.db"))
|
|
assert isinstance(repo, SQLiteRepository)
|
|
|
|
|
|
def test_factory_rejects_unknown_type(monkeypatch):
|
|
monkeypatch.setenv("DECNET_DB_TYPE", "cassandra")
|
|
with pytest.raises(ValueError, match="Unsupported database type"):
|
|
get_repository()
|