當前位置: 首頁>>代碼示例>>Python>>正文


Python throttling.UserRateThrottle方法代碼示例

本文整理匯總了Python中rest_framework.throttling.UserRateThrottle方法的典型用法代碼示例。如果您正苦於以下問題:Python throttling.UserRateThrottle方法的具體用法?Python throttling.UserRateThrottle怎麽用?Python throttling.UserRateThrottle使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.throttling的用法示例。


在下文中一共展示了throttling.UserRateThrottle方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_throttling

# 需要導入模塊: from rest_framework import throttling [as 別名]
# 或者: from rest_framework.throttling import UserRateThrottle [as 別名]
def test_throttling(self):
        """Test that the rate of requests to the basket creation endpoint is throttled."""
        request_limit = UserRateThrottle().num_requests
        # Make a number of requests equal to the number of allowed requests
        for _ in range(request_limit):
            self.create_basket(skus=[self.PAID_SKU])

        # Make one more request to trigger throttling of the client
        response = self.create_basket(skus=[self.PAID_SKU])
        self.assertEqual(response.status_code, 429)
        self.assertIn("Request was throttled.", response.data['detail']) 
開發者ID:edx,項目名稱:ecommerce,代碼行數:13,代碼來源:test_baskets.py

示例2: allow_request

# 需要導入模塊: from rest_framework import throttling [as 別名]
# 或者: from rest_framework.throttling import UserRateThrottle [as 別名]
def allow_request(self, request, view):
        """Returns True if the request is coming from one of the service users
        and defaults to UserRateThrottle's configured setting otherwise.
        """
        service_users = [settings.ECOMMERCE_SERVICE_WORKER_USERNAME, settings.PROSPECTUS_WORKER_USERNAME]
        if request.user.username in service_users:
            return True
        return super(ServiceUserThrottle, self).allow_request(request, view) 
開發者ID:edx,項目名稱:ecommerce,代碼行數:10,代碼來源:throttles.py

示例3: allow_request

# 需要導入模塊: from rest_framework import throttling [as 別名]
# 或者: from rest_framework.throttling import UserRateThrottle [as 別名]
def allow_request(self, request, view):
        """
        Modify throttling for service users.

        Updates throttling rate if the request is coming from the service user, and
        defaults to UserRateThrottle's configured setting otherwise.

        Updated throttling rate comes from `DEFAULT_THROTTLE_RATES` key in `REST_FRAMEWORK`
        setting. service user throttling is specified in `DEFAULT_THROTTLE_RATES` by `service_user` key

        Example Setting:
            ```
            REST_FRAMEWORK = {
                ...
                'DEFAULT_THROTTLE_RATES': {
                    ...
                    'service_user': '50/day'
                }
            }
            ```
        """
        service_users = get_service_usernames()

        # User service user throttling rates for service user.
        if request.user.username in service_users:
            self.update_throttle_scope()

        return super(ServiceUserThrottle, self).allow_request(request, view) 
開發者ID:edx,項目名稱:edx-enterprise,代碼行數:30,代碼來源:throttles.py


注:本文中的rest_framework.throttling.UserRateThrottle方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。