Added setting to disable throttling the API

This commit is contained in:
Rob Hudson 2013-05-21 11:29:55 -07:00
Родитель 446df110fc
Коммит 9d62357c69
5 изменённых файлов: 24 добавлений и 1 удалений

Просмотреть файл

@ -1567,3 +1567,6 @@ ALLOW_TASTYPIE_SERVICES = False
# The version we append to the app feature profile. Bump when we add new app
# features to the `AppFeatures` model.
APP_FEATURES_VERSION = 1
# Whether to throttle API requests. Default is True. Disable where appropriate.
API_THROTTLE = True

Просмотреть файл

@ -4,6 +4,7 @@ import logging
import sys
import traceback
from django.conf import settings
from django.conf.urls.defaults import url
from django.core.exceptions import ObjectDoesNotExist, PermissionDenied
from django.http import HttpResponseNotFound
@ -188,7 +189,8 @@ class Marketplace(object):
``Resource._meta``.
"""
# Never throttle users with Apps:APIUnthrottled.
if not acl.action_allowed(request, 'Apps', 'APIUnthrottled'):
if (settings.API_THROTTLE and
not acl.action_allowed(request, 'Apps', 'APIUnthrottled')):
identifiers = [a.get_identifier(request) for a in self._auths()]
# Check to see if they should be throttled.

Просмотреть файл

@ -146,6 +146,20 @@ class TestThrottling(TestCase):
sbt.return_value = True
self.no_throttle_expected()
def test_throttled_user_setting_enabled(self):
with self.settings(API_THROTTLE=True):
ACLMiddleware().process_request(self.request)
with self.mocked_sbt as sbt:
sbt.return_value = True
self.throttle_expected()
def test_throttled_user_setting_disabled(self):
with self.settings(API_THROTTLE=False):
ACLMiddleware().process_request(self.request)
with self.mocked_sbt as sbt:
sbt.return_value = True
self.no_throttle_expected()
class FilteredCORS(CORSResource, MarketplaceResource):

Просмотреть файл

@ -207,3 +207,5 @@ LESS_PREPROCESS = True
XSENDFILE_HEADER = 'X-Accel-Redirect'
ALLOW_SELF_REVIEWS = True
API_THROTTLE = False

Просмотреть файл

@ -197,3 +197,5 @@ AWS_SECRET_ACCESS_KEY = private.AWS_SECRET_ACCESS_KEY
AWS_STORAGE_BUCKET_NAME = private.AWS_STORAGE_BUCKET_NAME
RAISE_ON_SIGNAL_ERROR = True
API_THROTTLE = False