mirror of
https://framagit.org/framasoft/framaspace/argos.git
synced 2025-04-28 18:02:41 +02:00
- Adjusted test cases in test_api.py - Updated test_db fixture to delete the database between each test. - Consolidated test cases for tasks retrieval and results
41 lines
1.2 KiB
Python
41 lines
1.2 KiB
Python
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
from argos.schemas import AgentResult
|
|
from argos.server import app, models
|
|
|
|
|
|
@pytest.fixture()
|
|
def test_db():
|
|
models.Base.metadata.create_all(bind=app.state.engine)
|
|
yield app.state.db
|
|
models.Base.metadata.drop_all(bind=app.state.engine)
|
|
|
|
|
|
def test_read_tasks_requires_auth():
|
|
with TestClient(app) as client:
|
|
response = client.get("/tasks")
|
|
assert response.status_code == 403
|
|
|
|
|
|
def test_tasks_retrieval_and_results(test_db):
|
|
with TestClient(app) as client:
|
|
token = app.state.config.service.secrets[0]
|
|
client.headers = {"Authorization": f"Bearer {token}"}
|
|
response = client.get("/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("/results", json=data)
|
|
|
|
assert response.status_code == 201
|
|
assert test_db.query(models.Result).count() == 2
|