Spaces:
Sleeping
Sleeping
Pavanupadhyay27 commited on
Commit ·
b9a0b03
1
Parent(s): fe6c464
Fix: Resolve backend test hangs and ModuleNotFoundError in GitHub Actions
Browse files
.github/workflows/ci.yml
CHANGED
|
@@ -31,7 +31,7 @@ jobs:
|
|
| 31 |
- name: Run Pytest Test Suite
|
| 32 |
run: |
|
| 33 |
cd backend
|
| 34 |
-
pytest --cov=app --cov-report=xml -v
|
| 35 |
|
| 36 |
build-containers:
|
| 37 |
runs-on: ubuntu-latest
|
|
|
|
| 31 |
- name: Run Pytest Test Suite
|
| 32 |
run: |
|
| 33 |
cd backend
|
| 34 |
+
python -m pytest --cov=app --cov-report=xml -v
|
| 35 |
|
| 36 |
build-containers:
|
| 37 |
runs-on: ubuntu-latest
|
backend/app/tests/test_auth.py
CHANGED
|
@@ -88,13 +88,19 @@ def test_live_stream_auth_failure(client):
|
|
| 88 |
assert response.status_code == 401
|
| 89 |
|
| 90 |
@patch("app.core.security.crud.get_user_by_email")
|
| 91 |
-
|
|
|
|
| 92 |
mock_role = models.Role(id=1, name="Super Admin")
|
| 93 |
mock_user = models.User(id=1, email="admin@netraid.ai", is_active=True, role=mock_role)
|
| 94 |
mock_get_user.return_value = mock_user
|
| 95 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 96 |
token = create_access_token(subject="admin@netraid.ai", role="Super Admin")
|
| 97 |
|
| 98 |
-
# We can connect to the streaming endpoint using client.stream
|
| 99 |
with client.stream("GET", f"/api/v1/analytics/live-stream?token={token}") as response:
|
| 100 |
assert response.status_code == 200
|
|
|
|
| 88 |
assert response.status_code == 401
|
| 89 |
|
| 90 |
@patch("app.core.security.crud.get_user_by_email")
|
| 91 |
+
@patch("app.api.v1.analytics.event_bus.subscribe")
|
| 92 |
+
def test_live_stream_auth_success(mock_subscribe, mock_get_user, client):
|
| 93 |
mock_role = models.Role(id=1, name="Super Admin")
|
| 94 |
mock_user = models.User(id=1, email="admin@netraid.ai", is_active=True, role=mock_role)
|
| 95 |
mock_get_user.return_value = mock_user
|
| 96 |
|
| 97 |
+
# Pre-populate queue to prevent TestClient from hanging waiting for the first yield
|
| 98 |
+
import asyncio
|
| 99 |
+
q = asyncio.Queue()
|
| 100 |
+
q.put_nowait({"type": "test"})
|
| 101 |
+
mock_subscribe.return_value = q
|
| 102 |
+
|
| 103 |
token = create_access_token(subject="admin@netraid.ai", role="Super Admin")
|
| 104 |
|
|
|
|
| 105 |
with client.stream("GET", f"/api/v1/analytics/live-stream?token={token}") as response:
|
| 106 |
assert response.status_code == 200
|