Skip to content

Commit 66d4dfb

Browse files
committed
test fixes
1 parent cd6ebab commit 66d4dfb

File tree

2 files changed

+27
-13
lines changed

2 files changed

+27
-13
lines changed

stac_fastapi/tests/conftest.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,10 +238,17 @@ async def app():
238238
).app
239239

240240

241-
@pytest_asyncio.fixture(scope="function")
242-
async def app_rate_limit(monkeypatch):
243-
monkeypatch.setenv("STAC_FASTAPI_RATE_LIMIT", "2/minute")
241+
@pytest_asyncio.fixture(scope="session")
242+
async def app_client(app):
243+
await create_index_templates()
244+
await create_collection_index()
244245

246+
async with AsyncClient(app=app, base_url="http://test-server") as c:
247+
yield c
248+
249+
250+
@pytest_asyncio.fixture(scope="session")
251+
async def app_rate_limit():
245252
settings = AsyncSettings()
246253

247254
aggregation_extension = AggregationExtension(
@@ -285,21 +292,14 @@ async def app_rate_limit(monkeypatch):
285292
).app
286293

287294
# Set up rate limit
295+
os.environ["STAC_FASTAPI_RATE_LIMIT"] = "2/minute"
288296
setup_rate_limit(app)
297+
del os.environ["STAC_FASTAPI_RATE_LIMIT"]
289298

290299
return app
291300

292301

293302
@pytest_asyncio.fixture(scope="session")
294-
async def app_client(app):
295-
await create_index_templates()
296-
await create_collection_index()
297-
298-
async with AsyncClient(app=app, base_url="http://test-server") as c:
299-
yield c
300-
301-
302-
@pytest_asyncio.fixture(scope="function")
303303
async def app_client_rate_limit(app_rate_limit):
304304
await create_index_templates()
305305
await create_collection_index()

stac_fastapi/tests/rate_limit/test_rate_limit.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99

1010
@pytest.mark.asyncio
11-
async def test_rate_limit(app_client_rate_limit: AsyncClient):
11+
async def test_rate_limit(app_client_rate_limit: AsyncClient, ctx):
1212
expected_status_codes = [200, 200, 429, 429, 429]
1313

1414
for i, expected_status_code in enumerate(expected_status_codes):
@@ -22,3 +22,17 @@ async def test_rate_limit(app_client_rate_limit: AsyncClient):
2222
assert (
2323
status_code == expected_status_code
2424
), f"Expected status code {expected_status_code}, but got {status_code}"
25+
26+
27+
@pytest.mark.asyncio
28+
async def test_rate_limit_no_limit(app_client: AsyncClient, ctx):
29+
expected_status_codes = [200, 200, 200, 200, 200]
30+
31+
for i, expected_status_code in enumerate(expected_status_codes):
32+
response = await app_client.get("/collections")
33+
status_code = response.status_code
34+
35+
logger.info(f"Request {i+1}: Status code {status_code}")
36+
assert (
37+
status_code == expected_status_code
38+
), f"Expected status code {expected_status_code}, but got {status_code}"

0 commit comments

Comments
 (0)