def setUp(self): self.user = User.objects.get(username='******') # Survey_template model self.survey_template = Survey_template( name='test_survey', user=self.user, ) self.survey_template.save() # Survey model self.survey = Survey( name='test_survey', user=self.user, ) self.survey.save() self.assertEqual(self.survey.__unicode__(), u'test_survey') # Section_template self.section_template = Section_template( question='test_question', survey=self.survey_template, ) self.section_template.save() # Section model self.section = Section( question='test_question', survey=self.survey, ) self.section.save() self.assertEqual(self.section.__unicode__(), u'[7] test_question') # Branching_template model self.branching_template = Branching_template( keys=5, section=self.section_template, ) self.branching_template.save() # Branching model self.branching = Branching( keys=5, section=self.section, ) self.branching.save() self.assertEqual(self.branching.__unicode__(), u'[3] 5') self.section.get_branching_count_per_section() # Result model self.result = Result( section=self.section, callrequest_id=1, response='apple' ) self.result.save() self.assertEqual( self.result.__unicode__(), '[1] [7] test_question = apple') # ResultAggregate model self.result_aggregate = ResultAggregate( survey=self.survey, campaign_id=1, section=self.section, count=1, response='apple' ) self.result_aggregate.save() self.assertEqual( self.result_aggregate.__unicode__(), '[1] [7] test_question = apple')
class SurveyModel(TestCase): """Test Survey, Section, Branching, Result, ResultAggregate Model""" fixtures = ['gateway.json', 'auth_user.json', 'contenttype.json', 'phonebook.json', 'contact.json', 'campaign.json', 'subscriber.json', 'survey_template.json', 'survey.json', 'section_template.json', 'section.json', 'branching_template.json', 'branching.json', 'callrequest.json'] def setUp(self): self.user = User.objects.get(username='******') # Survey_template model self.survey_template = Survey_template( name='test_survey', user=self.user, ) self.survey_template.save() # Survey model self.survey = Survey( name='test_survey', user=self.user, ) self.survey.save() self.assertEqual(self.survey.__unicode__(), u'test_survey') # Section_template self.section_template = Section_template( question='test_question', survey=self.survey_template, ) self.section_template.save() # Section model self.section = Section( question='test_question', survey=self.survey, ) self.section.save() self.assertEqual(self.section.__unicode__(), u'[7] test_question') # Branching_template model self.branching_template = Branching_template( keys=5, section=self.section_template, ) self.branching_template.save() # Branching model self.branching = Branching( keys=5, section=self.section, ) self.branching.save() self.assertEqual(self.branching.__unicode__(), u'[3] 5') self.section.get_branching_count_per_section() # Result model self.result = Result( section=self.section, callrequest_id=1, response='apple' ) self.result.save() self.assertEqual( self.result.__unicode__(), '[1] [7] test_question = apple') # ResultAggregate model self.result_aggregate = ResultAggregate( survey=self.survey, campaign_id=1, section=self.section, count=1, response='apple' ) self.result_aggregate.save() self.assertEqual( self.result_aggregate.__unicode__(), '[1] [7] test_question = apple') def test_survey_forms(self): self.assertEqual(self.survey_template.name, "test_survey") self.assertEqual(self.section_template.survey, self.survey_template) self.assertEqual(self.branching_template.section, self.section_template) self.assertEqual(self.result.section, self.section) form = PlayMessageSectionForm(self.user, instance=self.section_template) obj = form.save(commit=False) obj.question = "test question" obj.type = 1 obj.survey = self.survey_template obj.save() form = MultipleChoiceSectionForm(self.user, instance=self.section_template) obj = form.save(commit=False) obj.type = 2 obj.question = "test question" obj.key_0 = "apple" obj.survey = self.survey_template obj.save() form = RatingSectionForm(self.user, instance=self.section_template) obj = form.save(commit=False) obj.type = 3 obj.question = "test question" obj.rating_laps = 5 obj.survey_template = self.survey_template obj.save() form = CaptureDigitsSectionForm(self.user, instance=self.section_template) obj = form.save(commit=False) obj.type = 4 obj.question = "test question" obj.number_digits = 2 obj.min_number = 1 obj.max_number = 100 obj.survey = self.survey_template obj.save() form = RecordMessageSectionForm(self.user) obj = form.save(commit=False) obj.type = 5 obj.question = "test question" obj.survey = self.survey_template obj.save() form = CallTransferSectionForm(self.user) obj = form.save(commit=False) obj.type = 6 obj.question = "test question" obj.phonenumber = 1234567890 obj.survey = self.survey_template obj.save() form = ScriptForm() obj = form.save(commit=False) obj.script = 'xyz' obj.survey = self.survey_template obj.save() form = SurveyDetailReportForm(self.user) def teardown(self): self.survey_template.delete() self.survey.delete() self.section_template.delete() self.section.delete() self.branching_template.delete() self.branching.delete() self.result.delete() self.result_aggregate.delete()