feat: implement Logs endpoints for web dashboard

This commit is contained in:
2026-04-07 14:56:25 -04:00
parent 5b990743db
commit b46934db46
4 changed files with 242 additions and 1 deletions

View File

@@ -1,7 +1,9 @@
import os
from typing import Generator
import pytest
from fastapi.testclient import TestClient
from decnet.web.api import app, repo
@@ -45,3 +47,28 @@ def test_login_failure() -> None:
json={"username": "nonexistent", "password": "wrongpassword"}
)
assert response.status_code == 401
def test_get_logs_unauthorized() -> None:
with TestClient(app) as client:
response = client.get("/api/v1/logs")
assert response.status_code == 401
def test_get_logs_success() -> None:
with TestClient(app) as client:
login_response = client.post(
"/api/v1/auth/login",
json={"username": "admin", "password": "admin"}
)
token = login_response.json()["access_token"]
response = client.get(
"/api/v1/logs",
headers={"Authorization": f"Bearer {token}"}
)
assert response.status_code == 200
data = response.json()
assert "data" in data
assert data["total"] >= 0
assert isinstance(data["data"], list)