fix: expand bgp pipeline and stabilize backend tests
This commit is contained in:
@@ -8,6 +8,8 @@ from httpx import AsyncClient, ASGITransport
|
||||
from app.main import app
|
||||
from app.core.config import settings
|
||||
from app.core.security import create_access_token
|
||||
from app.db.session import get_db
|
||||
from app.models.user import User
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -90,10 +92,58 @@ async def test_alerts_without_auth():
|
||||
@pytest.mark.asyncio
|
||||
async def test_alerts_endpoint_with_auth(auth_headers):
|
||||
"""Test alerts endpoint with authentication"""
|
||||
class _ScalarResult:
|
||||
def __init__(self, rows=None, scalar_value=0):
|
||||
self._rows = rows or []
|
||||
self._scalar_value = scalar_value
|
||||
|
||||
def scalars(self):
|
||||
class _Scalars:
|
||||
def __init__(self, rows):
|
||||
self._rows = rows
|
||||
|
||||
def all(self):
|
||||
return self._rows
|
||||
|
||||
return _Scalars(self._rows)
|
||||
|
||||
def scalar(self):
|
||||
return self._scalar_value
|
||||
|
||||
class _FakeAlertsSession:
|
||||
def __init__(self):
|
||||
self.calls = 0
|
||||
|
||||
async def execute(self, _query):
|
||||
self.calls += 1
|
||||
if self.calls == 1:
|
||||
return _ScalarResult(rows=[])
|
||||
return _ScalarResult(rows=[], scalar_value=0)
|
||||
|
||||
def override_get_current_user():
|
||||
return User(
|
||||
id=1,
|
||||
username="testuser",
|
||||
email="test@example.com",
|
||||
password_hash="hashed",
|
||||
role="admin",
|
||||
is_active=True,
|
||||
)
|
||||
|
||||
async def override_get_db():
|
||||
yield _FakeAlertsSession()
|
||||
|
||||
app.dependency_overrides = {
|
||||
__import__("app.core.security", fromlist=["get_current_user"]).get_current_user: override_get_current_user,
|
||||
get_db: override_get_db,
|
||||
}
|
||||
transport = ASGITransport(app=app)
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.get("/api/v1/alerts", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
try:
|
||||
async with AsyncClient(transport=transport, base_url="http://test") as client:
|
||||
response = await client.get("/api/v1/alerts", headers=auth_headers)
|
||||
assert response.status_code == 200
|
||||
finally:
|
||||
app.dependency_overrides.clear()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
|
||||
Reference in New Issue
Block a user