def test_should_return_10_given_reporter_responds_10_to_boys_enrollment_poll(self):
     schedule_script_now(grp=self.head_teacher_group.name, slug = self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10", self.emis_reporter1)
     enrolled_boys = get_enrolled_pupils(self.emis_reporter1.connection_set.all()[0], self.p6_boys_enroll_poll.name,
         settings.SCHOOL_TERM_START, settings.SCHOOL_TERM_END)
     self.assertEqual(10, enrolled_boys)
Exemplo n.º 2
0
    def test_gendered_text_responses(self):
        params = {
            "description":
            "A response value for a Poll with expected text responses",
            "datatype": "text",
            "enum_group": None,
            "required": False,
            "type": None,
            "slug": "poll_text_value",
            "name": "Text"
        }
        Attribute.objects.get_or_create(**params)

        schedule_script_now(self.smc_group.name,
                            slug=self.head_teacher_weekly_script.slug)
        check_progress(self.head_teacher_weekly_script)
        fake_incoming("yes", self.emis_reporter3)

        male_yes_result = gendered_text_responses(self.term_range,
                                                  [self.kampala_district],
                                                  ['Yes', 'YES', 'yes'], 'M')
        male_no_result = gendered_text_responses(self.term_range,
                                                 [self.kampala_district],
                                                 ['No', 'NO', 'no'], 'M')
        female_yes_result = gendered_text_responses(self.term_range,
                                                    [self.kampala_district],
                                                    ['Yes', 'YES', 'yes'], 'F')
        female_no_result = gendered_text_responses(self.term_range,
                                                   [self.kampala_district],
                                                   ['No', 'NO', 'no'], 'F')

        self.assertEqual(1, male_yes_result)
        self.assertEqual(0, male_no_result)
        self.assertEqual(0, female_yes_result)
        self.assertEqual(0, female_no_result)
Exemplo n.º 3
0
 def test_should_return_location_numeric_data_given_a_poll_and_time_range(self):
     schedule_script_now(self.head_teacher_group.name, slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("20 boys", self.emis_reporter1)
     fake_incoming("10 boys", self.emis_reporter2)
     result = get_numeric_data_for_location([self.p3_boys_absent_poll], [self.kampala_district], self.term_range)
     self.assertEqual(30, result[self.kampala_district.id])
Exemplo n.º 4
0
 def test_messages_are_handled_in_education_app(self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     with patch('script.app.App.handle') as mock_method:
         fake_incoming("dummy response", self.emis_reporter1)
         assert not mock_method.called
Exemplo n.º 5
0
    def test_get_aggregated_report_data_single_indicator(self):
        schedule_script_now(self.head_teacher_group.name,
                            slug=self.head_teachers_termly_script.slug)
        check_progress(self.head_teachers_termly_script)
        fake_incoming("10 boys", self.emis_reporter1)
        check_progress(self.head_teachers_termly_script)
        fake_incoming("5 girls", self.emis_reporter1)
        schedule_script_now(self.head_teacher_group.name,
                            slug=self.teachers_weekly_script.slug)

        check_progress(self.teachers_weekly_script)
        fake_incoming("8 boys", self.emis_reporter1)
        check_progress(self.teachers_weekly_script)
        fake_incoming("1 girls", self.emis_reporter1)

        config_list = get_polls_for_keyword('P3Boys')
        collective_result, chart_results_model, school_percent,tooltip = \
            get_aggregated_report_data_single_indicator([self.kampala_district], [self.term_range], config_list)

        self.assertEqual(20.0, collective_result['P3 Boys'][0].values()[0])

        config_list = get_polls_for_keyword('P3Girls')
        collective_result, chart_results_model, school_percent, tooltip = get_aggregated_report_data_single_indicator(
            [self.kampala_district], [self.term_range], config_list)

        self.assertEqual(80.0, collective_result['P3 Girls'][0].values()[0])
Exemplo n.º 6
0
 def test_should_send_2_invalid_alerts_by_script_completion(self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("Invalid", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     fake_incoming("Invalid", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     alert = 'The answer you have provided is not in the correct format. Use figures like 3 to answer the question'
     messages = Message.objects.filter(
         direction='O',
         text=alert,
         connection=self.emis_reporter1.connection_set.all()[0])
     self.assertEqual(2, messages.count())
     expected = 'Thankyou p3 Teacher, Attendance for boys have been improved by 40percent Attendance for girls have been improved by 40percent'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(
         direction='O',
         connection=self.emis_reporter1.connection_set.all()
         [0]).values_list('text', flat=True))  #pausing feedback
Exemplo n.º 7
0
 def test_should_send_alert_messages_on_invalid_and_partial_responses(self):
     # 5 outgoing messages (1st) step 0 poll, (2nd) error msg alert (3rd) resend error poll (4th) step 1 msg (5th) Script completion alert
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("Invalid", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     expected = 'The answer you have provided is not in the correct format. Use figures like 3 to answer the question'
     self.assertTrue(expected in Message.objects.filter(
         direction='O',
         connection=self.emis_reporter1.connection_set.all()
         [0]).values_list('text', flat=True))
     time.sleep(3)
     check_progress(self.teachers_weekly_script)
     fake_incoming("3", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     # self.assertEqual(5, Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     self.assertEqual(
         4,
         Message.objects.filter(
             direction='O',
             connection=self.emis_reporter1.connection_set.all()
             [0]).count())  #pausing feedback
     expected = 'Thank you for participating. Remember to answer all your questions next Thursday.'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(
         direction='O',
         connection=self.emis_reporter1.connection_set.all()
         [0]).values_list('text', flat=True))  #pausing feedback
 def test_messages_are_handled_in_education_app(self):
     schedule_script_now(grp=self.head_teacher_group.name,slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     with patch('script.app.App.handle') as mock_method:
         fake_incoming("dummy response"
             ,self.emis_reporter1)
         assert not mock_method.called
Exemplo n.º 9
0
    def test_gendered_text_responses(self):
        params = {
            "description": "A response value for a Poll with expected text responses",
            "datatype": "text",
            "enum_group": None,
            "required": False,
            "type": None,
            "slug": "poll_text_value",
            "name": "Text"
        }
        Attribute.objects.get_or_create(**params)

        schedule_script_now(self.smc_group.name, slug=self.head_teacher_weekly_script.slug)
        check_progress(self.head_teacher_weekly_script)
        fake_incoming("yes", self.emis_reporter3)

        male_yes_result = gendered_text_responses(self.term_range, [self.kampala_district], ['Yes', 'YES', 'yes'], 'M')
        male_no_result = gendered_text_responses(self.term_range, [self.kampala_district], ['No', 'NO', 'no'], 'M')
        female_yes_result = gendered_text_responses(self.term_range, [self.kampala_district], ['Yes', 'YES', 'yes'], 'F')
        female_no_result = gendered_text_responses(self.term_range, [self.kampala_district],  ['No', 'NO', 'no'], 'F')

        self.assertEqual(1, male_yes_result)
        self.assertEqual(0, male_no_result)
        self.assertEqual(0, female_yes_result)
        self.assertEqual(0, female_no_result)
 def test_should_send_message_if_invalid_response_received(self):
     schedule_script_now(grp=self.head_teacher_group.name,slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("dummy response",self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     expected = 'The answer you have provided is not in the correct format. Use figures like 3 to answer the question'
     self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
Exemplo n.º 11
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")
Exemplo n.º 12
0
 def test_should_reject_numeric_data_thats_implausibly_large(self):
     schedule_script_now(self.head_teacher_group.name, slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("20 boys", self.emis_reporter1)
     fake_incoming("5001 boys", self.emis_reporter2)
     result = get_numeric_data([self.p3_boys_absent_poll], [self.kampala_district], self.term_range)
     self.assertEqual(20, result)
Exemplo n.º 13
0
 def test_should_return_get_numeric_data_by_school(self):
     schedule_script_now(self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("20 boys", self.emis_reporter1)
     school_results = get_numeric_data_by_school([self.p3_boys_absent_poll],
                                                 [self.kampala_school],
                                                 self.term_range)
     self.assertEqual(20, sum(school_results))
Exemplo n.º 14
0
 def test_should_return_get_numeric_data_all_schools_for_locations(self):
     schedule_script_now(self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("20 boys", self.emis_reporter1)
     school_results = get_numeric_data_all_schools_for_locations(
         [self.p3_boys_absent_poll], [self.kampala_district],
         self.term_range)
     self.assertEqual({self.kampala_school.id: 20}, school_results)
Exemplo n.º 15
0
 def test_should_check_message_of_error_messages(self):
     schedule_script_now(grp=self.smc_group.name,slug='edtrac_head_teachers_weekly')
     check_progress(self.head_teachers_script)
     self.fake_incoming("2", self.emis_reporter6)
     self.fake_incoming("No one in school today", self.emis_reporter7) #error msg
     request = self.factory.get('/customer/messages/?error_msgs=True')
     request.user = self.admin_user
     resp = messages(request)
     self.assertEqual(1 ,resp.count())
Exemplo n.º 16
0
 def test_should_ignore_short_messages(self):
     schedule_script_now(grp=self.smc_group.name, slug='edtrac_head_teachers_weekly')
     check_progress(self.head_teachers_script)
     self.fake_incoming("No one in school today", self.emis_reporter9)
     self.fake_incoming("No one in school to", self.emis_reporter8)
     request = self.factory.get('/edtrac/error_messages/')
     request.user = self.admin_user
     list_of_error_messages = error_messages(request)
     self.assertEquals(1, list_of_error_messages.count())
Exemplo n.º 17
0
 def test_should_reject_numeric_data_thats_implausibly_large(self):
     schedule_script_now(self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("20 boys", self.emis_reporter1)
     fake_incoming("5001 boys", self.emis_reporter2)
     result = get_numeric_data([self.p3_boys_absent_poll],
                               [self.kampala_district], self.term_range)
     self.assertEqual(20, result)
Exemplo n.º 18
0
 def test_should_return_numeric_data_given_a_poll_location_and_time_range(
         self):
     schedule_script_now(self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("20 boys", self.emis_reporter1)
     fake_incoming("10 boys", self.emis_reporter2)
     result = get_numeric_data([self.p3_boys_absent_poll],
                               [self.kampala_district], self.term_range)
     self.assertEqual(30, result)
 def test_should_check_increment_in_outgoing_msg_count_on_all_responses_received(self):
     schedule_script_now(grp=self.head_teacher_group.name,slug = self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("4",self.emis_reporter1)#response to p3 boys poll
     check_progress(self.teachers_weekly_script)
     self.assertEqual(2,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     fake_incoming("3",self.emis_reporter1)#response to p3 girls poll
     check_progress(self.teachers_weekly_script)
     # self.assertEqual(3,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     self.assertEqual(2,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())#pausing feedbacks
 def test_should_return_0_given_no_reporter_responds_to_boys_enrollment_poll(
         self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     enrolled_boys = get_enrolled_pupils(
         self.emis_reporter1.connection_set.all()[0],
         self.p6_boys_enroll_poll.name, settings.SCHOOL_TERM_START,
         settings.SCHOOL_TERM_END)
     self.assertEqual(0, enrolled_boys)
 def test_should_not_send_absenteeism_calculation_if_partial_responses_sent(self):
     schedule_script_now(grp=self.head_teacher_group.name,slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("3",self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     time.sleep(3)
     check_progress(self.teachers_weekly_script)
     expected = 'Thankyou p3 Teacher, Attendance for boys have been improved by 0percent" \
                      "Attendance for girls have been improved by 0percent'
     self.assertFalse(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
Exemplo n.º 22
0
 def test_should_return_none_if_all_messages_are_valid(self):
     schedule_script_now(grp=self.smc_group.name,slug='edtrac_head_teachers_weekly')
     check_progress(self.head_teachers_script)
     self.fake_incoming("2", self.emis_reporter6)
     self.fake_incoming("3", self.emis_reporter7)
     self.fake_incoming("2", self.emis_reporter8)
     request = self.factory.get('/customer/messages/?error_msgs=True')
     request.user = self.admin_user
     resp = messages(request)
     self.assertEqual(0,resp.count())
 def test_should_send_feedbacks_to_smc(self):
     schedule_script_now(grp= self.smc_group.name, slug=self.smc_weekly_script.slug)
     check_progress(self.smc_weekly_script)
     fake_incoming("yes", self.emis_reporter3)
     check_progress(self.smc_weekly_script)
     # self.assertEqual(2,Message.objects.filter(direction='O',connection=self.emis_reporter3.connection_set.all()[0]).count())
     self.assertEqual(1,Message.objects.filter(direction='O',connection=self.emis_reporter3.connection_set.all()[0]).count())#paisong feedback
     expected='Thank you for your report. Please continue to visit your school and report on what is happening.'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter3.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(direction='O',connection=self.emis_reporter3.connection_set.all()[0]).values_list('text',flat=True))#pausing feedback
 def test_should_resend_poll_question_on_invalid_responses(self):
     schedule_script_now(grp=self.head_teacher_group.name,slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("invalid response",self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     self.assertEqual(3,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     outgoing_messages = list(Message.objects.filter(direction='O',
                                               connection=self.emis_reporter1.connection_set.all()[0]).values_list(
         'text', flat=True))
     self.assertEqual(2,outgoing_messages.count(self.p3_boys_absent_poll.question))
 def test_should_return_10_boys_and_0_girls_given_reporter_responds_10boys_but_no_girls_to_enrollment_poll(self):
     schedule_script_now(grp = self.head_teacher_group.name, slug = self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     time.sleep(2)
     check_progress(self.head_teachers_termly_script)
     boys, girls = get_enrolled_boys_and_girls(self.emis_reporter1.connection_set.all()[0],
         self.p3_boys_enroll_poll.name, self.p3_girls_enroll_poll.name)
     self.assertEqual(10, boys)
     self.assertEqual(0, girls)
Exemplo n.º 26
0
 def test_should_convert_error_messages_to_json(self):
     schedule_script_now(grp=self.smc_group.name, slug='edtrac_head_teachers_weekly')
     check_progress(self.head_teachers_script)
     self.fake_incoming("NO one in school today", self.emis_reporter7)
     self.fake_incoming("NO one in school today", self.emis_reporter8)
     request = self.factory.get('/edtrac/error_messages/')
     request.user = self.admin_user
     response = error_messages_as_json(request)
     error_messages = Message.objects.filter(direction="I").order_by('-date')
     error_messages_json = serialize("json", error_messages)
     self.assertEqual(response.content, error_messages_json)
Exemplo n.º 27
0
    def test_aggregated_report_has_school_id(self):
        schedule_script_now(self.head_teacher_group.name, slug=self.head_teachers_termly_script.slug)
        check_progress(self.head_teachers_termly_script)
        fake_incoming("10 boys", self.emis_reporter1)

        config_list = get_polls_for_keyword('all')

        collective_result, chart_results_model, school_percent,tooltip = \
            get_aggregated_report_for_district([self.kampala_district], [self.term_range], config_list)

        self.assertEqual(self.kampala_school_lubaga.id, collective_result['UMHS Lubaga']['id'])
Exemplo n.º 28
0
 def test_should_send_message_if_number_too_large(self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("5001 boys", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     expected = 'The answer you have provided is not in the correct format. Use figures like 3 to answer the question'
     self.assertTrue(expected in Message.objects.filter(
         direction='O',
         connection=self.emis_reporter1.connection_set.all()
         [0]).values_list('text', flat=True))
 def test_should_send_alert_messages_on_partial_responses(self):
     schedule_script_now(grp=self.head_teacher_group.name,slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("3",self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     time.sleep(3)
     check_progress(self.teachers_weekly_script)
     # self.assertEqual(3,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     self.assertEqual(2,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())#pausing feedback
     expected = 'Thank you for participating. Remember to answer all your questions next Thursday.'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))#pausing feedback
 def test_should_return_4_given_reporter_responds_4_to_girls_enrollment_poll(self):
     self.head_teachers_termly_script.steps.all().delete()
     self.head_teachers_termly_script.steps.add(
         ScriptStep.objects.create(script=self.head_teachers_termly_script, poll=self.p6_girls_enroll_poll, order=0,
         rule=ScriptStep.WAIT_MOVEON, start_offset=0, giveup_offset=7200))
     schedule_script_now(grp = self.head_teacher_group.name, slug = self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     enrolled_girls = get_enrolled_pupils(self.emis_reporter1.connection_set.all()[0],
         self.p6_girls_enroll_poll.name, settings.SCHOOL_TERM_START, settings.SCHOOL_TERM_END)
     self.assertEqual(4, enrolled_girls)
Exemplo n.º 31
0
 def test_should_give_head_teachers_absenteeism_percent(self):
     schedule_script_now(grp=self.smc_group.name,slug='edtrac_smc_weekly')
     check_progress(self.head_teachers_script)
     locations = [self.kampala_district]
     # self.head_teachers_poll.start()
     self.fake_incoming('no', self.emis_reporter5)
     self.fake_incoming('yes', self.emis_reporter6)
     config = get_polls_for_keyword('MaleHeadTeachers')
     result_by_location, result_by_time,school_percent = get_head_teachers_absent_over_time(locations,config[0], self.date_week)
     self.assertEqual(50, result_by_location.get('Kampala'))
     self.assertIn(50, result_by_time)
     self.assertEqual(25,school_percent) #n four weeks only once replies were sent
Exemplo n.º 32
0
    def test_aggregated_report_has_school_id(self):
        schedule_script_now(self.head_teacher_group.name,
                            slug=self.head_teachers_termly_script.slug)
        check_progress(self.head_teachers_termly_script)
        fake_incoming("10 boys", self.emis_reporter1)

        config_list = get_polls_for_keyword('all')

        collective_result, chart_results_model, school_percent,tooltip = \
            get_aggregated_report_for_district([self.kampala_district], [self.term_range], config_list)

        self.assertEqual(self.kampala_school_lubaga.id,
                         collective_result['UMHS Lubaga']['id'])
Exemplo n.º 33
0
 def test_should_return_top_5_error_messages_given_6_incoming_error_messages(self):
     schedule_script_now(grp=self.smc_group.name, slug='edtrac_head_teachers_weekly')
     check_progress(self.head_teachers_script)
     self.fake_incoming("No one in school today", self.emis_reporter7)
     self.fake_incoming("No one in school today", self.emis_reporter8)
     self.fake_incoming("No one in school today", self.emis_reporter6)
     self.fake_incoming("No one in school today", self.emis_reporter6)
     self.fake_incoming("No one in school today", self.emis_reporter6)
     self.fake_incoming("No one in school today", self.emis_reporter6)
     request = self.factory.get('/edtrac/error_messages/')
     request.user = self.admin_user
     response = error_messages(request)
     self.assertEquals(5, response.count())
Exemplo n.º 34
0
 def test_should_return_10_boys_and_0_girls_given_reporter_responds_10boys_but_no_girls_to_enrollment_poll(
         self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     time.sleep(2)
     check_progress(self.head_teachers_termly_script)
     boys, girls = get_enrolled_boys_and_girls(
         self.emis_reporter1.connection_set.all()[0],
         self.p3_boys_enroll_poll.name, self.p3_girls_enroll_poll.name)
     self.assertEqual(10, boys)
     self.assertEqual(0, girls)
 def test_should_check_message_string_for_teachers(self):
     schedule_script_now(grp= self.head_teacher_group.name, slug=self.head_teachers_weekly_script.slug)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("9", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     expected ='Thankyou, Attendance for male teacher have been improved by 40percent Attendance for female teachers have been improved by 40percent'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))#pausing feedbacks
 def test_should_give_attendance_difference_as_0_if_error_message_received(self):
     schedule_script_now(grp=self.head_teacher_group.name,slug=self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10",self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10",self.emis_reporter1)
     schedule_script_now(grp=self.head_teacher_group.name,slug = self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("I am not in school today",self.emis_reporter1)#response to p3 boys poll
     progress = ScriptProgress.objects.create(script=self.teachers_weekly_script,
         connection=self.emis_reporter1.connection_set.all()[0],step=self.p3_boys_attendance_step)
     attendance_difference = calculate_attendance_difference(self.emis_reporter1.connection_set.all()[0],progress)
     self.assertEqual(0,attendance_difference[self.p3_boys_absent_poll.name][0])
     self.assertEqual("improved",attendance_difference[self.p3_boys_absent_poll.name][1])
 def test_returns_3_as_number_of_schools_that_responded_to_all_violence_questions_if_3_schools_respond(self):
     month_day_range = get_month_day_range(datetime.datetime.now(), depth=1)[0]
     schedule_script_now(self.head_teacher_group.name, slug=self.p3_violence_script.slug)
     check_progress(self.p3_violence_script)
     fake_incoming('6', self.emis_reporter1)
     fake_incoming('3', self.emis_reporter2)
     check_progress(self.p3_violence_script)
     fake_incoming('0', self.emis_reporter1)
     fake_incoming('1', self.emis_reporter2)
     check_progress(self.p3_violence_script)
     fake_incoming('0', self.emis_reporter1)
     fake_incoming('1', self.emis_reporter2)
     self.assertEquals(2, total_number_of_schools_that_responded_to_all_violence_questions([self.emis_reporter1.reporting_location,\
                                                                                            self.emis_reporter2.reporting_location],\
                                                                                           month_day_range))
    def test_should_calculate_difference_in_attendance_for_this_and_past_week(self):
        schedule_script_now(grp=self.head_teacher_group.name,slug=self.head_teachers_termly_script.slug)
        check_progress(self.head_teachers_termly_script)
        fake_incoming("10",self.emis_reporter1)
        check_progress(self.head_teachers_termly_script)
        fake_incoming("10",self.emis_reporter1)
        schedule_script_now(grp=self.head_teacher_group.name,slug = self.teachers_weekly_script.slug)
        check_progress(self.teachers_weekly_script)
        fake_incoming("4",self.emis_reporter1)
        progress = ScriptProgress.objects.create(script=self.teachers_weekly_script,
                                                 connection=self.emis_reporter1.connection_set.all()[0],
                                                 step=self.p6_boys_attendance_step)
        attendance_difference = calculate_attendance_difference(self.emis_reporter1.connection_set.all()[0], progress)

        self.assertEqual(40,attendance_difference[self.p6_boys_absent_poll.name][0])
        self.assertEqual("improved",attendance_difference[self.p6_boys_absent_poll.name][1])
Exemplo n.º 39
0
    def test_should_not_send_absenteeism_calculation_if_partial_responses_sent(
            self):
        schedule_script_now(grp=self.head_teacher_group.name,
                            slug=self.teachers_weekly_script.slug)
        check_progress(self.teachers_weekly_script)
        fake_incoming("3", self.emis_reporter1)
        check_progress(self.teachers_weekly_script)
        time.sleep(3)
        check_progress(self.teachers_weekly_script)
        expected = 'Thankyou p3 Teacher, Attendance for boys have been improved by 0percent" \
                         "Attendance for girls have been improved by 0percent'

        self.assertFalse(expected in Message.objects.filter(
            direction='O',
            connection=self.emis_reporter1.connection_set.all()
            [0]).values_list('text', flat=True))
 def test_that_0_reporters_responded_to_all_the_three_questions_given_all_respond_to_only_two_questions(self):
     month_day_range = get_month_day_range(datetime.datetime.now(), depth=1)[0]
     schedule_script_now(self.head_teacher_group.name, slug=self.p3_violence_script.slug)
     check_progress(self.p3_violence_script)
     fake_incoming('6', self.emis_reporter1)
     fake_incoming('3', self.emis_reporter2)
     fake_incoming('0', self.emis_reporter3)
     check_progress(self.p3_violence_script)
     fake_incoming('1', self.emis_reporter2)
     fake_incoming('2', self.emis_reporter3)
     check_progress(self.p3_violence_script)
     fake_incoming('9', self.emis_reporter1)
     self.assertEquals(0, total_number_of_schools_that_responded_to_all_violence_questions([self.emis_reporter1.reporting_location,\
                                                                                            self.emis_reporter2.reporting_location,\
                                                                                           self.emis_reporter3.reporting_location],\
                                                                                           month_day_range))
 def test_should_report_attendance_difference_for_teachers(self):
     schedule_script_now(grp= self.head_teacher_group.name, slug=self.head_teachers_weekly_script.slug)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("9", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)
     progress = ScriptProgress.objects.create(script=self.head_teachers_weekly_script,
         connection=self.emis_reporter1.connection_set.all()[0], step=self.male_teacher_step)
     teachers_attendance_difference = calculate_attendance_difference(self.emis_reporter1.connection_set.all()[0],
     progress)
     self.assertTrue(teachers_attendance_difference is not None)
     self.assertEqual(40,teachers_attendance_difference[self.male_teachers_attendance_poll.name][0])
     self.assertEqual("improved",teachers_attendance_difference[self.male_teachers_attendance_poll.name][1])
 def test_should_send_alert_messages_on_invalid_and_partial_responses(self):
     # 5 outgoing messages (1st) step 0 poll, (2nd) error msg alert (3rd) resend error poll (4th) step 1 msg (5th) Script completion alert
     schedule_script_now(grp=self.head_teacher_group.name, slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("Invalid", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     expected = 'The answer you have provided is not in the correct format. Use figures like 3 to answer the question'
     self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     time.sleep(3)
     check_progress(self.teachers_weekly_script)
     fake_incoming("3",self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     # self.assertEqual(5, Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     self.assertEqual(4, Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())#pausing feedback
     expected = 'Thank you for participating. Remember to answer all your questions next Thursday.'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))#pausing feedback
Exemplo n.º 43
0
 def test_should_check_message_string_for_teachers(self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.head_teachers_weekly_script.slug)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("9", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.head_teachers_weekly_script)
     expected = 'Thankyou, Attendance for male teacher have been improved by 40percent Attendance for female teachers have been improved by 40percent'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(
         direction='O',
         connection=self.emis_reporter1.connection_set.all()
         [0]).values_list('text', flat=True))  #pausing feedbacks
Exemplo n.º 44
0
 def test_returns_3_as_number_of_schools_that_responded_to_all_violence_questions_if_3_schools_respond(
         self):
     month_day_range = get_month_day_range(datetime.datetime.now(),
                                           depth=1)[0]
     schedule_script_now(self.head_teacher_group.name,
                         slug=self.p3_violence_script.slug)
     check_progress(self.p3_violence_script)
     fake_incoming('6', self.emis_reporter1)
     fake_incoming('3', self.emis_reporter2)
     check_progress(self.p3_violence_script)
     fake_incoming('0', self.emis_reporter1)
     fake_incoming('1', self.emis_reporter2)
     check_progress(self.p3_violence_script)
     fake_incoming('0', self.emis_reporter1)
     fake_incoming('1', self.emis_reporter2)
     self.assertEquals(2, total_number_of_schools_that_responded_to_all_violence_questions([self.emis_reporter1.reporting_location,\
                                                                                            self.emis_reporter2.reporting_location],\
                                                                                           month_day_range))
Exemplo n.º 45
0
 def test_that_0_reporters_responded_to_all_the_three_questions_given_all_respond_to_only_two_questions(
         self):
     month_day_range = get_month_day_range(datetime.datetime.now(),
                                           depth=1)[0]
     schedule_script_now(self.head_teacher_group.name,
                         slug=self.p3_violence_script.slug)
     check_progress(self.p3_violence_script)
     fake_incoming('6', self.emis_reporter1)
     fake_incoming('3', self.emis_reporter2)
     fake_incoming('0', self.emis_reporter3)
     check_progress(self.p3_violence_script)
     fake_incoming('1', self.emis_reporter2)
     fake_incoming('2', self.emis_reporter3)
     check_progress(self.p3_violence_script)
     fake_incoming('9', self.emis_reporter1)
     self.assertEquals(0, total_number_of_schools_that_responded_to_all_violence_questions([self.emis_reporter1.reporting_location,\
                                                                                            self.emis_reporter2.reporting_location,\
                                                                                           self.emis_reporter3.reporting_location],\
                                                                                           month_day_range))
Exemplo n.º 46
0
    def test_get_count_for_yes_no_response_by_school(self):
        params = {
            "description": "A response value for a Poll with expected text responses",
            "datatype": "text",
            "enum_group": None,
            "required": False,
            "type": None,
            "slug": "poll_text_value",
            "name": "Text"
        }
        Attribute.objects.get_or_create(**params)

        schedule_script_now(self.smc_group.name, slug=self.head_teacher_weekly_script.slug)
        check_progress(self.head_teacher_weekly_script)
        fake_incoming("yes", self.emis_reporter3)

        yes, no = get_count_for_yes_no_response_by_school([self.head_teacher_monitoring_poll], [self.kampala_district], self.term_range)
        self.assertEqual({self.kampala_school.id : 1}, yes)
        self.assertEqual({}, no)
Exemplo n.º 47
0
 def test_should_send_feedbacks_to_smc(self):
     schedule_script_now(grp=self.smc_group.name,
                         slug=self.smc_weekly_script.slug)
     check_progress(self.smc_weekly_script)
     fake_incoming("yes", self.emis_reporter3)
     check_progress(self.smc_weekly_script)
     # self.assertEqual(2,Message.objects.filter(direction='O',connection=self.emis_reporter3.connection_set.all()[0]).count())
     self.assertEqual(
         1,
         Message.objects.filter(
             direction='O',
             connection=self.emis_reporter3.connection_set.all()
             [0]).count())  #paisong feedback
     expected = 'Thank you for your report. Please continue to visit your school and report on what is happening.'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter3.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(
         direction='O',
         connection=self.emis_reporter3.connection_set.all()
         [0]).values_list('text', flat=True))  #pausing feedback
Exemplo n.º 48
0
 def test_should_resend_poll_question_on_invalid_responses(self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("invalid response", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     self.assertEqual(
         3,
         Message.objects.filter(
             direction='O',
             connection=self.emis_reporter1.connection_set.all()
             [0]).count())
     outgoing_messages = list(
         Message.objects.filter(
             direction='O',
             connection=self.emis_reporter1.connection_set.all()
             [0]).values_list('text', flat=True))
     self.assertEqual(
         2, outgoing_messages.count(self.p3_boys_absent_poll.question))
 def test_should_return_4_given_reporter_responds_4_to_girls_enrollment_poll(
         self):
     self.head_teachers_termly_script.steps.all().delete()
     self.head_teachers_termly_script.steps.add(
         ScriptStep.objects.create(script=self.head_teachers_termly_script,
                                   poll=self.p6_girls_enroll_poll,
                                   order=0,
                                   rule=ScriptStep.WAIT_MOVEON,
                                   start_offset=0,
                                   giveup_offset=7200))
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     enrolled_girls = get_enrolled_pupils(
         self.emis_reporter1.connection_set.all()[0],
         self.p6_girls_enroll_poll.name, settings.SCHOOL_TERM_START,
         settings.SCHOOL_TERM_END)
     self.assertEqual(4, enrolled_girls)
Exemplo n.º 50
0
 def test_should_send_alert_messages_on_partial_responses(self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("3", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     time.sleep(3)
     check_progress(self.teachers_weekly_script)
     # self.assertEqual(3,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     self.assertEqual(
         2,
         Message.objects.filter(
             direction='O',
             connection=self.emis_reporter1.connection_set.all()
             [0]).count())  #pausing feedback
     expected = 'Thank you for participating. Remember to answer all your questions next Thursday.'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(
         direction='O',
         connection=self.emis_reporter1.connection_set.all()
         [0]).values_list('text', flat=True))  #pausing feedback
Exemplo n.º 51
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')
Exemplo n.º 52
0
 def test_should_check_increment_in_outgoing_msg_count_on_all_responses_received(
         self):
     schedule_script_now(grp=self.head_teacher_group.name,
                         slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)  #response to p3 boys poll
     check_progress(self.teachers_weekly_script)
     self.assertEqual(
         2,
         Message.objects.filter(
             direction='O',
             connection=self.emis_reporter1.connection_set.all()
             [0]).count())
     fake_incoming("3", self.emis_reporter1)  #response to p3 girls poll
     check_progress(self.teachers_weekly_script)
     # self.assertEqual(3,Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).count())
     self.assertEqual(
         2,
         Message.objects.filter(
             direction='O',
             connection=self.emis_reporter1.connection_set.all()
             [0]).count())  #pausing feedbacks
Exemplo n.º 53
0
    def test_get_count_for_yes_no_response_by_school(self):
        params = {
            "description":
            "A response value for a Poll with expected text responses",
            "datatype": "text",
            "enum_group": None,
            "required": False,
            "type": None,
            "slug": "poll_text_value",
            "name": "Text"
        }
        Attribute.objects.get_or_create(**params)

        schedule_script_now(self.smc_group.name,
                            slug=self.head_teacher_weekly_script.slug)
        check_progress(self.head_teacher_weekly_script)
        fake_incoming("yes", self.emis_reporter3)

        yes, no = get_count_for_yes_no_response_by_school(
            [self.head_teacher_monitoring_poll], [self.kampala_district],
            self.term_range)
        self.assertEqual({self.kampala_school.id: 1}, yes)
        self.assertEqual({}, no)
 def test_should_send_2_invalid_alerts_by_script_completion(self):
     schedule_script_now(grp = self.head_teacher_group.name, slug = self.head_teachers_termly_script.slug)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     fake_incoming("10", self.emis_reporter1)
     check_progress(self.head_teachers_termly_script)
     schedule_script_now(grp=self.head_teacher_group.name,slug=self.teachers_weekly_script.slug)
     check_progress(self.teachers_weekly_script)
     fake_incoming("Invalid", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     fake_incoming("Invalid", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     fake_incoming("4", self.emis_reporter1)
     check_progress(self.teachers_weekly_script)
     alert = 'The answer you have provided is not in the correct format. Use figures like 3 to answer the question'
     messages = Message.objects.filter(direction='O', text =alert, connection=self.emis_reporter1.connection_set.all()[0])
     self.assertEqual(2, messages.count())
     expected ='Thankyou p3 Teacher, Attendance for boys have been improved by 40percent Attendance for girls have been improved by 40percent'
     # self.assertTrue(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))
     self.assertFalse(expected in Message.objects.filter(direction='O',connection=self.emis_reporter1.connection_set.all()[0]).values_list('text',flat=True))#pausing feedback