Пример #1
0
    def test_should_calculate_attd_for_past_five_weeks(self):
        client = Client()
        client.login(username='******',password='******')
        create_attribute()
        self.p3_boys_enrolled_poll.start()
        self.fake_incoming('10', self.emis_reporter1)
        self.p3_boys_enrolled_poll.end()

        self.p3_boys_absent_poll.start()
        self.fake_incoming('6', self.emis_reporter1)
        self.fake_incoming('5', self.emis_reporter1)
        self.fake_incoming('7', self.emis_reporter1)
        self.fake_incoming('0', self.emis_reporter1)
        self.fake_incoming('4', self.emis_reporter1)
        self.p3_boys_absent_poll.end()
        responses = self.p3_boys_absent_poll.responses.all()
        self.set_weekly_date(responses)
        self.p3_girls_absent_poll.start()
        self.fake_incoming('5', self.emis_reporter1)
        self.fake_incoming('6', self.emis_reporter1)
        self.fake_incoming('4', self.emis_reporter1)
        self.fake_incoming('6', self.emis_reporter1)
        self.fake_incoming('4', self.emis_reporter1)
        self.p3_girls_absent_poll.end()
        responses = self.p3_boys_absent_poll.responses.all()
        self.set_weekly_date(responses)

        create_record_enrolled_deployed_questions_answered(model = EnrolledDeployedQuestionsAnswered)
        response = client.post('/edtrac/detail-attd/', {'from_date': getattr(settings, 'SCHOOL_TERM_START').strftime('%m/%d/%Y') , 'to_date': getattr(settings, 'SCHOOL_TERM_END').strftime('%m/%d/%Y') , 'indicator':'P3Pupils'})
        import ast
        time_data = ast.literal_eval(response.context['time_data'])
        self.assertTrue(set([60.0, 100.0, 30.0, 50.0, 40.0]) < set(time_data[0]['data']))
        self.assertEqual(76.0 , round(response.context['collective_result']['Kampala']['P3 Pupils']))
Пример #2
0
 def setUp(self):
     super(TestViolenceView, self).setUp()
     self.client = Client()
     self.client.login(username="******", password="******")
     self.add_group(
         [self.emisreporter1, self.emisreporter2, self.emisreporter3], Group.objects.create(name="Head Teachers")
     )
     create_attribute()
     self.script = Script.objects.create(
         slug="edtrac_headteacher_violence_monthly", name="Headteacher Violence Monthly Script", enabled=False
     )
     polls = ["edtrac_violence_girls", "edtrac_violence_boys", "edtrac_violence_reported", "edtrac_gem_abuse"]
     poll_questions = [
         "How many cases of violence against girls were recorded this month? Answer in figures e.g. 5",
         "How many cases of violence against boys were recorded this month? Answer in figures e.g. 4",
         "How many cases of violence were referred to the Police this month? Answer in figures e.g. 6",
         "How many violence cases were reported to you this month?",
     ]
     for poll, poll_question in zip(polls, poll_questions):
         self.create_poll(poll, self.admin_user, Poll.TYPE_NUMERIC, poll_question, "")
         self.script.steps.add(
             ScriptStep.objects.create(
                 script=self.script,
                 poll=self.violence_poll,
                 order=polls.index(poll),
                 rule=ScriptStep.WAIT_MOVEON,
                 start_offset=0,
                 giveup_offset=86400,
             )
         )
     schedule_script_now("Head Teachers", "edtrac_headteacher_violence_monthly")
Пример #3
0
    def test_should_ignore_attd_if_no_enrollment_found(self):
        client = Client()
        client.login(username='******',password='******')
        create_attribute()
        self.p3_boys_enrolled_poll.start()
        self.fake_incoming('10', self.emis_reporter1)
        self.fake_incoming('10', self.emis_reporter2)
        self.fake_incoming('10', self.emis_reporter3)
        self.fake_incoming('10', self.emis_reporter4)
        self.p3_boys_enrolled_poll.end()

        self.p3_boys_absent_poll.start()
        self.fake_incoming('12', self.emis_reporter1)
        self.fake_incoming('6', self.emis_reporter2)
        self.fake_incoming('8', self.emis_reporter3)
        self.fake_incoming('4', self.emis_reporter4)
        self.p3_boys_absent_poll.end()
        self.p3_girls_absent_poll.start()
        self.fake_incoming('3', self.emis_reporter1)
        self.fake_incoming('2', self.emis_reporter2)
        self.fake_incoming('6', self.emis_reporter3)
        self.fake_incoming('4', self.emis_reporter4)
        self.p3_girls_absent_poll.end()
        create_record_enrolled_deployed_questions_answered(model = EnrolledDeployedQuestionsAnswered)
        response = client.post('/edtrac/detail-attd/', {'from_date': getattr(settings, 'SCHOOL_TERM_START').strftime('%m/%d/%Y') , 'to_date': getattr(settings, 'SCHOOL_TERM_END').strftime('%m/%d/%Y') , 'indicator':'P3Pupils'})
        import ast
        time_data = ast.literal_eval(response.context['time_data'])
        self.assertIn(25.0, time_data[0]['data'])
