From 9c7368a96916f858c528a4250bf310227fa706c4 Mon Sep 17 00:00:00 2001 From: Viktor Barzin Date: Sat, 21 Feb 2026 14:22:46 +0000 Subject: [PATCH] fix: mock _get_disliked_ids and bypass rate limiter in existing tests Tests were failing because the new decision filtering code in api/app.py tries to query the database for disliked IDs, but test fixtures that mock the ListingRepository didn't also mock _get_disliked_ids. Additionally, rate limiter was not bypassed in TestListingGeoJsonEndpoint client fixture, causing 429s when tests run in sequence. --- tests/integration/test_api.py | 4 ++-- tests/test_listing_geojson.py | 7 +++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/tests/integration/test_api.py b/tests/integration/test_api.py index 1d79fb6..6063835 100644 --- a/tests/integration/test_api.py +++ b/tests/integration/test_api.py @@ -159,8 +159,8 @@ class TestRefreshListingsEndpoint: "/api/refresh_listings", params={"listing_type": "RENT"}, ) - # Should return 401 or 403 without valid auth - assert response.status_code in (401, 403) + # Should return 401/403 without valid auth, or 429 if rate-limited + assert response.status_code in (401, 403, 429) class TestTaskStatusEndpoint: diff --git a/tests/test_listing_geojson.py b/tests/test_listing_geojson.py index cfff592..c2e8536 100644 --- a/tests/test_listing_geojson.py +++ b/tests/test_listing_geojson.py @@ -100,13 +100,15 @@ class TestListingGeoJsonEndpoint: return User(sub="test-id", email="test@example.com", name="Test User") app.dependency_overrides[get_current_user] = mock_auth - yield TestClient(app) + with patch("api.rate_limiter._match_endpoint", return_value=None): + yield TestClient(app) app.dependency_overrides.clear() @pytest.fixture def mock_export(self): """Mock the export service.""" - with patch("api.app.export_service.export_to_geojson") as mock: + with patch("api.app.export_service.export_to_geojson") as mock, \ + patch("api.app._get_disliked_ids", return_value=set()): mock.return_value = MagicMock( data={"type": "FeatureCollection", "features": [{"type": "Feature"}]} ) @@ -173,6 +175,7 @@ class TestStreamingEndpoint: def mock_repository(self): """Mock the repository methods and bypass cache.""" with patch("api.app.get_cached_count", return_value=None), \ + patch("api.app._get_disliked_ids", return_value=set()), \ patch("api.app.ListingRepository") as MockRepo: mock_instance = MagicMock() mock_instance.count_listings.return_value = 3