def test_formats_headers_for_csv_leaving_out_country(self): result_down_load_service = ResultsDownloadService(batch=self.batch) header_structure = [unicode(self.district.name), unicode(self.county.name), unicode(self.subcounty.name), unicode(self.parish.name), unicode(self.village.name),unicode(self.ea.name), 'Household Number', 'Family Name', 'First Name', 'Age', 'Date of Birth', 'Gender' ] headers = result_down_load_service.set_report_headers() self.assertEqual(header_structure, headers)
def test_formats_headers_for_csv_leaving_out_country(self): result_down_load_service = ResultsDownloadService(batch=self.batch) header_structure = [self.district.name, self.county.name, self.subcounty.name, self.parish.name, self.village.name, 'Household ID', 'Name', 'Age', 'Month of Birth', 'Year of Birth', 'Gender', self.question_1.identifier, self.question_2.identifier, '', self.question_3.identifier] headers = result_down_load_service.set_report_headers() self.assertEqual(header_structure, headers)
def test_formats_headers_for_csv_leaving_out_country(self): result_down_load_service = ResultsDownloadService(batch=self.batch) header_structure = [self.district.name, self.county.name, self.subcounty.name, self.parish.name, self.village.name, 'Household ID', 'Name', 'Age', 'Month of Birth', 'Year of Birth', 'Gender', self.question_1.identifier, self.question_2.identifier, '', self.question_3.identifier] headers = result_down_load_service.set_report_headers() self.assertEqual(header_structure, headers)
def test_gets_summarised_response_for_all_batches_under_survey(self): household_listing = HouseholdListing.objects.create(ea=self.ea,list_registrar=self.investigator,initial_survey=self.survey) survey_householdlisting = SurveyHouseholdListing.objects.create(listing=household_listing,survey=self.survey) HouseholdMemberGroup.objects.create(name="GENERAL", order=2) household_head_1 = create_household_head(0, self.investigator,household_listing,survey_householdlisting) household_head_2 = create_household_head(1, self.investigator,household_listing,survey_householdlisting) household_head_3 = create_household_head(2, self.investigator,household_listing,survey_householdlisting) household_head_4 = create_household_head(3, self.investigator,household_listing,survey_householdlisting) household_head_5 = create_household_head(4, self.investigator,household_listing,survey_householdlisting) batchB = Batch.objects.create(order=2, name="different batch", survey=self.survey) module = QuestionModule.objects.create(name="Education in a different batch") question_1B = Question.objects.create(identifier='1.21',text="This is a question21", answer_type='Numerical Answer', group=self.group,batch=self.batch,module=module) question_2B = Question.objects.create(identifier='1.22',text="This is a question22", answer_type='Numerical Answer', group=self.group,batch=self.batch,module=module) question_3B = Question.objects.create(identifier='1.23',text="This is a question23", answer_type='Numerical Answer', group=self.group,batch=self.batch,module=module) yes_option = QuestionOption.objects.create(question=question_2B, text="Yes", order=1) no_option = QuestionOption.objects.create(question=question_2B, text="No", order=2) result_down_load_service = ResultsDownloadService(survey=self.survey) header_structure = [unicode(self.district.name), unicode(self.county.name), unicode(self.subcounty.name), unicode(self.parish.name), unicode(self.village.name), unicode(self.ea.name), 'Household Number', 'Family Name', 'First Name','Age', 'Date of Birth', 'Gender'] headers = result_down_load_service.set_report_headers() self.assertEqual(header_structure, headers) AGE = '28' household1=household_head_1.surname+'-'+household_head_1.first_name household2=household_head_2.surname+'-'+household_head_2.first_name household3=household_head_3.surname+'-'+household_head_3.first_name household4=household_head_4.surname+'-'+household_head_4.first_name household5=household_head_5.surname+'-'+household_head_5.first_name expected_csv_data = [ [u'Kampala', unicode(self.ea.name),household_head_2.household.house_number, unicode(household2), AGE, '01-01-1988', 'Male' if household_head_2.household.head_sex else 'Female'], [u'Kampala', unicode(self.ea.name),household_head_3.household.house_number, unicode(household3), AGE, '01-01-1988', 'Male' if household_head_3.household.head_sex else 'Female'], [u'Kampala', unicode(self.ea.name),household_head_4.household.house_number, unicode(household4),AGE, '01-01-1988', 'Male' if household_head_4.household.head_sex else 'Female'], [u'Kampala', unicode(self.ea.name),household_head_5.household.house_number, unicode(household5),AGE, '01-01-1988', 'Male' if household_head_5.household.head_sex else 'Female']] actual_csv_data = result_down_load_service.get_summarised_answers() self.assertEqual(5, len(actual_csv_data)) for i in range(4): self.assertIn(expected_csv_data[i], actual_csv_data)
def test_gets_summarised_response_for_all_batches_under_survey(self): HouseholdMemberGroup.objects.create(name="GENERAL", order=2) household_head_1 = self.create_household_head(0, self.investigator, self.batch.survey) household_head_2 = self.create_household_head(1, self.investigator, self.batch.survey) household_head_3 = self.create_household_head(2, self.investigator, self.batch.survey) household_head_4 = self.create_household_head(3, self.investigator, self.batch.survey) household_head_5 = self.create_household_head(4, self.investigator, self.batch.survey) self.investigator.member_answered(self.question_1, household_head_1, 1, self.batch) self.investigator.member_answered(self.question_1, household_head_2, 2, self.batch) self.investigator.member_answered(self.question_1, household_head_3, 1, self.batch) self.investigator.member_answered(self.question_1, household_head_4, 2, self.batch) self.investigator.member_answered(self.question_1, household_head_5, 3, self.batch) self.investigator.member_answered(self.question_2, household_head_1, self.no_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_2, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_3, self.no_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_4, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_5, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_3, household_head_1, 1, self.batch) self.investigator.member_answered(self.question_3, household_head_2, 2, self.batch) self.investigator.member_answered(self.question_3, household_head_3, 1, self.batch) self.investigator.member_answered(self.question_3, household_head_4, 2, self.batch) self.investigator.member_answered(self.question_3, household_head_5, 3, self.batch) batchB = Batch.objects.create(order=2, name="different batch", survey=self.survey) module = QuestionModule.objects.create(name="Education in a different batch") question_1B = Question.objects.create(group=self.group, text="Question 1 B", module=module, answer_type=Question.NUMBER, order=1, identifier='Q1B') question_2B = Question.objects.create(group=self.group, text="Question 2B", module=module, answer_type=Question.MULTICHOICE, order=2, identifier='Q2B') question_3B = Question.objects.create(group=self.group, text="Question 3B", module=module, answer_type=Question.NUMBER, order=3, identifier='Q3B') yes_option = QuestionOption.objects.create(question=question_2B, text="Yes", order=1) no_option = QuestionOption.objects.create(question=question_2B, text="No", order=2) question_1B.batches.add(batchB) question_2B.batches.add(batchB) question_3B.batches.add(batchB) BatchQuestionOrder.objects.create(question=question_1B, batch=batchB, order=1) BatchQuestionOrder.objects.create(question=question_2B, batch=batchB, order=2) BatchQuestionOrder.objects.create(question=question_3B, batch=batchB, order=3) self.investigator.member_answered(question_1B, household_head_1, 1, batchB) self.investigator.member_answered(question_1B, household_head_2, 2, batchB) self.investigator.member_answered(question_1B, household_head_3, 1, batchB) self.investigator.member_answered(question_1B, household_head_4, 2, batchB) self.investigator.member_answered(question_1B, household_head_5, 3, batchB) self.investigator.member_answered(question_2B, household_head_1, no_option.order, batchB) self.investigator.member_answered(question_2B, household_head_2, yes_option.order, batchB) self.investigator.member_answered(question_2B, household_head_3, no_option.order, batchB) self.investigator.member_answered(question_2B, household_head_4, yes_option.order, batchB) self.investigator.member_answered(question_2B, household_head_5, yes_option.order, batchB) self.investigator.member_answered(question_3B, household_head_1, 1, batchB) self.investigator.member_answered(question_3B, household_head_2, 2, batchB) self.investigator.member_answered(question_3B, household_head_3, 1, batchB) self.investigator.member_answered(question_3B, household_head_4, 2, batchB) self.investigator.member_answered(question_3B, household_head_5, 3, batchB) result_down_load_service = ResultsDownloadService(survey=self.survey) header_structure = [self.district.name, self.county.name, self.subcounty.name, self.parish.name, self.village.name, 'Household ID', 'Name', 'Age', 'Month of Birth', 'Year of Birth', 'Gender', self.question_1.identifier, self.question_2.identifier, '', self.question_3.identifier, question_1B.identifier, question_2B.identifier, '', question_3B.identifier] headers = result_down_load_service.set_report_headers() self.assertEqual(header_structure, headers) age = '24' expected_csv_data = [ ['Kampala', household_head_1.household.household_code, household_head_1.surname, age, '2', '1990', 'Male' if household_head_1.male else 'Female', 1, self.no_option.order, self.no_option.text, 1, 1, no_option.order, no_option.text, 1], ['Kampala', household_head_2.household.household_code, household_head_2.surname, age, '2', '1990', 'Male' if household_head_2.male else 'Female', 2, self.yes_option.order, self.yes_option.text, 2, 2, yes_option.order, yes_option.text, 2], ['Kampala', household_head_3.household.household_code, household_head_3.surname, age, '2', '1990', 'Male' if household_head_3.male else 'Female', 1, self.no_option.order, self.no_option.text, 1, 1, no_option.order, no_option.text, 1], ['Kampala', household_head_4.household.household_code, household_head_4.surname, age, '2', '1990', 'Male' if household_head_4.male else 'Female', 2, self.yes_option.order, self.yes_option.text, 2, 2, yes_option.order, yes_option.text, 2], ['Kampala', household_head_5.household.household_code, household_head_5.surname, age, '2', '1990', 'Male' if household_head_5.male else 'Female', 3, self.yes_option.order, self.yes_option.text, 3, 3, yes_option.order, yes_option.text, 3]] actual_csv_data = result_down_load_service.get_summarised_answers() self.assertEqual(5, len(actual_csv_data)) for i in range(5): self.assertIn(expected_csv_data[i], actual_csv_data)
def test_gets_summarised_response_for_all_batches_under_survey(self): HouseholdMemberGroup.objects.create(name="GENERAL", order=2) household_head_1 = self.create_household_head(0, self.investigator, self.batch.survey) household_head_2 = self.create_household_head(1, self.investigator, self.batch.survey) household_head_3 = self.create_household_head(2, self.investigator, self.batch.survey) household_head_4 = self.create_household_head(3, self.investigator, self.batch.survey) household_head_5 = self.create_household_head(4, self.investigator, self.batch.survey) self.investigator.member_answered(self.question_1, household_head_1, 1, self.batch) self.investigator.member_answered(self.question_1, household_head_2, 2, self.batch) self.investigator.member_answered(self.question_1, household_head_3, 1, self.batch) self.investigator.member_answered(self.question_1, household_head_4, 2, self.batch) self.investigator.member_answered(self.question_1, household_head_5, 3, self.batch) self.investigator.member_answered(self.question_2, household_head_1, self.no_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_2, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_3, self.no_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_4, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_2, household_head_5, self.yes_option.order, self.batch) self.investigator.member_answered(self.question_3, household_head_1, 1, self.batch) self.investigator.member_answered(self.question_3, household_head_2, 2, self.batch) self.investigator.member_answered(self.question_3, household_head_3, 1, self.batch) self.investigator.member_answered(self.question_3, household_head_4, 2, self.batch) self.investigator.member_answered(self.question_3, household_head_5, 3, self.batch) batchB = Batch.objects.create(order=2, name="different batch", survey=self.survey) module = QuestionModule.objects.create(name="Education in a different batch") question_1B = Question.objects.create(group=self.group, text="Question 1 B", module=module, answer_type=Question.NUMBER, order=1, identifier='Q1B') question_2B = Question.objects.create(group=self.group, text="Question 2B", module=module, answer_type=Question.MULTICHOICE, order=2, identifier='Q2B') question_3B = Question.objects.create(group=self.group, text="Question 3B", module=module, answer_type=Question.NUMBER, order=3, identifier='Q3B') yes_option = QuestionOption.objects.create(question=question_2B, text="Yes", order=1) no_option = QuestionOption.objects.create(question=question_2B, text="No", order=2) question_1B.batches.add(batchB) question_2B.batches.add(batchB) question_3B.batches.add(batchB) BatchQuestionOrder.objects.create(question=question_1B, batch=batchB, order=1) BatchQuestionOrder.objects.create(question=question_2B, batch=batchB, order=2) BatchQuestionOrder.objects.create(question=question_3B, batch=batchB, order=3) self.investigator.member_answered(question_1B, household_head_1, 1, batchB) self.investigator.member_answered(question_1B, household_head_2, 2, batchB) self.investigator.member_answered(question_1B, household_head_3, 1, batchB) self.investigator.member_answered(question_1B, household_head_4, 2, batchB) self.investigator.member_answered(question_1B, household_head_5, 3, batchB) self.investigator.member_answered(question_2B, household_head_1, no_option.order, batchB) self.investigator.member_answered(question_2B, household_head_2, yes_option.order, batchB) self.investigator.member_answered(question_2B, household_head_3, no_option.order, batchB) self.investigator.member_answered(question_2B, household_head_4, yes_option.order, batchB) self.investigator.member_answered(question_2B, household_head_5, yes_option.order, batchB) self.investigator.member_answered(question_3B, household_head_1, 1, batchB) self.investigator.member_answered(question_3B, household_head_2, 2, batchB) self.investigator.member_answered(question_3B, household_head_3, 1, batchB) self.investigator.member_answered(question_3B, household_head_4, 2, batchB) self.investigator.member_answered(question_3B, household_head_5, 3, batchB) result_down_load_service = ResultsDownloadService(survey=self.survey) header_structure = [self.district.name, self.county.name, self.subcounty.name, self.parish.name, self.village.name, 'Household ID', 'Name', 'Age', 'Month of Birth', 'Year of Birth', 'Gender', self.question_1.identifier, self.question_2.identifier, '', self.question_3.identifier, question_1B.identifier, question_2B.identifier, '', question_3B.identifier] headers = result_down_load_service.set_report_headers() self.assertEqual(header_structure, headers) age = '24' expected_csv_data = [ ['Kampala', household_head_1.household.household_code, household_head_1.surname, age, '2', '1990', 'Male' if household_head_1.male else 'Female', 1, self.no_option.order, self.no_option.text, 1, 1, no_option.order, no_option.text, 1], ['Kampala', household_head_2.household.household_code, household_head_2.surname, age, '2', '1990', 'Male' if household_head_2.male else 'Female', 2, self.yes_option.order, self.yes_option.text, 2, 2, yes_option.order, yes_option.text, 2], ['Kampala', household_head_3.household.household_code, household_head_3.surname, age, '2', '1990', 'Male' if household_head_3.male else 'Female', 1, self.no_option.order, self.no_option.text, 1, 1, no_option.order, no_option.text, 1], ['Kampala', household_head_4.household.household_code, household_head_4.surname, age, '2', '1990', 'Male' if household_head_4.male else 'Female', 2, self.yes_option.order, self.yes_option.text, 2, 2, yes_option.order, yes_option.text, 2], ['Kampala', household_head_5.household.household_code, household_head_5.surname, age, '2', '1990', 'Male' if household_head_5.male else 'Female', 3, self.yes_option.order, self.yes_option.text, 3, 3, yes_option.order, yes_option.text, 3]] actual_csv_data = result_down_load_service.get_summarised_answers() self.assertEqual(5, len(actual_csv_data)) for i in range(5): self.assertIn(expected_csv_data[i], actual_csv_data)