Skip to content

Commit

Permalink
throttle parser test invalid value
Browse files Browse the repository at this point in the history
  • Loading branch information
vitalik committed Dec 29, 2024
1 parent 7ab86e7 commit a59ccb0
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions tests/test_throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,7 @@ def test_throttle_auth():
set_throttle_timer(th, 2)
assert th.allow_request(request) is True

assert (
th.get_cache_key(request)
== "throttle_auth_a6b46dd0d1ae5e86cbc8f37e75ceeb6760230c1ca4ffbcb0c97b96dd7d9c464b"
)
assert th.get_cache_key(request) == "throttle_auth_a6b46dd0d1ae5e86cbc8f37e75ceeb6760230c1ca4ffbcb0c97b96dd7d9c464b"


def test_throttle_user():
Expand All @@ -212,9 +209,7 @@ def test_throttle_user():
request.user.is_authenticated = False
assert th.allow_request(request) is True
assert th.allow_request(request) is False
assert (
th.get_cache_key(request) == "throttle_user_8.8.8.8"
) # not authenticated throttled by IP
assert th.get_cache_key(request) == "throttle_user_8.8.8.8" # not authenticated throttled by IP


def test_wait():
Expand Down Expand Up @@ -267,6 +262,9 @@ def test_rate_parser():
assert th.parse_rate("10_000/7d") == (10000, 86400 * 7)
assert th.parse_rate("10_000/7day") == (10000, 86400 * 7)

with pytest.raises(ValueError):
th.parse_rate("42")


def test_proxy_throttle():
from ninja.conf import settings
Expand Down

0 comments on commit a59ccb0

Please sign in to comment.