<s> from django . test import TestCase <EOL> from . forms import SurveyForm <EOL> from . models import ( <EOL> Survey , <EOL> SurveyQuestion , <EOL> WaitingListEntry <EOL> ) <EOL> class SurveyTests ( TestCase ) : <EOL> def setUp ( self ) : <EOL> self . survey = Survey . objects . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . entry = WaitingListEntry . objects . create ( email = "<STR_LIT>" ) <EOL> self . ice_cream_question = self . survey . questions . create ( <EOL> question = "<STR_LIT>" , <EOL> kind = SurveyQuestion . TEXT_FIELD , <EOL> help_text = "<STR_LIT>" , <EOL> required = True <EOL> ) <EOL> self . summer_question = self . survey . questions . create ( <EOL> question = "<STR_LIT>" , <EOL> kind = SurveyQuestion . TEXT_AREA , <EOL> required = False <EOL> ) <EOL> self . season_question = self . survey . questions . create ( <EOL> question = "<STR_LIT>" , <EOL> kind = SurveyQuestion . RADIO_CHOICES , <EOL> required = True <EOL> ) <EOL> self . spring = self . season_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . summer = self . season_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . fall = self . season_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . winter = self . season_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . city_question = self . survey . questions . create ( <EOL> question = "<STR_LIT>" , <EOL> kind = SurveyQuestion . CHECKBOX_FIELD , <EOL> required = True <EOL> ) <EOL> self . boston = self . city_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . denver = self . city_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . nashville = self . city_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . danville = self . city_question . choices . create ( <EOL> label = "<STR_LIT>" <EOL> ) <EOL> self . golf_question = self . survey . questions . create ( <EOL> question = "<STR_LIT>" , <EOL> kind = SurveyQuestion . BOOLEAN_FIELD , <EOL> required = True <EOL> ) <EOL> def test_create_second_survey ( self ) : <EOL> Survey . objects . create ( label = "<STR_LIT>" ) <EOL> self . assertEquals ( Survey . objects . count ( ) , <NUM_LIT:2> ) <EOL> self . assertEquals ( Survey . objects . filter ( active = False ) . count ( ) , <NUM_LIT:1> ) <EOL> self . assertEquals ( Survey . objects . filter ( active = True ) . count ( ) , <NUM_LIT:1> ) <EOL> def test_survey_form_creation ( self ) : <EOL> form = SurveyForm ( survey = self . survey ) <EOL> self . assertTrue ( len ( form . fields ) , <NUM_LIT:5> ) <EOL> def test_survey_form_invalid ( self ) : <EOL> form = SurveyForm ( <EOL> data = { <EOL> self . ice_cream_question . name : "<STR_LIT>" <EOL> } , <EOL> survey = self . survey <EOL> ) <EOL> self . assertFalse ( form . is_valid ( ) ) <EOL> def test_survey_form_valid ( self ) : <EOL> form = SurveyForm ( <EOL> data = { <EOL> self . ice_cream_question . name : "<STR_LIT>" , <EOL> self . summer_question . name : "<STR_LIT>" , <EOL> self . season_question . name : self . summer . pk , <EOL> self . city_question . name : [ self . nashville . pk ] , <EOL> self . golf_question . name : True <EOL> } , <EOL> survey = self . survey <EOL> ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> def test_survey_form_save ( self ) : <EOL> form = SurveyForm ( <EOL> data = { <EOL> self . ice_cream_question . name : "<STR_LIT>" , <EOL> self . summer_question . name : "<STR_LIT>" , <EOL> self . season_question . name : self . summer . pk , <EOL> self . city_question . name : [ self . nashville . pk , self . boston . pk ] , <EOL> self . golf_question . name : True <EOL> } , <EOL> survey = self . survey <EOL> ) <EOL> self . assertTrue ( form . is_valid ( ) ) <EOL> form . save ( self . entry . surveyinstance ) <EOL> answers = self . entry . surveyinstance . answers . all ( ) <EOL> self . assertEquals ( answers . count ( ) , <NUM_LIT:5> ) <EOL> self . assertEquals ( answers . get ( question = self . ice_cream_question ) . value , "<STR_LIT>" ) <EOL> self . assertEquals ( answers . get ( question = self . summer_question ) . value , "<STR_LIT>" ) <EOL> self . assertEquals ( answers . get ( question = self . season_question ) . value , self . summer . label ) <EOL> self . assertTrue ( <EOL> self . nashville . label in answers . get ( question = self . city_question ) . value <EOL> ) <EOL> self . assertTrue ( <EOL> self . boston . label in answers . get ( question = self . city_question ) . value <EOL> ) <EOL> self . assertTrue ( answers . get ( question = self . golf_question ) . value_boolean ) </s>
