Import tests: tests/test_rate_limit
Import the existing local project snapshot. This commit organizes existing files; it does not represent newly developed functionality.
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
from fastapi import FastAPI
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
|
||||
def test_rate_limit_rejects_after_limit():
|
||||
from axon.middleware.rate_limit import RateLimitMiddleware
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/data")
|
||||
async def data():
|
||||
return {"ok": True}
|
||||
|
||||
app.add_middleware(RateLimitMiddleware, limit_per_minute=1)
|
||||
client = TestClient(app)
|
||||
|
||||
assert client.get("/data").status_code == 200
|
||||
assert client.get("/data").status_code == 429
|
||||
|
||||
|
||||
def test_rate_limit_exempts_health():
|
||||
from axon.middleware.rate_limit import RateLimitMiddleware
|
||||
|
||||
app = FastAPI()
|
||||
|
||||
@app.get("/health")
|
||||
async def health():
|
||||
return {"ok": True}
|
||||
|
||||
app.add_middleware(RateLimitMiddleware, limit_per_minute=1)
|
||||
client = TestClient(app)
|
||||
|
||||
assert client.get("/health").status_code == 200
|
||||
assert client.get("/health").status_code == 200
|
||||
Reference in New Issue
Block a user