Пример #4
0
 def test_should_return_data_for_given_location_only(self):
     create_attribute()
     locations = [self.kampala_district]
     self.p3_boys_enrolled_poll.start()
     self.fake_incoming('10', self.emis_reporter1)
     self.fake_incoming('10', self.emis_reporter2)
     self.fake_incoming('10', self.emis_reporter3) #gulu response
     result_absent, result_enrolled,school_percent = get_responses_over_depth(self.p3_boys_absent_poll.name,
                                                               self.p3_boys_enrolled_poll.name, locations, self.date_week)
     location_result = result_enrolled[0]
     self.assertFalse(self.gulu_district.name in location_result.values())
Пример #5
0
 def test_should_return_sum_over_districts(self):
     create_attribute()
     locations = [self.kampala_district, self.gulu_district]
     self.p3_boys_enrolled_poll.start()
     self.fake_incoming('10', self.emis_reporter1)
     self.fake_incoming('10', self.emis_reporter2)
     self.p3_boys_enrolled_poll.end()
     result_absent, result_enrolled,school_percent = get_responses_over_depth(self.p3_boys_absent_poll.name,
                                                               self.p3_boys_enrolled_poll.name, locations, self.date_week)
     kampala_result = result_enrolled[0]
     self.assertTrue(self.kampala_district.name in kampala_result.values())
     self.assertIn(20.0, kampala_result.values())
     self.assertEqual(0,school_percent)
Пример #6
0
 def test_should_return_proper_result_on_POST_request(self):
     client = Client()
     client.login(username='******',password='******')
     create_attribute()
     self.p3_boys_enrolled_poll.start()
     self.fake_incoming('10', self.emis_reporter1)
     self.fake_incoming('10', self.emis_reporter2)
     self.p3_boys_enrolled_poll.end()
     self.p3_boys_absent_poll.start()
     self.fake_incoming('5', self.emis_reporter1)
     self.fake_incoming('5', self.emis_reporter2)
     self.p3_boys_absent_poll.end()
     create_record_enrolled_deployed_questions_answered(model = EnrolledDeployedQuestionsAnswered)
     response = client.post('/edtrac/detail-attd/', {'from_date': getattr(settings, 'SCHOOL_TERM_START').strftime('%m/%d/%Y') , 'to_date': getattr(settings, 'SCHOOL_TERM_END').strftime('%m/%d/%Y') , 'indicator':'P3Boys'})
     kampala_result =  response.context['collective_result']['Kampala']
     self.assertEqual(94.0 , round(kampala_result['P3 Boys']))
Пример #7
0
 def setUp(self):
     self.attribute = create_attribute()
     user = User.objects.create(username="******")
     backend = Backend.objects.create()
     self.contact = EmisReporter.objects.create()
     self.poll = Poll.objects.create(name="foo", user=user, response_type=Poll.TYPE_NUMERIC)
     self.connection = Connection.objects.create(contact=self.contact, backend=backend)
Пример #8
0
    def setUp(self):
        self.attribute = create_attribute()
        user = User.objects.create(username="******")
        backend = Backend.objects.create()
        self.contact = EmisReporter.objects.create()
        self.poll = Poll.objects.create(name="foo", user=user, response_type=Poll.TYPE_NUMERIC)
        self.connection = Connection.objects.create(contact=self.contact, backend=backend)

        self.gulu = Location.objects.create(name="Gulu")
        self.kampala = Location.objects.create(name="Kampala")
