Feat(API): Added rate-limiting and json error handling
This commit is contained in:
29
backend/tests/test_rate_limits.py
Normal file
29
backend/tests/test_rate_limits.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from quart_rate_limiter import (
|
||||
QUART_RATE_LIMITER_EXEMPT_ATTRIBUTE,
|
||||
QUART_RATE_LIMITER_LIMITS_ATTRIBUTE,
|
||||
)
|
||||
|
||||
from backend.run import app
|
||||
|
||||
IGNORED_ENDPOINTS = {"static"}
|
||||
|
||||
|
||||
# Check if all api routes are rate limited
|
||||
async def test_routes_have_rate_limits() -> None:
|
||||
for rule in app.url_map.iter_rules():
|
||||
endpoint = rule.endpoint
|
||||
|
||||
exempt = getattr(
|
||||
app.view_functions[endpoint],
|
||||
QUART_RATE_LIMITER_EXEMPT_ATTRIBUTE,
|
||||
False,
|
||||
)
|
||||
|
||||
if not exempt and endpoint not in IGNORED_ENDPOINTS:
|
||||
rate_limits = getattr(
|
||||
app.view_functions[endpoint],
|
||||
QUART_RATE_LIMITER_LIMITS_ATTRIBUTE,
|
||||
[],
|
||||
)
|
||||
|
||||
assert rate_limits != []
|
Reference in New Issue
Block a user