1.4 KiB
1.4 KiB
Task: Fix test_get_all_alerts
Goal
Fix the single failing test in test_alerts.py::TestAlertCRUD::test_get_all_alerts. The test creates 2 alerts but GET returns total: 0.
Root Cause
The test uses mock_db.execute_query.side_effect with SQL string matching. The router's query for alerts uses parameterized queries with dynamic placeholders ($1, $2, etc.) that don't match the mock's simple string patterns. Specifically, the count query and the data query use different SQL patterns than what the mock expects.
Requirements
- Read
test_alerts.pylines 30-80 to understand the mock side_effect logic - Read
routers/alerts.pylines 30-80 to understand the actual SQL queries being made - Fix the mock's
alerts_query_side_effectfunction to correctly match all SQL patterns the router uses:- The COUNT query with
watchlist_id IN (...)pattern - The data query with
watchlist_id IN (...)pattern - Ensure the mock returns correct data for both queries
- The COUNT query with
- Ensure the watchlist fixture's
user_id: "test-user-1"matches the test user's ID
Acceptance Criteria
pytest tests/test_alerts.py::TestAlertCRUD::test_get_all_alertspassespytest tests/test_alerts.pypasses all 23 tests (0 failures)
Files to Modify
src/backend/tests/test_alerts.py— Fix the mock side_effect function
Constraints
- Do not change the router code
- Do not change the conftest.py fixtures
- Keep the test's existing structure and mock approach