Пример #9
0
 def setUp(self):
     super(TestViolenceView, self).setUp()
     self.client=Client()
     self.client.login(username='******', password='******')
     self.add_group([self.emisreporter1, self.emisreporter2, self.emisreporter3],
                    Group.objects.create(name='Head Teachers'))
     create_attribute()
     self.script = Script.objects.create(slug="edtrac_headteacher_violence_monthly",
                                         name="Headteacher Violence Monthly Script",
                                         enabled=False)
     polls = ["edtrac_violence_girls", "edtrac_violence_boys", "edtrac_violence_reported", "edtrac_gem_abuse"]
     poll_questions = ["How many cases of violence against girls were recorded this month? Answer in figures e.g. 5",
                       "How many cases of violence against boys were recorded this month? Answer in figures e.g. 4",
                       "How many cases of violence were referred to the Police this month? Answer in figures e.g. 6",
                       "How many violence cases were reported to you this month?"]
     for poll, poll_question in zip(polls, poll_questions):
         self.create_poll(poll, self.admin_user, Poll.TYPE_NUMERIC, poll_question, '')
         self.script.steps.add(
             ScriptStep.objects.create(script=self.script, poll=self.violence_poll, order=polls.index(poll),
                                       rule=ScriptStep.WAIT_MOVEON, start_offset=0, giveup_offset=86400, ))
     schedule_script_now('Head Teachers','edtrac_headteacher_violence_monthly')
Пример #10
0
    def setUp(self):
        country = create_location_type("country")
        uganda_fields = {
            "rght": 15274,
            "level": 0,
            "tree_id": 1,
            "lft": 1,
        }
        self.uganda = create_location("uganda", country, **uganda_fields)
        admin_group = create_group("Admins")
        self.smc_group = create_group("SMC")
        self.admin_user = create_user_with_group("John", admin_group,
                                                 self.uganda)

        district = create_location_type("district")
        kampala_fields = {
            "rght": 10901,
            "tree_parent": self.uganda,
            "level": 1,
            "tree_id": 1,
            "lft": 10686,
        }
        kampala_point = {
            "latitude": "0.3162800000",
            "longitude": "32.5821900000"
        }
        self.kampala_district = create_location("Kampala",
                                                district,
                                                point=kampala_point,
                                                **kampala_fields)
        self.kampala_school = create_school("St. Joseph's",
                                            self.kampala_district)
        self.kampala_school_lubaga = create_school("UMHS Lubaga",
                                                   self.kampala_district)
        self.head_teacher_group = create_group("Head Teachers")
        self.emis_reporter1 = create_emis_reporters("dummy1",
                                                    self.kampala_district,
                                                    self.kampala_school, 12345,
                                                    self.head_teacher_group)
        self.emis_reporter1.grade = 'P3'
        self.emis_reporter1.gender = 'M'
        self.emis_reporter1.save()
        self.emis_reporter2 = create_emis_reporters("dummy2",
                                                    self.kampala_district,
                                                    self.kampala_school, 12346,
                                                    self.head_teacher_group)

        self.emis_reporter2.grade = 'P3'
        self.emis_reporter2.gender = 'M'
        self.emis_reporter2.save()

        self.emis_reporter3 = create_emis_reporters("dummy1",
                                                    self.kampala_district,
                                                    self.kampala_school, 12347,
                                                    self.smc_group)
        self.emis_reporter3.gender = 'F'
        self.emis_reporter3.save()

        self.p3_boys_absent_poll = create_poll_with_reporters(
            "edtrac_boysp3_attendance",
            "How many P3 boys are at school today?", Poll.TYPE_NUMERIC,
            self.admin_user, [self.emis_reporter1, self.emis_reporter2])
        self.p3_girls_absent_poll = create_poll_with_reporters(
            "edtrac_girlsp3_attendance",
            "How many P3 girls are at school today?", Poll.TYPE_NUMERIC,
            self.admin_user, [self.emis_reporter1, self.emis_reporter2])

        self.p3_boys_enroll_poll = create_poll_with_reporters(
            "edtrac_boysp3_enrollment",
            "How many boys are enrolled in P3 this term?", Poll.TYPE_NUMERIC,
            self.admin_user, [self.emis_reporter1])
        self.p3_girls_enroll_poll = create_poll_with_reporters(
            "edtrac_girlsp3_enrollment",
            "How many girls are enrolled in P3 this term?", Poll.TYPE_NUMERIC,
            self.admin_user, [self.emis_reporter1])
        self.head_teacher_monitoring_poll = create_poll_with_reporters(
            "edtrac_head_teachers_attendance",
            "Has the head teacher been at school for at least 3 days? Answer YES or NO",
            Poll.TYPE_TEXT, self.admin_user, [self.emis_reporter3])
        self.teachers_weekly_script = Script.objects.create(
            name='Revised P3 Teachers Weekly Script',
            slug='edtrac_p3_teachers_weekly')

        self.p3_boys_attendance_step = ScriptStep.objects.create(
            script=self.teachers_weekly_script,
            poll=self.p3_boys_absent_poll,
            order=0,
            rule=ScriptStep.WAIT_MOVEON,
            start_offset=0,
            giveup_offset=2)
        self.teachers_weekly_script.steps.add(self.p3_boys_attendance_step)

        self.p3_girls_attendance_step = ScriptStep.objects.create(
            script=self.teachers_weekly_script,
            poll=self.p3_girls_absent_poll,
            order=1,
            rule=ScriptStep.WAIT_MOVEON,
            start_offset=0,
            giveup_offset=2)
        self.teachers_weekly_script.steps.add(self.p3_girls_attendance_step)

        self.head_teachers_termly_script = Script.objects.create(
            name='P3 Enrollment Headteacher Termly Script',
            slug='edtrac_p3_enrollment_headteacher_termly')
        self.head_teacher_weekly_script = Script.objects.create(
            name='Education monitoring smc weekly script',
            slug='edtrac_education_monitoring_smc_weekly_script')
        self.head_teachers_termly_script.steps.add(
            ScriptStep.objects.create(script=self.head_teachers_termly_script,
                                      poll=self.p3_boys_enroll_poll,
                                      order=0,
                                      rule=ScriptStep.WAIT_MOVEON,
                                      start_offset=0,
                                      giveup_offset=7200))

        self.head_teachers_termly_script.steps.add(
            ScriptStep.objects.create(script=self.head_teachers_termly_script,
                                      poll=self.p3_girls_enroll_poll,
                                      order=1,
                                      rule=ScriptStep.WAIT_MOVEON,
                                      start_offset=0,
                                      giveup_offset=7200))
        self.head_teacher_weekly_script.steps.add(
            ScriptStep.objects.create(script=self.head_teacher_weekly_script,
                                      poll=self.head_teacher_monitoring_poll,
                                      order=0,
                                      rule=ScriptStep.WAIT_MOVEON,
                                      start_offset=0,
                                      giveup_offset=7200))

        settings.SCHOOL_TERM_START = dateutils.increment(
            datetime.datetime.today(), weeks=-4)
        settings.SCHOOL_TERM_END = dateutils.increment(
            datetime.datetime.today(), weeks=8)
        self.term_range = [
            getattr(settings, 'SCHOOL_TERM_START'),
            getattr(settings, 'SCHOOL_TERM_END')
        ]

        create_attribute()
