Commit 0fe2d40f by Clinton Blackburn

Updated throttle

ECOM-4277
parent 2f2cb5a5
from django.core.cache import cache
from django.core.urlresolvers import reverse
from rest_framework.test import APITestCase
from course_discovery.apps.core.models import UserThrottleRate
......@@ -48,7 +47,3 @@ class RateLimitingTest(APITestCase):
self.user.save()
response = self._make_requests()
self.assertEqual(response.status_code, 200)
def test_anonymous_throttling(self):
self.client.logout()
self.test_rate_limiting()
......@@ -9,9 +9,10 @@ class OverridableUserRateThrottle(UserRateThrottle):
def allow_request(self, request, view):
user = request.user
if user.is_superuser:
return True
if not user.is_anonymous():
if user and user.is_authenticated():
if user.is_superuser:
return True
try:
# Override this throttle's rate if applicable
user_throttle = UserThrottleRate.objects.get(user=user)
......@@ -19,4 +20,5 @@ class OverridableUserRateThrottle(UserRateThrottle):
self.num_requests, self.duration = self.parse_rate(self.rate)
except UserThrottleRate.DoesNotExist:
pass
return super(OverridableUserRateThrottle, self).allow_request(request, view)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment