test get tast by source 🟩

This commit is contained in:
Daniel Roth 2026-03-18 16:15:03 +00:00
parent 9cb02ebad2
commit b20d8145f3
2 changed files with 21 additions and 11 deletions

View file

@ -1,3 +1,5 @@
from typing import Dict
from fastapi import APIRouter, Depends, HTTPException
from uuid import UUID
import json # ← REQUIRED for json.loads
@ -82,17 +84,21 @@ async def get_task_by_source(
source_id: str,
service: str,
session: Session = Depends(get_session),
):
task = session.execute(
select(Task)
.where(
Task.source == source,
Task.source_id == source_id,
Task.service == service,
) -> Dict[str, Task]:
task = (
session.execute(
select(Task)
.where(
Task.source == source,
Task.source_id == source_id,
Task.service == service,
)
.order_by(Task.job_started.desc())
.limit(1)
)
.order_by(Task.job_started.desc())
.limit(1)
).first()
.scalars()
.first()
)
if not task:
raise HTTPException(status_code=404, detail="Task not found")

View file

@ -1,6 +1,7 @@
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from sqlmodel import SQLModel
from backend.app.db.base import Base
@ -24,7 +25,7 @@ def engine(postgresql):
engine = create_engine(connection_string)
# Create tables once per test session
Base.metadata.create_all(engine)
# Base.metadata.create_all(engine)
# Yeild will split this function into two phase. 1) setup and 2) teardown, the latter of which will run after all
# tests have completed
@ -46,6 +47,9 @@ def db_session(engine):
connection = engine.connect()
transaction = connection.begin()
Base.metadata.create_all(bind=connection)
SQLModel.metadata.create_all(bind=connection)
session = sessionmaker(bind=connection)()
yield session