Skip to content

Commit

Permalink
Moved check_post_rate_limit inside TestPasswordResetEmail
Browse files Browse the repository at this point in the history
  • Loading branch information
SemVerTsar committed Oct 30, 2014
1 parent 5f3e31c commit 5b0359a
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions user_management/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,12 +214,6 @@ def test_duplicate_email(self):
self.assertFalse(User.objects.count() > 1)


def check_post_rate_limit(self, view, data, expected_status):
request = self.create_request('post', data=data, auth=False)
response = view(request)
self.assertEqual(response.status_code, expected_status)


class TestPasswordResetEmail(APIRequestTestCase):
view_class = views.PasswordResetEmail

Expand All @@ -242,6 +236,11 @@ def test_existent_email(self):

send_email.assert_called_once_with(user)

def check_post_rate_limit(self, view, data, expected_status):
request = self.create_request('post', data=data, auth=False)
response = view(request)
self.assertEqual(response.status_code, expected_status)

def test_post_rate_limit(self):
"""
Ensure the post requests are rate limited.
Expand All @@ -256,16 +255,10 @@ def test_post_rate_limit(self):
# Test the the first 3 requests aren't limited.
data = {'email': email}
for i in range(rate_limit):
check_post_rate_limit(
self,
view,
data,
status.HTTP_204_NO_CONTENT,
)
self.check_post_rate_limit(view, data, status.HTTP_204_NO_CONTENT)

# Test that the 4th request is throttled.
check_post_rate_limit(
self,
self.check_post_rate_limit(
view,
data,
status.HTTP_429_TOO_MANY_REQUESTS,
Expand Down

0 comments on commit 5b0359a

Please sign in to comment.