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.
This commit is contained in:
Viktor Barzin 2026-02-21 14:22:46 +00:00
parent 49280d9679
commit 9c7368a969
No known key found for this signature in database
GPG key ID: 0EB088298288D958
2 changed files with 7 additions and 4 deletions

View file

@ -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:

View file

@ -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