Commit 0fe2d40f by Clinton Blackburn

Updated throttle

ECOM-4277
parent 2f2cb5a5
from django.core.cache import cache from django.core.cache import cache
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from course_discovery.apps.core.models import UserThrottleRate from course_discovery.apps.core.models import UserThrottleRate
...@@ -48,7 +47,3 @@ class RateLimitingTest(APITestCase): ...@@ -48,7 +47,3 @@ class RateLimitingTest(APITestCase):
self.user.save() self.user.save()
response = self._make_requests() response = self._make_requests()
self.assertEqual(response.status_code, 200) 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): ...@@ -9,9 +9,10 @@ class OverridableUserRateThrottle(UserRateThrottle):
def allow_request(self, request, view): def allow_request(self, request, view):
user = request.user user = request.user
if user.is_superuser:
return True if user and user.is_authenticated():
if not user.is_anonymous(): if user.is_superuser:
return True
try: try:
# Override this throttle's rate if applicable # Override this throttle's rate if applicable
user_throttle = UserThrottleRate.objects.get(user=user) user_throttle = UserThrottleRate.objects.get(user=user)
...@@ -19,4 +20,5 @@ class OverridableUserRateThrottle(UserRateThrottle): ...@@ -19,4 +20,5 @@ class OverridableUserRateThrottle(UserRateThrottle):
self.num_requests, self.duration = self.parse_rate(self.rate) self.num_requests, self.duration = self.parse_rate(self.rate)
except UserThrottleRate.DoesNotExist: except UserThrottleRate.DoesNotExist:
pass pass
return super(OverridableUserRateThrottle, self).allow_request(request, view) 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