11import json
2- from django . test import override_settings
2+
33from django .contrib .auth .models import User
4- from django .db . models import Q
4+ from django .test import override_settings
55from rest_framework import status
66from rest_framework .test import APITestCase
7+
78from django_rest_passwordreset .models import ResetPasswordToken
89from tests .test .helpers import HelperMixin , patch
910
@@ -12,6 +13,7 @@ class AuthTestCase(APITestCase, HelperMixin):
1213 """
1314 Several Test Cases for the Multi Auth Token Django App
1415 """
16+
1517 def setUp (self ):
1618 self .setUpUrls ()
1719 self .
user1 = User .
objects .
create_user (
"user1" ,
"[email protected] " ,
"secret1" )
@@ -72,7 +74,7 @@ def test_validate_bad_token(self):
7274 # try to validate an invalid token
7375 response = self .rest_do_validate_token ("not_a_valid_token" )
7476 self .assertEqual (response .status_code , status .HTTP_404_NOT_FOUND )
75-
77+
7678 # there should be zero tokens
7779 self .assertEqual (ResetPasswordToken .objects .all ().count (), 0 )
7880
@@ -224,21 +226,20 @@ def test_reset_password_multiple_users(self, mock_reset_password_token_created):
224226 # connect signal
225227 # we need to check whether the signal is getting called
226228
227-
228229 # create a token for user 1
229230 response = self .
rest_do_request_reset_token (
email = "[email protected] " )
230231 self .assertEqual (response .status_code , status .HTTP_200_OK )
231232 self .assertEqual (ResetPasswordToken .objects .all ().count (), 1 )
232233 self .assertTrue (mock_reset_password_token_created .called )
233- self .assertEquals (mock_reset_password_token_created .call_count , 1 )
234+ self .assertEqual (mock_reset_password_token_created .call_count , 1 )
234235 token1 = mock_reset_password_token_created .call_args [1 ]['reset_password_token' ]
235236
236237 # create another token for user 2
237238 response = self .
rest_do_request_reset_token (
email = "[email protected] " )
238239 self .assertEqual (response .status_code , status .HTTP_200_OK )
239240 tokens = ResetPasswordToken .objects .all ()
240241 self .assertEqual (tokens .count (), 2 )
241- self .assertEquals (mock_reset_password_token_created .call_count , 2 )
242+ self .assertEqual (mock_reset_password_token_created .call_count , 2 )
242243 token2 = mock_reset_password_token_created .call_args [1 ]['reset_password_token' ]
243244
244245 # validate that those two tokens are different
@@ -269,7 +270,7 @@ def test_reset_password_multiple_users(self, mock_reset_password_token_created):
269270
270271 # try to reset again with token2 (should not work)
271272 response = self .rest_do_reset_password_with_token (token2 .key , "secret2_fake_new" )
272- self .assertEquals (response .status_code , status .HTTP_404_NOT_FOUND )
273+ self .assertEqual (response .status_code , status .HTTP_404_NOT_FOUND )
273274
274275 # user 2 should still be able to login with "secret2_new" now
275276 self .assertTrue (
@@ -296,10 +297,11 @@ def test_signals(self,
296297
297298 # verify that the reset_password_token_created signal was fired
298299 self .assertTrue (mock_reset_password_token_created .called )
299- self .assertEquals (mock_reset_password_token_created .call_count , 1 )
300+ self .assertEqual (mock_reset_password_token_created .call_count , 1 )
300301
301302 token1 = mock_reset_password_token_created .call_args [1 ]['reset_password_token' ]
302- self .assertNotEqual (token1 .key , "" , msg = "Verify that the reset_password_token of the reset_password_Token_created signal is not empty" )
303+ self .assertNotEqual (token1 .key , "" ,
304+ msg = "Verify that the reset_password_token of the reset_password_Token_created signal is not empty" )
303305
304306 # verify that the other two signals have not yet been called
305307 self .assertFalse (mock_post_password_reset .called )
@@ -315,12 +317,13 @@ def test_signals(self,
315317
316318 @override_settings (DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE = True )
317319 def test_try_reset_password_email_does_not_exist_no_leakage_enabled (self ):
318- """
320+ """
319321 Tests requesting a token for an email that does not exist when
320322 DJANGO_REST_PASSWORDRESET_NO_INFORMATION_LEAKAGE == True
321- """
323+ """
322324 response = self .
rest_do_request_reset_token (
email = "[email protected] " )
323325 self .assertEqual (response .status_code , status .HTTP_200_OK )
326+
324327 def test_user_without_password (self ):
325328 """ Tests requesting a token for an email without a password doesn't work"""
326329 response = self .
rest_do_request_reset_token (
email = "[email protected] " )
@@ -334,7 +337,6 @@ def test_user_without_password(self):
334337 def test_user_without_password_where_not_required (self , mock_reset_password_token_created ):
335338 """ Tests requesting a token for an email without a password works when not required"""
336339 response = self .
rest_do_request_reset_token (
email = "[email protected] " )
337- decoded_response = json .loads (response .content .decode ())
338340 self .assertEqual (response .status_code , status .HTTP_200_OK )
339341 # check that the signal was sent once
340342 self .assertTrue (mock_reset_password_token_created .called )
@@ -372,4 +374,3 @@ def test_user_without_password_where_not_required(self, mock_reset_password_toke
372374 self .django_check_login ("user4" , "new_secret" ),
373375 msg = "User 4 should be able to login with the modified credentials"
374376 )
375-
0 commit comments