70 lines
4.1 KiB
Plaintext
70 lines
4.1 KiB
Plaintext
============================= test session starts ==============================
|
|||
|
|
platform linux -- Python 3.14.5, pytest-9.0.3, pluggy-1.6.0
|
||
|
|
rootdir: /home/laptran/ai-env/projects/invest-copilot/src/backend
|
||
|
|
configfile: pyproject.toml
|
||
|
|
plugins: asyncio-1.3.0, cov-7.1.0, anyio-4.13.0
|
||
|
|
asyncio: mode=Mode.AUTO, debug=False, asyncio_default_fixture_loop_scope=None, asyncio_default_test_loop_scope=function
|
||
|
|
collected 23 items / 22 deselected / 1 selected
|
||
|
|
|
||
|
|
src/backend/tests/test_alerts.py F [100%]
|
||
|
|
|
||
|
|
=================================== FAILURES ===================================
|
||
|
|
______________________ TestAlertCRUD.test_get_all_alerts _______________________
|
||
|
|
|
||
|
|
self = <backend.tests.test_alerts.TestAlertCRUD object at 0x7f7faa3a3e10>
|
||
|
|
client = <httpx.AsyncClient object at 0x7f7faa0d1450>
|
||
|
|
test_user = {'token': 'eyJhbGciOiAiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJzdWIiOiAidGVzdC11c2VyLTEiLCAiZW1haWwiOiAidGVzdEBleGFtcGxlLmNvbS...148F2igONjGXciVac', 'user': {'email': 'test@example.com', 'id': 'test-user-1', 'name': 'Test User', 'timezone': 'UTC'}}
|
||
|
|
watchlist = {'created_at': '2024-01-01T00:00:00', 'description': 'My tech picks', 'id': 'wl-1', 'is_default': False, ...}
|
||
|
|
mock_db = <AsyncMock id='140186291514944'>
|
||
|
|
|
||
|
|
async def test_get_all_alerts(self, client, test_user, watchlist, mock_db):
|
||
|
|
"""User can retrieve all their alerts."""
|
||
|
|
headers = {"Authorization": f"Bearer {test_user['token']}"}
|
||
|
|
# Create two alerts
|
||
|
|
await client.post("/api/v1/alerts", json={
|
||
|
|
"watchlist_id": watchlist["id"],
|
||
|
|
"type": "price",
|
||
|
|
"message": "Alert 1",
|
||
|
|
}, headers=headers)
|
||
|
|
await client.post("/api/v1/alerts", json={
|
||
|
|
"watchlist_id": watchlist["id"],
|
||
|
|
"type": "sentiment",
|
||
|
|
"message": "Alert 2",
|
||
|
|
}, headers=headers)
|
||
|
|
|
||
|
|
# Mock execute_query to return the created alerts
|
||
|
|
def alerts_query_side_effect(sql, params=None):
|
||
|
|
sql_upper = sql.upper()
|
||
|
|
print(f"DEBUG: sql_upper: {sql_upper}")
|
||
|
|
if "COUNT(*)" in sql_upper and "FROM ALERTS" in sql_upper:
|
||
|
|
return [{"count": 2}]
|
||
|
|
if "FROM ALERTS" in sql_upper:
|
||
|
|
return [
|
||
|
|
{"id": "alert-1", "watchlist_id": watchlist["id"], "type": "price", "trigger_type": None, "message": "Alert 1", "severity": "info", "status": "active", "ticker": None, "triggered_at": None, "resolved_at": None, "metadata": {}, "created_at": "2026-05-01T00:01:00"},
|
||
|
|
{"id": "alert-2", "watchlist_id": watchlist["id"], "type": "sentiment", "trigger_type": None, "message": "Alert 2", "severity": "info", "status": "active", "ticker": None, "triggered_at": None, "resolved_at": None, "metadata": {}, "created_at": "2026-05-01T00:02:00"},
|
||
|
|
]
|
||
|
|
return []
|
||
|
|
mock_db.execute_query.side_effect = alerts_query_side_effect
|
||
|
|
|
||
|
|
response = await client.get(
|
||
|
|
f"/api/v1/alerts?watchlist_id={watchlist['id']}&status=active",
|
||
|
|
headers=headers,
|
||
|
|
)
|
||
|
|
assert response.status_code == 200
|
||
|
|
data = response.json()
|
||
|
|
> assert data["total"] >= 2
|
||
|
|
E assert 0 >= 2
|
||
|
|
|
||
|
|
src/backend/tests/test_alerts.py:78: AssertionError
|
||
|
|
----------------------------- Captured stderr call -----------------------------
|
||
|
|
INFO:httpx:HTTP Request: POST http://test/api/v1/alerts "HTTP/1.1 201 Created"
|
||
|
|
INFO:httpx:HTTP Request: POST http://test/api/v1/alerts "HTTP/1.1 201 Created"
|
||
|
|
INFO:httpx:HTTP Request: GET http://test/api/v1/alerts?watchlist_id=wl-1&status=active "HTTP/1.1 200 OK"
|
||
|
|
------------------------------ Captured log call -------------------------------
|
||
|
|
INFO httpx:_client.py:1740 HTTP Request: POST http://test/api/v1/alerts "HTTP/1.1 201 Created"
|
||
|
|
INFO httpx:_client.py:1740 HTTP Request: POST http://test/api/v1/alerts "HTTP/1.1 201 Created"
|
||
|
|
INFO httpx:_client.py:1740 HTTP Request: GET http://test/api/v1/alerts?watchlist_id=wl-1&status=active "HTTP/1.1 200 OK"
|
||
|
|
=========================== short test summary info ============================
|
||
|
|
FAILED src/backend/tests/test_alerts.py::TestAlertCRUD::test_get_all_alerts
|
||
|
|
======================= 1 failed, 22 deselected in 0.04s =======================
|