argos/tests/test_api.py

37 lines
1.1 KiB
Python

from fastapi.testclient import TestClient
from argos.schemas import AgentResult
from argos.server import models
def test_read_tasks_requires_auth(app):
with TestClient(app) as client:
response = client.get("/api/tasks")
assert response.status_code == 403
def test_tasks_retrieval_and_results(app):
with TestClient(app) as client:
token = app.state.config.service.secrets[0]
client.headers = {"Authorization": f"Bearer {token}"}
response = client.get("/api/tasks")
assert response.status_code == 200
tasks = response.json()
assert len(tasks) == 2
results = []
for task in tasks:
results.append(
AgentResult(task_id=task["id"], status="success", context={})
)
data = [r.model_dump() for r in results]
response = client.post("/api/results", json=data)
assert response.status_code == 201
assert app.state.db.query(models.Result).count() == 2
# The list of tasks should be empty now
response = client.get("/api/tasks")
assert len(response.json()) == 0