<s> from django . contrib . auth . models import User <EOL> from django . contrib . auth . forms import UserCreationForm , AuthenticationForm , PasswordChangeForm , SetPasswordForm , UserChangeForm , PasswordResetForm <EOL> from django . test import TestCase <EOL> class UserCreationFormTest ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_user_already_exists ( self ) : <EOL> data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> form = UserCreationForm ( data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ "<STR_LIT:username>" ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_invalid_data ( self ) : <EOL> data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> form = UserCreationForm ( data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ "<STR_LIT:username>" ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_password_verification ( self ) : <EOL> data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:test>' , <EOL> } <EOL> form = UserCreationForm ( data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . errors , <EOL> [ u"<STR_LIT>" ] ) <EOL> def test_both_passwords ( self ) : <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' } <EOL> form = UserCreationForm ( data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> data [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> form = UserCreationForm ( data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ '<STR_LIT>' ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_success ( self ) : <EOL> data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> form = UserCreationForm ( data ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> u = form . save ( ) <EOL> self . assertEqual ( repr ( u ) , '<STR_LIT>' ) <EOL> class AuthenticationFormTest ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_invalid_username ( self ) : <EOL> data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT>' , <EOL> } <EOL> form = AuthenticationForm ( None , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . non_field_errors ( ) , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_inactive_user ( self ) : <EOL> data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> } <EOL> form = AuthenticationForm ( None , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . non_field_errors ( ) , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_success ( self ) : <EOL> data = { <EOL> '<STR_LIT:username>' : '<STR_LIT>' , <EOL> '<STR_LIT:password>' : '<STR_LIT:password>' , <EOL> } <EOL> form = AuthenticationForm ( None , data ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . non_field_errors ( ) , [ ] ) <EOL> class SetPasswordFormTest ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_password_verification ( self ) : <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:abc>' , <EOL> } <EOL> form = SetPasswordForm ( user , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . errors , <EOL> [ u"<STR_LIT>" ] ) <EOL> def test_success ( self ) : <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> form = SetPasswordForm ( user , data ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> class PasswordChangeFormTest ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_incorrect_password ( self ) : <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:test>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> form = PasswordChangeForm ( user , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_password_verification ( self ) : <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT:abc>' , <EOL> } <EOL> form = PasswordChangeForm ( user , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ "<STR_LIT>" ] . errors , <EOL> [ u"<STR_LIT>" ] ) <EOL> def test_success ( self ) : <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> data = { <EOL> '<STR_LIT>' : '<STR_LIT:password>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> form = PasswordChangeForm ( user , data ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> def test_field_order ( self ) : <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> self . assertEqual ( PasswordChangeForm ( user , { } ) . fields . keys ( ) , <EOL> [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> class UserChangeFormTest ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_username_validity ( self ) : <EOL> user = User . objects . get ( username = '<STR_LIT>' ) <EOL> data = { '<STR_LIT:username>' : '<STR_LIT>' } <EOL> form = UserChangeForm ( data , instance = user ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ '<STR_LIT:username>' ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_bug_14242 ( self ) : <EOL> class MyUserForm ( UserChangeForm ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> super ( MyUserForm , self ) . __init__ ( * args , ** kwargs ) <EOL> self . fields [ '<STR_LIT>' ] . help_text = '<STR_LIT>' <EOL> class Meta ( UserChangeForm . Meta ) : <EOL> fields = ( '<STR_LIT>' , ) <EOL> form = MyUserForm ( { } ) <EOL> class PasswordResetFormTest ( TestCase ) : <EOL> fixtures = [ '<STR_LIT>' ] <EOL> def test_invalid_email ( self ) : <EOL> data = { '<STR_LIT:email>' : '<STR_LIT>' } <EOL> form = PasswordResetForm ( data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form [ '<STR_LIT:email>' ] . errors , <EOL> [ u'<STR_LIT>' ] ) <EOL> def test_nonexistant_email ( self ) : <EOL> data = { '<STR_LIT:email>' : '<STR_LIT>' } <EOL> form = PasswordResetForm ( data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . errors , <EOL> { '<STR_LIT:email>' : [ u"<STR_LIT>" ] } ) <EOL> def test_cleaned_data ( self ) : <EOL> user = User . objects . create_user ( "<STR_LIT>" , "<STR_LIT>" , "<STR_LIT>" ) <EOL> data = { '<STR_LIT:email>' : '<STR_LIT>' } <EOL> form = PasswordResetForm ( data ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> self . assertEqual ( form . cleaned_data [ '<STR_LIT:email>' ] , u'<STR_LIT>' ) <EOL> def test_bug_5605 ( self ) : <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> self . assertEqual ( user . email , '<STR_LIT>' ) <EOL> user = User . objects . create_user ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:test>' ) <EOL> self . assertEqual ( user . email , '<STR_LIT>' ) </s>
