def test_daily_spray_effectiveness(self, mocked_start_flow): """Test daily_spray_effectiveness calls rapidpro""" data_setup() load_spray_data() daily_spray_effectiveness("flow_uuid", '2018-09-20') self.assertTrue(mocked_start_flow.called) self.assertEqual(mocked_start_flow.call_count, 1)
def test_sprayable(self): """Test sprayable.""" data_setup() load_spray_data() self.assertEqual(Household.objects.filter(sprayable=False).count(), 4) akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.not_sprayable, 4)
def test_last_decision_date(self): """Test last_decision_date""" data_setup() load_spray_data() decision_visit = create_decision_visit(DECISION_VISIT_DATA) self.assertIsInstance(decision_visit, Decision) akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.last_visit, datetime.date(2018, 9, 20)) self.assertEqual(akros_2.last_decision_date, "2018-09-25")
def test_se_serializer(self): """Test SprayEffectivenessSerializer""" data_setup() load_spray_data() locations = Location.objects.filter(code="2") serializer = SprayEffectivenessSerializer(locations, many=True) data = serializer.data[0] self.assertEqual(data["spray_effectiveness"], 62) self.assertEqual(data["district"], "1") self.assertEqual(data["spray_area"], "Akros_2")
def test_spray_areas_to_mopup(self): """Test calculating number of spray_areas that need mopup.""" data_setup() self.assertEqual( Location.objects.get(name="Lusaka", level="district").spray_areas_to_mopup, 0) load_spray_data() self.assertEqual( Location.objects.get(name="Lusaka", level="district").spray_areas_to_mopup, 1)
def test_structures_to_mopup(self): """Test calculating number of structures that need mopup.""" data_setup() akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.structures_to_mopup, 12) load_spray_data() akros_2.refresh_from_db() akros_2 = Location.objects.get(name="Akros_2", level="ta") # 90th percentile is 8 , sprayed is 5, difference is 3 self.assertEqual(akros_2.structures_to_mopup, 3) lusaka = Location.objects.get(name="Lusaka", level="district") self.assertEqual(lusaka.structures_to_mopup, 3)
def test_health_facility_mopup_view(self): """Test HealthFacilityMopUpView""" data_setup() load_spray_data() health_facility = Location.objects.filter(level="RHC").first() spray_area = health_facility.get_children().filter( name='Akros_2').first() factory = RequestFactory() request = factory.get("/mopup-up/{}".format(health_facility.parent_id)) view = HealthFacilityMopUpView.as_view() response = view(request, district=health_facility.parent_id) self.assertDictEqual( { 'structures_on_ground': 9, 'visited_sprayed': 5, 'structures_to_mopup': 3, 'mopup_days_needed': 0.022222222222222223 }, response.context_data['totals'] ) self.assertContains(response, health_facility.name, 1, 200) self.assertContains(response, spray_area.name, 1, 200) self.assertEqual( reverse("mop-up", kwargs={"district": health_facility.parent_id}), "/mop-up/{}".format(health_facility.parent_id), ) # test targeted spray_area.target = False spray_area.save() view = HealthFacilityMopUpView.as_view() response = view(request, district=health_facility.parent_id) self.assertContains(response, health_facility.name, 0, 200) self.assertContains(response, spray_area.name, 0, 200) self.assertDictEqual({ 'structures_on_ground': 0, 'visited_sprayed': 0, 'structures_to_mopup': 0, 'mopup_days_needed': 0 }, response.context_data['totals'])
def test_mopup_days_needed(self): """Test return number of mopup days needed.""" data_setup() with self.settings( MOPUP_DAYS_DENOMINATOR=5, MSPRAY_MOPUP_LOWER_BOUND=0.2): akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.mopup_days_needed, 2.6) # lusaka has just these two areas inside lusaka = Location.objects.get(name="Lusaka", level="district") self.assertEqual(lusaka.mopup_days_needed, 0) # load some spray data load_spray_data() akros_2.refresh_from_db() lusaka.refresh_from_db() akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.mopup_days_needed, 0.2) lusaka = Location.objects.get(name="Lusaka", level="district") self.assertEqual(lusaka.mopup_days_needed, 0.2)
def test_visited_found(self): """Test found""" data_setup() load_spray_data() akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.visited_found, 8)
def test_structures_on_ground(self): """Test structures_on_ground""" data_setup() load_spray_data() akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.structures_on_ground, 9)
def test_visited_sprayed(self): """Test return number of structures visited that were sprayed.""" data_setup() load_spray_data() akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.visited_sprayed, 5)
def test_last_visit(self): """Test last_visit""" data_setup() load_spray_data() akros_2 = Location.objects.get(name="Akros_2", level="ta") self.assertEqual(akros_2.last_visit, datetime.date(2018, 9, 20))