adds new endpoint for active users

This commit is contained in:
msramalho
2024-10-29 10:56:44 +00:00
parent 47cb250a12
commit 17105ffa66
5 changed files with 43 additions and 6 deletions

View File

@@ -2,6 +2,8 @@ from unittest.mock import AsyncMock, patch
from fastapi.testclient import TestClient
import pytest
from core.config import VERSION
from tests.db.test_crud import test_data
def test_endpoint_home(client_with_auth):
@@ -44,6 +46,24 @@ def test_endpoint_health(client_with_auth):
assert r.json() == {"status": "ok"}
def test_endpoint_active_no_auth(client, test_no_auth):
test_no_auth(client.get, "/user/active")
def test_endpoint_active_true_user(client_with_auth):
r = client_with_auth.get("/user/active")
assert r.status_code == 200
assert r.json() == {"active": True}
def test_endpoint_active_true_user(client_with_auth, db_session):
from db import models
db_session.query(models.User).delete()
db_session.commit()
r = client_with_auth.get("/user/active")
assert r.status_code == 200
assert r.json() == {"active": False}
def test_endpoint_groups_no_auth(client, test_no_auth):
test_no_auth(client.get, "/groups")
@@ -79,9 +99,6 @@ def test_favicon(client_with_auth):
assert r.headers["content-type"] == "image/vnd.microsoft.icon"
from tests.db.test_crud import test_data
@pytest.mark.asyncio
async def test_prometheus_metrics(test_data, client_with_auth, get_settings):
# before metrics calculation
@@ -117,4 +134,4 @@ async def test_prometheus_metrics(test_data, client_with_auth, get_settings):
assert 'database_metrics{query="count_users"} 4.0' in r3.text
assert 'database_metrics_counter_total{query="count_by_user",user="rick@example.com"} 34.0' in r3.text
assert 'database_metrics_counter_total{query="count_by_user",user="morty@example.com"} 33.0' in r3.text
assert 'database_metrics_counter_total{query="count_by_user",user="jerry@example.com"} 33.0' in r3.text
assert 'database_metrics_counter_total{query="count_by_user",user="jerry@example.com"} 33.0' in r3.text