def test_returns_minus_one_when_no_batch_is_open_in_the_location(self):
        kisoro = Location.objects.create(name='Kisoro', type=self.district)

        survey = Survey.objects.create(name="open survey", description="open survey", has_sampling=True)
        batch = Batch.objects.create(order=1, name='B', survey=survey)
        batch.open_for_location(self.abim)

        with patch.object(BatchLocationCompletionRates, 'percent_completed_households', return_value=10):
            completion = BatchSurveyCompletionRates(self.district)
            self.assertEqual(-1, completion.get_completion_formatted_for_json(survey)[kisoro.name])
            self.assertNotEqual(0, completion.get_completion_formatted_for_json(survey)[self.abim.name])
Exemplo n.º 2
0
    def test_returns_minus_one_when_no_batch_is_open_in_the_location(self):
        kisoro = Location.objects.create(name='Kisoro', type=self.district)

        survey = Survey.objects.create(name="open survey",
                                       description="open survey",
                                       has_sampling=True)
        batch = Batch.objects.create(order=1, name='B', survey=survey)
        batch.open_for_location(self.abim)

        with patch.object(BatchLocationCompletionRates,
                          'percent_completed_households',
                          return_value=10):
            completion = BatchSurveyCompletionRates(self.district)
            self.assertEqual(
                -1,
                completion.get_completion_formatted_for_json(survey)[
                    kisoro.name])
            self.assertNotEqual(
                0,
                completion.get_completion_formatted_for_json(survey)[
                    self.abim.name])
    def test_knows_completion_rates_for_location_type(self):

        household_1_member = HouseholdMember.objects.create(household=self.household_1,
                                                            date_of_birth=date(1980, 05, 01))
        household_2_member = HouseholdMember.objects.create(household=self.household_2,
                                                            date_of_birth=date(1980, 05, 01))
        household_3_member = HouseholdMember.objects.create(household=self.household_3,
                                                            date_of_birth=date(1980, 05, 01))
        household_4_member = HouseholdMember.objects.create(household=self.household_4, date_of_birth=date(1980, 05, 01))

        HouseholdMemberBatchCompletion.objects.create(household=self.household_1, householdmember=household_1_member,
                                                      batch=self.batch, investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(household=self.household_2, householdmember=household_2_member,
                                                      batch=self.batch, investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(household=self.household_3, householdmember=household_3_member,
                                                      batch=self.batch, investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(household=self.household_3, householdmember=household_4_member,
                                                      batch=self.batch, investigator=self.investigator_1)

        self.household_5 = Household.objects.create(investigator=self.investigator_2, ea=self.investigator_2.ea,
                                                    survey=self.survey)
        self.household_6 = Household.objects.create(investigator=self.investigator_2, ea=self.investigator_2.ea,
                                                    survey=self.survey)
        self.household_7 = Household.objects.create(investigator=self.investigator_2, ea=self.investigator_2.ea,
                                                    survey=self.survey)
        self.household_8 = Household.objects.create(investigator=self.investigator_2, ea=self.investigator_2.ea,
                                                    survey=self.survey)

        household_5_member = HouseholdMember.objects.create(household=self.household_5,
                                                            date_of_birth=date(1980, 05, 01))
        household_6_member = HouseholdMember.objects.create(household=self.household_6,
                                                            date_of_birth=date(1980, 05, 01))

        HouseholdMember.objects.create(household=self.household_7, date_of_birth=date(1980, 05, 01))
        HouseholdMember.objects.create(household=self.household_8, date_of_birth=date(1980, 05, 01))

        HouseholdMemberBatchCompletion.objects.create(household=self.household_1, householdmember=household_5_member,
                                                      batch=self.batch, investigator=self.investigator_2)
        HouseholdMemberBatchCompletion.objects.create(household=self.household_2, householdmember=household_6_member,
                                                      batch=self.batch, investigator=self.investigator_2)

        district_level_completion = BatchSurveyCompletionRates(self.district)
        expected_completion = {self.zombo.name: 25.0, self.abim.name: 50.0}
        self.assertEqual(district_level_completion.get_completion_formatted_for_json(self.survey), expected_completion)
Exemplo n.º 4
0
    def test_knows_completion_rates_for_location_type(self):

        household_1_member = HouseholdMember.objects.create(
            household=self.household_1, date_of_birth=date(1980, 05, 01))
        household_2_member = HouseholdMember.objects.create(
            household=self.household_2, date_of_birth=date(1980, 05, 01))
        household_3_member = HouseholdMember.objects.create(
            household=self.household_3, date_of_birth=date(1980, 05, 01))
        household_4_member = HouseholdMember.objects.create(
            household=self.household_4, date_of_birth=date(1980, 05, 01))

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_1,
            householdmember=household_1_member,
            batch=self.batch,
            investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_2,
            householdmember=household_2_member,
            batch=self.batch,
            investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_3,
            householdmember=household_3_member,
            batch=self.batch,
            investigator=self.investigator_1)

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_3,
            householdmember=household_4_member,
            batch=self.batch,
            investigator=self.investigator_1)

        self.household_5 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)
        self.household_6 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)
        self.household_7 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)
        self.household_8 = Household.objects.create(
            investigator=self.investigator_2,
            ea=self.investigator_2.ea,
            survey=self.survey)

        household_5_member = HouseholdMember.objects.create(
            household=self.household_5, date_of_birth=date(1980, 05, 01))
        household_6_member = HouseholdMember.objects.create(
            household=self.household_6, date_of_birth=date(1980, 05, 01))

        HouseholdMember.objects.create(household=self.household_7,
                                       date_of_birth=date(1980, 05, 01))
        HouseholdMember.objects.create(household=self.household_8,
                                       date_of_birth=date(1980, 05, 01))

        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_1,
            householdmember=household_5_member,
            batch=self.batch,
            investigator=self.investigator_2)
        HouseholdMemberBatchCompletion.objects.create(
            household=self.household_2,
            householdmember=household_6_member,
            batch=self.batch,
            investigator=self.investigator_2)

        district_level_completion = BatchSurveyCompletionRates(self.district)
        expected_completion = {self.zombo.name: 25.0, self.abim.name: 50.0}
        self.assertEqual(
            district_level_completion.get_completion_formatted_for_json(
                self.survey), expected_completion)