<s> from huxley . accounts . exceptions import PasswordChangeFailed <EOL> from huxley . accounts . models import User <EOL> from huxley . api . tests import UpdateAPITestCase <EOL> from huxley . utils . test import TestUsers <EOL> class ChangePasswordTestCase ( UpdateAPITestCase ) : <EOL> url_name = '<STR_LIT>' <EOL> is_resource = False <EOL> params = { '<STR_LIT:password>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' } <EOL> def setUp ( self ) : <EOL> self . user = TestUsers . new_user ( username = '<STR_LIT>' , <EOL> password = '<STR_LIT>' ) <EOL> def login ( self ) : <EOL> self . client . login ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> def test_anonymous_user ( self ) : <EOL> '''<STR_LIT>''' <EOL> response = self . get_response ( ) <EOL> self . assertPermissionDenied ( response ) <EOL> user = User . objects . get ( id = self . user . id ) <EOL> self . assertTrue ( user . check_password ( '<STR_LIT>' ) ) <EOL> def test_self ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . login ( ) <EOL> response = self . get_response ( ) <EOL> self . assertOK ( response ) <EOL> user = User . objects . get ( id = self . user . id ) <EOL> self . assertTrue ( user . check_password ( '<STR_LIT>' ) ) <EOL> def test_missing_fields ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . login ( ) <EOL> params = self . get_params ( new_password = '<STR_LIT>' ) <EOL> response = self . get_response ( params = params ) <EOL> self . assertEqual ( response . data , { <EOL> '<STR_LIT>' : PasswordChangeFailed . MISSING_FIELDS } ) <EOL> user = User . objects . get ( id = self . user . id ) <EOL> self . assertTrue ( user . check_password ( '<STR_LIT>' ) ) <EOL> params = self . get_params ( password = '<STR_LIT>' ) <EOL> response = self . get_response ( params = params ) <EOL> self . assertEqual ( response . data , { <EOL> '<STR_LIT>' : PasswordChangeFailed . MISSING_FIELDS } ) <EOL> user = User . objects . get ( id = self . user . id ) <EOL> self . assertTrue ( user . check_password ( '<STR_LIT>' ) ) <EOL> def test_short_password ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . login ( ) <EOL> params = self . get_params ( new_password = '<STR_LIT:a>' ) <EOL> response = self . get_response ( params = params ) <EOL> self . assertEqual ( response . data , { <EOL> '<STR_LIT>' : PasswordChangeFailed . PASSWORD_TOO_SHORT } ) <EOL> user = User . objects . get ( id = self . user . id ) <EOL> self . assertTrue ( user . check_password ( '<STR_LIT>' ) ) <EOL> def test_invalid_password ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . login ( ) <EOL> params = self . get_params ( new_password = '<STR_LIT>' ) <EOL> response = self . get_response ( params = params ) <EOL> self . assertEqual ( response . data , { <EOL> '<STR_LIT>' : PasswordChangeFailed . INVALID_CHARACTERS } ) <EOL> user = User . objects . get ( id = self . user . id ) <EOL> self . assertTrue ( user . check_password ( '<STR_LIT>' ) ) <EOL> def test_incorrect_password ( self ) : <EOL> '''<STR_LIT>''' <EOL> self . login ( ) <EOL> params = self . get_params ( password = '<STR_LIT>' ) <EOL> response = self . get_response ( params = params ) <EOL> self . assertEqual ( response . data , { <EOL> '<STR_LIT>' : PasswordChangeFailed . INCORRECT_PASSWORD } ) <EOL> user = User . objects . get ( id = self . user . id ) <EOL> self . assertTrue ( user . check_password ( '<STR_LIT>' ) ) </s>
