<s> from django . test import TestCase <EOL> from django . contrib . auth . models import User , Group <EOL> from projector . forms import DashboardAddMemberForm <EOL> class DashboardAddMemberFormTest ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . group = Group . objects . create ( name = '<STR_LIT>' ) <EOL> self . user = User . objects . create ( username = '<STR_LIT>' ) <EOL> self . user . groups . add ( self . group ) <EOL> profile = self . user . get_profile ( ) <EOL> profile . group = self . group <EOL> profile . is_team = True <EOL> profile . save ( ) <EOL> def test_wrong_user ( self ) : <EOL> data = { '<STR_LIT:user>' : '<STR_LIT>' } <EOL> form = DashboardAddMemberForm ( self . group , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertTrue ( '<STR_LIT:user>' in form . _errors ) <EOL> def test_wrong_username ( self ) : <EOL> wrong_usernames = ( '<STR_LIT:U+0020>' , '<STR_LIT:.>' , '<STR_LIT:*>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for username in wrong_usernames : <EOL> data = { '<STR_LIT:user>' : username } <EOL> form = DashboardAddMemberForm ( self . group , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertTrue ( '<STR_LIT:user>' in form . _errors ) <EOL> def test_proper_user ( self ) : <EOL> joe = User . objects . create ( username = '<STR_LIT>' ) <EOL> data = { '<STR_LIT:user>' : joe . username } <EOL> form = DashboardAddMemberForm ( self . group , data ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> def test_already_in_group ( self ) : <EOL> data = { '<STR_LIT:user>' : self . user . username } <EOL> form = DashboardAddMemberForm ( self . group , data ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> self . assertTrue ( '<STR_LIT:user>' in form . _errors ) </s>
