|
|
@@ -38,13 +38,13 @@ async def test_log_request_and_count(limits_handler):
|
|
|
}
|
|
|
limits_handler.config.route_limits = new_route_limits
|
|
|
|
|
|
- print(f"\nTesting with route limits: {new_route_limits}")
|
|
|
- print(f"Route settings: {limits_handler.config.route_limits[route]}")
|
|
|
+ #print(f"\nTesting with route limits: {new_route_limits}")
|
|
|
+ #print(f"Route settings: {limits_handler.config.route_limits[route]}")
|
|
|
|
|
|
try:
|
|
|
# Initial check should pass (no requests yet)
|
|
|
await limits_handler.check_limits(test_user, route)
|
|
|
- print("Initial check passed (no requests)")
|
|
|
+ #print("Initial check passed (no requests)")
|
|
|
|
|
|
# Log 5 requests (exactly at limit)
|
|
|
for i in range(5):
|
|
|
@@ -53,17 +53,17 @@ async def test_log_request_and_count(limits_handler):
|
|
|
one_min_ago = now - timedelta(minutes=1)
|
|
|
route_count = await limits_handler._count_requests(
|
|
|
user_id, route, one_min_ago)
|
|
|
- print(f"Route count after request {i + 1}: {route_count}")
|
|
|
+ #print(f"Route count after request {i + 1}: {route_count}")
|
|
|
|
|
|
# This should pass for all 5 requests
|
|
|
await limits_handler.check_limits(test_user, route)
|
|
|
- print(f"Check limits passed after request {i + 1}")
|
|
|
+ #print(f"Check limits passed after request {i + 1}")
|
|
|
|
|
|
# Log the 6th request (over limit)
|
|
|
await limits_handler.log_request(user_id, route)
|
|
|
route_count = await limits_handler._count_requests(
|
|
|
user_id, route, one_min_ago)
|
|
|
- print(f"Route count after request 6: {route_count}")
|
|
|
+ #print(f"Route count after request 6: {route_count}")
|
|
|
|
|
|
# This check should fail as we've exceeded route_per_min=5
|
|
|
with pytest.raises(ValueError,
|
|
|
@@ -101,7 +101,7 @@ async def test_global_limit(limits_handler):
|
|
|
try:
|
|
|
# Initial check should pass (no requests)
|
|
|
await limits_handler.check_limits(test_user, route)
|
|
|
- print("Initial global check passed (no requests)")
|
|
|
+ #print("Initial global check passed (no requests)")
|
|
|
|
|
|
# Log 10 requests (hits the limit)
|
|
|
for i in range(11):
|
|
|
@@ -112,7 +112,7 @@ async def test_global_limit(limits_handler):
|
|
|
one_min_ago = now - timedelta(minutes=1)
|
|
|
global_count = await limits_handler._count_requests(
|
|
|
user_id, None, one_min_ago)
|
|
|
- print(f"Global count after 10 requests: {global_count}")
|
|
|
+ #print(f"Global count after 10 requests: {global_count}")
|
|
|
|
|
|
# This should fail as we've hit global_per_min=10
|
|
|
with pytest.raises(ValueError,
|
|
|
@@ -148,7 +148,7 @@ async def test_monthly_limit(limits_handler):
|
|
|
try:
|
|
|
# Initial check should pass (no requests)
|
|
|
await limits_handler.check_limits(test_user, route)
|
|
|
- print("Initial monthly check passed (no requests)")
|
|
|
+ #print("Initial monthly check passed (no requests)")
|
|
|
|
|
|
# Log 20 requests (hits the monthly limit)
|
|
|
for i in range(21):
|
|
|
@@ -163,7 +163,7 @@ async def test_monthly_limit(limits_handler):
|
|
|
microsecond=0)
|
|
|
monthly_count = await limits_handler._count_requests(
|
|
|
user_id, None, first_of_month)
|
|
|
- print(f"Monthly count after 20 requests: {monthly_count}")
|
|
|
+ #print(f"Monthly count after 20 requests: {monthly_count}")
|
|
|
|
|
|
# This should fail as we've hit monthly_limit=20
|
|
|
with pytest.raises(ValueError, match="Monthly rate limit exceeded"):
|
|
|
@@ -206,13 +206,13 @@ async def test_user_level_override(limits_handler):
|
|
|
monthly_limit=20)
|
|
|
|
|
|
# Debug: Print current limits
|
|
|
- print(f"\nDefault limits: {limits_handler.config.limits}")
|
|
|
- print(f"User overrides: {test_user.limits_overrides}")
|
|
|
+ #print(f"\nDefault limits: {limits_handler.config.limits}")
|
|
|
+ #print(f"User overrides: {test_user.limits_overrides}")
|
|
|
|
|
|
try:
|
|
|
# First check limits (should pass as no requests yet)
|
|
|
await limits_handler.check_limits(test_user, route)
|
|
|
- print("Initial check passed (no requests yet)")
|
|
|
+ #print("Initial check passed (no requests yet)")
|
|
|
|
|
|
# Log first request
|
|
|
await limits_handler.log_request(user_id, route)
|
|
|
@@ -224,9 +224,9 @@ async def test_user_level_override(limits_handler):
|
|
|
user_id, None, one_min_ago)
|
|
|
route_count = await limits_handler._count_requests(
|
|
|
user_id, route, one_min_ago)
|
|
|
- print("\nAfter first request:")
|
|
|
- print(f"Global count: {global_count}")
|
|
|
- print(f"Route count: {route_count}")
|
|
|
+ #print("\nAfter first request:")
|
|
|
+ #print(f"Global count: {global_count}")
|
|
|
+ #print(f"Route count: {route_count}")
|
|
|
|
|
|
# Log second request
|
|
|
await limits_handler.log_request(user_id, route)
|