Skip to content

Commit e0b74db

Browse files
committed
Add MockRateLimiter test utility
Introduce tests/mock_limiter.py providing a MockRateLimiter class for tests. The mock is configurable via should_allow and an optional state, returns (allowed, state) from check(key, weight), records check calls, and supports reset() to clear recorded calls. Default state values mirror common rate-limit fields (allowed, remaining, limit, retry_after, reset_after).
1 parent 134804c commit e0b74db

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

tests/mock_limiter.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
class MockRateLimiter:
2+
def __init__(self, should_allow=True, state=None):
3+
self.should_allow = should_allow
4+
self.state = state or {
5+
'allowed': should_allow,
6+
'remaining': 50 if should_allow else 0,
7+
'limit': 100,
8+
'retry_after': 0 if should_allow else 30.0,
9+
'reset_after': 60.0
10+
}
11+
self.check_calls = []
12+
13+
def check(self, key, weight=1):
14+
self.check_calls.append((key, weight))
15+
return self.should_allow, self.state
16+
17+
def reset(self):
18+
self.check_calls = []

0 commit comments

Comments
 (0)