Feat(API): Added rate-limiting and json error handling

This commit is contained in:
minhtrannhat
2022-11-19 15:13:38 -05:00
parent 7815894d9f
commit 10b9f90524
8 changed files with 169 additions and 3 deletions

View 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 != []