Skip to content

Commit

Permalink
Don't need to patch each testcase ;)
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt Lenc committed Jun 2, 2014
1 parent 9fbeb57 commit f3dfb64
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 30 deletions.
30 changes: 0 additions & 30 deletions user_management/api/tests/test_views.py
Expand Up @@ -27,9 +27,6 @@ class GetTokenTest(APIRequestTestCase):
def tearDown(self):
cache.clear()

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'logins': '1/minute',
})
def test_post(self):
username = 'Test@example.com'
password = 'myepicstrongpassword'
Expand All @@ -41,9 +38,6 @@ def test_post(self):
response = view(request)
self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'logins': '1/minute',
})
def test_post_username(self):
username = 'Test@example.com'
password = 'myepicstrongpassword'
Expand All @@ -55,9 +49,6 @@ def test_post_username(self):
response = view(request)
self.assertEqual(response.status_code, status.HTTP_200_OK, msg=response.data)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'logins': '1/minute',
})
def test_delete(self):
user = UserFactory.create()
token = Token.objects.create(user=user)
Expand All @@ -69,9 +60,6 @@ def test_delete(self):
with self.assertRaises(Token.DoesNotExist):
Token.objects.get(pk=token.pk)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'logins': '1/minute',
})
def test_delete_no_token(self):
request = self.create_request('delete')
response = self.view_class.as_view()(request)
Expand Down Expand Up @@ -189,9 +177,6 @@ class TestPasswordResetEmail(APIRequestTestCase):
def tearDown(self):
cache.clear()

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'passwords': '1/minute',
})
def test_existent_email(self):
email = 'exists@example.com'
user = UserFactory.create(email=email)
Expand All @@ -204,18 +189,12 @@ def test_existent_email(self):

send_email.assert_called_once_with(user)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'passwords': '1/minute',
})
def test_authenticated(self):
request = self.create_request('post', auth=True)
view = self.view_class.as_view()
response = view(request)
self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'passwords': '1/minute',
})
def test_non_existent_email(self):
email = 'doesnotexist@example.com'
UserFactory.create(email='exists@example.com')
Expand All @@ -228,18 +207,12 @@ def test_non_existent_email(self):

self.assertFalse(send_email.called)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'passwords': '1/minute',
})
def test_missing_email(self):
request = self.create_request('post', auth=False)
view = self.view_class.as_view()
response = view(request)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'passwords': '1/minute',
})
def test_send_email(self):
email = 'test@example.com'
user = UserFactory.create(
Expand All @@ -258,9 +231,6 @@ def test_send_email(self):
self.assertIn('auth/password_reset/confirm/', sent_mail.body)
self.assertIn('https://', sent_mail.body)

@patch('rest_framework.throttling.ScopedRateThrottle.THROTTLE_RATES', new={
'passwords': '1/minute',
})
def test_options(self):
"""Ensure information about email field is included in options request"""
request = self.create_request('options', auth=False)
Expand Down
4 changes: 4 additions & 0 deletions user_management/tests/run.py
Expand Up @@ -39,6 +39,10 @@
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
),
'DEFAULT_THROTTLE_RATES': {
'logins': '100/day',
'passwords': '100/day',
}
},
)

Expand Down

0 comments on commit f3dfb64

Please sign in to comment.