Exemplo n.º 1
0
    def allow_request(self, request, view):
        if request.user and \
           request.user.username == settings.CLIENT_APP_USERNAME:
            # If the user is the client app, pass through and
            # don't attempt any throttling
            return True

        return UserRateThrottle.allow_request(self, request, view)
Exemplo n.º 2
0
    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 xrange(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'])
Exemplo n.º 3
0
    def test_throttling(self):
        """Test that the rate of requests to the orders endpoint is throttled."""
        request_limit = UserRateThrottle().num_requests
        # Make a number of requests equal to the number of allowed requests
        for _ in xrange(request_limit):
            self._order(sku=self.EXPENSIVE_TRIAL_SKU)

        # Make one more request to trigger throttling of the client
        response = self._order(sku=self.EXPENSIVE_TRIAL_SKU)
        self.assertEqual(response.status_code,
                         status.HTTP_429_TOO_MANY_REQUESTS)
        self.assertIn("Request was throttled.", response.data['detail'])
Exemplo n.º 4
0
 def get_throttles(self):
     if self.action == 'create' and not DEBUG:
         return [UserRateThrottle()]
     return super(ReportViewSet, self).get_throttles()