mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-18 12:12:19 +03:00
adding tests
This commit is contained in:
parent
35a63d8667
commit
71289fff0d
|
@ -18,6 +18,7 @@ from rest_framework.throttling import (
|
||||||
UserRateThrottle
|
UserRateThrottle
|
||||||
)
|
)
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
from utils.throttling_duration_parser import parse_quantity_and_unit
|
||||||
|
|
||||||
|
|
||||||
class User3SecRateThrottle(UserRateThrottle):
|
class User3SecRateThrottle(UserRateThrottle):
|
||||||
|
@ -466,6 +467,16 @@ class SimpleRateThrottleTests(TestCase):
|
||||||
rate = SimpleRateThrottle().parse_rate(None)
|
rate = SimpleRateThrottle().parse_rate(None)
|
||||||
assert rate == (None, None)
|
assert rate == (None, None)
|
||||||
|
|
||||||
|
def test_parse_quantity_and_unit_parses_correctly(self):
|
||||||
|
result = parse_quantity_and_unit("5min")
|
||||||
|
assert result == {'quantity': 5, 'unit': 'min'}
|
||||||
|
|
||||||
|
result = parse_quantity_and_unit("h")
|
||||||
|
assert result == {'quantity': 1, 'unit': 'h'}
|
||||||
|
|
||||||
|
result = parse_quantity_and_unit("123s")
|
||||||
|
assert result == {'quantity': 123, 'unit': 's'}
|
||||||
|
|
||||||
def test_allow_request_returns_true_if_rate_is_none(self):
|
def test_allow_request_returns_true_if_rate_is_none(self):
|
||||||
assert SimpleRateThrottle().allow_request(request={}, view={}) is True
|
assert SimpleRateThrottle().allow_request(request={}, view={}) is True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user