fix: make signal source orchestration sqlite-safe
This commit is contained in:
parent
2860f11cec
commit
d4691f1276
|
|
@ -54,3 +54,6 @@ COMPLETE_WORKER_WAIT_TIMEOUT_SECONDS = 6.0
|
|||
|
||||
def _utc_now_naive() -> datetime:
|
||||
return now_cn_naive()
|
||||
|
||||
|
||||
__all__ = [name for name in globals() if not name.startswith("__")]
|
||||
|
|
|
|||
|
|
@ -1,12 +1,15 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from datetime import datetime
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import JSON, select
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
os.environ["DATABASE_URL"] = "sqlite+aiosqlite:///:memory:"
|
||||
|
||||
from app.models.base import Base
|
||||
from app.models.project import Project
|
||||
from app.models.project_signal_link import ProjectSignalLink
|
||||
|
|
@ -17,9 +20,17 @@ from app.models.user_project import UserProject
|
|||
from app.services.signal.signal_capture_service import ProactiveSignalCaptureService
|
||||
|
||||
|
||||
def _use_sqlite_json_types() -> None:
|
||||
for table in (User.__table__, SignalSourceRegistry.__table__):
|
||||
for column in table.columns:
|
||||
if column.name in {"assigned_domains", "config", "raw_context"}:
|
||||
column.type = JSON()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def db_session():
|
||||
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
_use_sqlite_json_types()
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(
|
||||
lambda sync_conn: Base.metadata.create_all(
|
||||
|
|
@ -126,6 +137,7 @@ async def test_auto_create_project_from_new_signal_persists_signal_sources(db_se
|
|||
signal_row = (
|
||||
await db_session.execute(select(Signal).where(Signal.id == int(signal.id), Signal.tenant_id == 1))
|
||||
).scalar_one()
|
||||
await db_session.refresh(signal_row)
|
||||
assert signal_row.processed is True
|
||||
|
||||
registries = (
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
|
||||
import pytest
|
||||
import pytest_asyncio
|
||||
from sqlalchemy import select
|
||||
from sqlalchemy import JSON, select
|
||||
from sqlalchemy.ext.asyncio import async_sessionmaker, create_async_engine
|
||||
|
||||
os.environ["DATABASE_URL"] = "sqlite+aiosqlite:///:memory:"
|
||||
|
||||
from app.models.base import Base
|
||||
from app.models.project import Project
|
||||
from app.models.signal import Signal
|
||||
|
|
@ -13,9 +17,17 @@ from app.models.user import User
|
|||
from app.services.signal.signal_source_orchestration import SignalSourceOrchestrationService
|
||||
|
||||
|
||||
def _use_sqlite_json_types() -> None:
|
||||
for table in (User.__table__, SignalSourceRegistry.__table__):
|
||||
for column in table.columns:
|
||||
if column.name in {"assigned_domains", "config", "raw_context"}:
|
||||
column.type = JSON()
|
||||
|
||||
|
||||
@pytest_asyncio.fixture
|
||||
async def db_session():
|
||||
engine = create_async_engine("sqlite+aiosqlite:///:memory:")
|
||||
_use_sqlite_json_types()
|
||||
async with engine.begin() as conn:
|
||||
await conn.run_sync(
|
||||
lambda sync_conn: Base.metadata.create_all(
|
||||
|
|
|
|||
Loading…
Reference in New Issue