<s> from comport . public . forms import LoginForm <EOL> from comport . user . forms import RegisterForm <EOL> from comport . department . models import Department <EOL> from comport . user . models import Invite_Code <EOL> class TestRegisterForm : <EOL> def test_validate_user_already_registered ( self , user ) : <EOL> form = RegisterForm ( username = user . username , email = '<STR_LIT>' , password = '<STR_LIT>' , confirm = '<STR_LIT>' , invite_code = "<STR_LIT>" ) <EOL> assert form . validate ( ) is False <EOL> assert '<STR_LIT>' in form . username . errors <EOL> def test_validate_email_already_registered ( self , user ) : <EOL> form = RegisterForm ( username = '<STR_LIT>' , email = user . email , password = '<STR_LIT>' , confirm = '<STR_LIT>' , invite_code = "<STR_LIT>" ) <EOL> assert form . validate ( ) is False <EOL> assert '<STR_LIT>' in form . email . errors <EOL> def test_validate_invite_code_valid ( self , user ) : <EOL> form = RegisterForm ( username = '<STR_LIT>' , email = '<STR_LIT>' , password = '<STR_LIT>' , confirm = '<STR_LIT>' , invite_code = "<STR_LIT>" ) <EOL> assert form . validate ( ) is False <EOL> assert '<STR_LIT>' in form . invite_code . errors <EOL> def test_validate_invite_code_used_already ( self , user ) : <EOL> department = Department . create ( name = "<STR_LIT>" , short_name = "<STR_LIT>" , load_defaults = False ) <EOL> Invite_Code . create ( department_id = department . id , code = "<STR_LIT>" , used = True ) <EOL> form = RegisterForm ( username = '<STR_LIT>' , email = '<STR_LIT>' , password = '<STR_LIT>' , confirm = '<STR_LIT>' , invite_code = "<STR_LIT>" ) <EOL> assert form . validate ( ) is False <EOL> assert '<STR_LIT>' in form . invite_code . errors <EOL> def test_validate_success ( self , db ) : <EOL> department = Department . create ( name = "<STR_LIT>" , short_name = "<STR_LIT>" , load_defaults = False ) <EOL> Invite_Code . create ( department_id = department . id , code = "<STR_LIT:code>" ) <EOL> form = RegisterForm ( username = '<STR_LIT>' , email = '<STR_LIT>' , password = '<STR_LIT>' , confirm = '<STR_LIT>' , invite_code = "<STR_LIT:code>" ) <EOL> assert form . validate ( ) is True <EOL> class TestLoginForm : <EOL> def test_validate_success ( self , user ) : <EOL> user . set_password ( '<STR_LIT>' ) <EOL> user . save ( ) <EOL> form = LoginForm ( username = user . username , password = '<STR_LIT>' ) <EOL> assert form . validate ( ) is True <EOL> assert form . user == user <EOL> def test_validate_unknown_username ( self , db ) : <EOL> form = LoginForm ( username = '<STR_LIT>' , password = '<STR_LIT>' ) <EOL> assert form . validate ( ) is False <EOL> assert '<STR_LIT>' in form . username . errors <EOL> assert form . user is None <EOL> def test_validate_invalid_password ( self , user ) : <EOL> user . set_password ( '<STR_LIT>' ) <EOL> user . save ( ) <EOL> form = LoginForm ( username = user . username , password = '<STR_LIT>' ) <EOL> assert form . validate ( ) is False <EOL> assert '<STR_LIT>' in form . password . errors <EOL> def test_validate_inactive_user ( self , user ) : <EOL> user . active = False <EOL> user . set_password ( '<STR_LIT>' ) <EOL> user . save ( ) <EOL> form = LoginForm ( username = user . username , password = '<STR_LIT>' ) <EOL> assert form . validate ( ) is False <EOL> assert '<STR_LIT>' in form . username . errors </s>
