Skip to content

Commit

Permalink
Tweak test of authenticated user throttling
Browse files Browse the repository at this point in the history
* Only test the `UsernameLoginRateThrottle`.
* Check repeated requests don't trigger the throttle.
  • Loading branch information
LilyFoote committed Feb 26, 2015
1 parent 0e8300b commit 9b7acd6
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions user_management/api/tests/test_throttling.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from user_management.api import views
from user_management.models.tests.factories import UserFactory
from user_management.models.tests.utils import APIRequestTestCase
from .. import throttling

THROTTLE_RATE_PATH = 'rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES'

Expand Down Expand Up @@ -77,10 +78,21 @@ def test_user_auth_throttle_username(self):
response = self.view_class.as_view()(request)
self.assertEqual(response.status_code, self.throttle_expected_status)

@patch(THROTTLE_RATE_PATH, new={'logins': '1/minute'})
def test_authenticated_user_not_throttled(self):
"""An already authenticated user is not throttled."""
"""An authenticated user is not throttled by UsernameLoginRateThrottle."""
request = self.create_request('post', data={})
view = self.view_class.as_view()

class View(self.view_class):
throttle_classes = [throttling.UsernameLoginRateThrottle]

view = View.as_view()

# We are not throttled here
response = view(request)
self.assertNotEqual(response.status_code, self.throttle_expected_status)

# Or here
response = view(request)
self.assertNotEqual(response.status_code, self.throttle_expected_status)

Expand Down

0 comments on commit 9b7acd6

Please sign in to comment.