Пример #11
0
    def setUp(self):
        country = create_location_type("country")
        uganda_fields = {
            "rght": 15274,
            "level": 0,
            "tree_id": 1,
            "lft": 1,
        }
        self.uganda = create_location("uganda", country, **uganda_fields)
        admin_group = create_group("Admins")
        self.smc_group = create_group("SMC")
        self.admin_user = create_user_with_group("John", admin_group, self.uganda)

        district = create_location_type("district")
        kampala_fields = {
            "rght": 10901,
            "tree_parent": self.uganda,
            "level": 1,
            "tree_id": 1,
            "lft": 10686,
        }
        kampala_point = {
            "latitude": "0.3162800000",
            "longitude": "32.5821900000"
        }
        self.kampala_district = create_location("Kampala", district, point=kampala_point, **kampala_fields)
        self.kampala_school = create_school("St. Joseph's", self.kampala_district)
        self.kampala_school_lubaga = create_school("UMHS Lubaga", self.kampala_district)
        self.head_teacher_group = create_group("Head Teachers")
        self.emis_reporter1 = create_emis_reporters("dummy1", self.kampala_district, self.kampala_school, 12345,
                                                    self.head_teacher_group)
        self.emis_reporter1.grade = 'P3'
        self.emis_reporter1.gender = 'M'
        self.emis_reporter1.save()
        self.emis_reporter2 = create_emis_reporters("dummy2", self.kampala_district, self.kampala_school, 12346,
                                                    self.head_teacher_group)

        self.emis_reporter2.grade = 'P3'
        self.emis_reporter2.gender = 'M'
        self.emis_reporter2.save()

        self.emis_reporter3 = create_emis_reporters("dummy1", self.kampala_district, self.kampala_school, 12347,
                                                    self.smc_group)
        self.emis_reporter3.gender = 'F'
        self.emis_reporter3.save()

        self.p3_boys_absent_poll = create_poll_with_reporters("edtrac_boysp3_attendance",
                                                              "How many P3 boys are at school today?",
                                                              Poll.TYPE_NUMERIC, self.admin_user,
                                                              [self.emis_reporter1, self.emis_reporter2])
        self.p3_girls_absent_poll = create_poll_with_reporters("edtrac_girlsp3_attendance",
                                                               "How many P3 girls are at school today?",
                                                               Poll.TYPE_NUMERIC, self.admin_user,
                                                               [self.emis_reporter1, self.emis_reporter2])

        self.p3_boys_enroll_poll = create_poll_with_reporters("edtrac_boysp3_enrollment",
                                                              "How many boys are enrolled in P3 this term?",
                                                              Poll.TYPE_NUMERIC, self.admin_user,
                                                              [self.emis_reporter1])
        self.p3_girls_enroll_poll = create_poll_with_reporters("edtrac_girlsp3_enrollment",
                                                               "How many girls are enrolled in P3 this term?",
                                                               Poll.TYPE_NUMERIC, self.admin_user,
                                                               [self.emis_reporter1])
        self.head_teacher_monitoring_poll = create_poll_with_reporters("edtrac_head_teachers_attendance",
                                                                       "Has the head teacher been at school for at least 3 days? Answer YES or NO",
                                                                       Poll.TYPE_TEXT, self.admin_user,
                                                                       [self.emis_reporter3])
        self.teachers_weekly_script = Script.objects.create(name='Revised P3 Teachers Weekly Script',
                                                            slug='edtrac_p3_teachers_weekly')

        self.p3_boys_attendance_step = ScriptStep.objects.create(script=self.teachers_weekly_script,
                                                                 poll=self.p3_boys_absent_poll,
                                                                 order=0, rule=ScriptStep.WAIT_MOVEON, start_offset=0,
                                                                 giveup_offset=2)
        self.teachers_weekly_script.steps.add(self.p3_boys_attendance_step)

        self.p3_girls_attendance_step = ScriptStep.objects.create(script=self.teachers_weekly_script,
                                                                  poll=self.p3_girls_absent_poll,
                                                                  order=1, rule=ScriptStep.WAIT_MOVEON, start_offset=0,
                                                                  giveup_offset=2)
        self.teachers_weekly_script.steps.add(self.p3_girls_attendance_step)

        self.head_teachers_termly_script = Script.objects.create(name='P3 Enrollment Headteacher Termly Script',
                                                                 slug='edtrac_p3_enrollment_headteacher_termly')
        self.head_teacher_weekly_script = Script.objects.create(name='Education monitoring smc weekly script',
                                                                slug='edtrac_education_monitoring_smc_weekly_script')
        self.head_teachers_termly_script.steps.add(
            ScriptStep.objects.create(script=self.head_teachers_termly_script, poll=self.p3_boys_enroll_poll, order=0,
                                      rule=ScriptStep.WAIT_MOVEON, start_offset=0, giveup_offset=7200))

        self.head_teachers_termly_script.steps.add(
            ScriptStep.objects.create(script=self.head_teachers_termly_script, poll=self.p3_girls_enroll_poll, order=1,
                                      rule=ScriptStep.WAIT_MOVEON, start_offset=0, giveup_offset=7200))
        self.head_teacher_weekly_script.steps.add(
            ScriptStep.objects.create(script=self.head_teacher_weekly_script, poll=self.head_teacher_monitoring_poll,
                                      order=0,
                                      rule=ScriptStep.WAIT_MOVEON, start_offset=0, giveup_offset=7200)
        )

        settings.SCHOOL_TERM_START = dateutils.increment(datetime.datetime.today(), weeks=-4)
        settings.SCHOOL_TERM_END = dateutils.increment(datetime.datetime.today(), weeks=8)
        self.term_range = [getattr(settings, 'SCHOOL_TERM_START'), getattr(settings, 'SCHOOL_TERM_END')]

        create_attribute()