def test_should_show_data_only_for_investigators_who_completed_a_selected_batch(self): batch = Batch.objects.create(name="Batch 2", survey=self.survey) member_group = HouseholdMemberGroup.objects.create(name='group1', order=1) question_1 = Question.objects.create(text="some question", answer_type=Question.NUMBER, order=1, group=member_group) question_2 = Question.objects.create(text="some question", answer_type=Question.NUMBER, order=1, group=member_group) self.batch.questions.add(question_1) batch.questions.add(question_2) batch.open_for_location(self.abim) BatchQuestionOrder.objects.create(question=question_1, batch=self.batch, order=1) BatchQuestionOrder.objects.create(question=question_2, batch=batch, order=1) member_1 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime(2000, 02, 02)) member_2 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime(2000, 02, 02)) self.investigator_1.member_answered(question_1, member_1, 1, self.batch) data = [self.investigator_1.name, self.investigator_1.mobile_number] data.extend([loc.name for loc in self.investigator_1.location_hierarchy().values()]) investigator_completion = Investigator.generate_completion_report(self.survey, self.batch) self.assertNotIn(data, investigator_completion) self.investigator_1.member_answered(question_1, member_2, 1, self.batch) investigator_completion = Investigator.generate_completion_report(self.survey, self.batch) self.assertIn(data, investigator_completion)
def send(request): params = dict(request.POST) if valid_parameters(params, request): locations = Location.objects.filter(id__in=params['locations']) Investigator.sms_investigators_in_locations(locations=locations, text=params['text'][0]) messages.success(request, "Your message has been sent to investigators.") return HttpResponseRedirect(reverse('bulk_sms'))
def test_should_show_data_only_for_investigators_who_completed_the_survey( self): member_group = HouseholdMemberGroup.objects.create(name='group1', order=1) question = Question.objects.create(text="some question", answer_type=Question.NUMBER, order=1, group=member_group) self.batch.questions.add(question) BatchQuestionOrder.objects.create(question=question, batch=self.batch, order=1) member_1 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime( 2000, 02, 02)) member_2 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime( 2000, 02, 02)) member_3 = HouseholdMember.objects.create(household=self.household_2, date_of_birth=datetime( 2000, 02, 02)) self.investigator_1.member_answered(question, member_1, 1, self.batch) self.investigator_1.member_answered(question, member_2, 1, self.batch) data = [self.investigator_1.name, self.investigator_1.mobile_number] data.extend([ loc.name for loc in self.investigator_1.location_hierarchy().values() ]) response = Investigator.generate_completion_report(self.survey) self.assertNotIn(data, response) self.investigator_1.member_answered(question, member_3, 1, self.batch) response = Investigator.generate_completion_report(self.survey) self.assertIn(data, response)
def test_should_show_data_only_for_investigators_who_completed_a_selected_batch( self): batch = Batch.objects.create(name="Batch 2", survey=self.survey) member_group = HouseholdMemberGroup.objects.create(name='group1', order=1) question_1 = Question.objects.create(text="some question", answer_type=Question.NUMBER, order=1, group=member_group) question_2 = Question.objects.create(text="some question", answer_type=Question.NUMBER, order=1, group=member_group) self.batch.questions.add(question_1) batch.questions.add(question_2) batch.open_for_location(self.abim) BatchQuestionOrder.objects.create(question=question_1, batch=self.batch, order=1) BatchQuestionOrder.objects.create(question=question_2, batch=batch, order=1) member_1 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime( 2000, 02, 02)) member_2 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime( 2000, 02, 02)) self.investigator_1.member_answered(question_1, member_1, 1, self.batch) data = [self.investigator_1.name, self.investigator_1.mobile_number] data.extend([ loc.name for loc in self.investigator_1.location_hierarchy().values() ]) investigator_completion = Investigator.generate_completion_report( self.survey, self.batch) self.assertNotIn(data, investigator_completion) self.investigator_1.member_answered(question_1, member_2, 1, self.batch) investigator_completion = Investigator.generate_completion_report( self.survey, self.batch) self.assertIn(data, investigator_completion)
def test_should_return_headers_when_generate_report_called(self): Investigator.objects.all().delete() data = ['Investigator', 'Phone Number'] data.extend(LocationType.objects.all().values_list('name', flat=True)) response = Investigator.generate_completion_report(self.survey) self.assertIn(data, response)
def test_should_return_data_when_generate_data_called(self): data = [self.investigator_1.name, self.investigator_1.mobile_number] data.extend([ loc.name for loc in self.investigator_1.location_hierarchy().values() ]) response = Investigator.generate_completion_report(self.survey) self.assertIn(data, response)
def compute_for_location(self, location): investigators = Investigator.lives_under_location(location) if self.numerator.is_multichoice(): return self.compute_multichoice_question_for_investigators( investigators) else: return self.compute_numerical_question_for_investigators( investigators)
def test_fields(self): investigator = Investigator() fields = [str(item.attname) for item in investigator._meta.fields] self.assertEqual(len(fields), 13) for field in [ 'id', 'name', 'mobile_number', 'created', 'modified', 'male', 'age', 'level_of_education', 'ea_id', 'language', 'backend_id', 'weights', 'is_blocked' ]: self.assertIn(field, fields)
def test_should_show_data_only_for_investigators_who_completed_the_survey(self): member_group = HouseholdMemberGroup.objects.create(name='group1', order=1) question = Question.objects.create(text="some question", answer_type=Question.NUMBER, order=1, group=member_group) self.batch.questions.add(question) BatchQuestionOrder.objects.create(question=question, batch=self.batch, order=1) member_1 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime(2000, 02, 02)) member_2 = HouseholdMember.objects.create(household=self.household_1, date_of_birth=datetime(2000, 02, 02)) member_3 = HouseholdMember.objects.create(household=self.household_2, date_of_birth=datetime(2000, 02, 02)) self.investigator_1.member_answered(question, member_1, 1, self.batch) self.investigator_1.member_answered(question, member_2, 1, self.batch) data = [self.investigator_1.name, self.investigator_1.mobile_number] data.extend([loc.name for loc in self.investigator_1.location_hierarchy().values()]) response = Investigator.generate_completion_report(self.survey) self.assertNotIn(data, response) self.investigator_1.member_answered(question, member_3, 1, self.batch) response = Investigator.generate_completion_report(self.survey) self.assertIn(data, response)
def test_should_return_all_households_members(self): hhold = Household.objects.create(investigator=Investigator(), uid=0) household_head = HouseholdHead.objects.create(household=hhold, surname="Name", date_of_birth='1989-02-02') household_member1 = HouseholdMember.objects.create(household=hhold, surname="name", male=False, date_of_birth='1989-02-02') household_member2 = HouseholdMember.objects.create(household=hhold, surname="name1", male=False, date_of_birth='1989-02-02') all_members = hhold.all_members() self.assertTrue(household_head in all_members) self.assertTrue(household_member1 in all_members) self.assertTrue(household_member2 in all_members)
def send_message(self): investigator = Investigator(mobile_number=self.mobile_number) investigator.backend = Backend.objects.all()[0] send(self.text_message(), [investigator])
def test_should_return_data_when_generate_data_called(self): data = [self.investigator_1.name, self.investigator_1.mobile_number] data.extend([loc.name for loc in self.investigator_1.location_hierarchy().values()]) response = Investigator.generate_completion_report(self.survey) self.assertIn(data, response)
def compute_for_location(self, location): investigators = Investigator.lives_under_location(location) if self.numerator.is_multichoice(): return self.compute_multichoice_question_for_investigators(investigators) else: return self.compute_numerical_question_for_investigators(investigators)
def test_store(self): household = Household.objects.create(investigator=Investigator(), uid=0) self.failUnless(household.id) self.failUnless(household.created) self.failUnless(household.modified) self.assertEquals(0, household.uid)