当前位置: 首页>>代码示例>>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;未经允许,请勿转载。