def test_risk_levels_during_first_semester(self, send_notification_mock,
                                               timezone_mock):
        calculate_students_risk_level()
        self.refresh_objects_from_db([
            self.student1, self.student2, self.student3, self.student4,
            self.student5, self.student6, self.student7, self.student8,
            self.student9, self.student10, self.student11, self.catalog4,
            self.catalog5, self.catalog8, self.catalog9, self.catalog11
        ])

        self.assertEqual(self.student1.labels.count(), 0)
        self.assertFalse(self.student1.is_at_risk)

        self.assertCountEqual(
            self.student2.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_1_LABEL))
        self.assertTrue(self.student2.is_at_risk)
        self.assertEqual(self.student2.risk_description,
                         '1-3 absențe nemotivate')

        self.assertCountEqual(
            self.student3.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student3.is_at_risk)
        self.assertEqual(self.student3.risk_description,
                         '4 sau mai multe absențe nemotivate')

        self.assertEqual(self.student4.labels.count(), 0)
        self.assertFalse(self.student4.is_at_risk)
        self.assertFalse(self.catalog4.is_at_risk)
        self.assertIsNone(self.student4.risk_description)

        self.assertEqual(self.student5.labels.count(), 0)
        self.assertFalse(self.student5.is_at_risk)
        self.assertFalse(self.catalog5.is_at_risk)
        self.assertIsNone(self.student5.risk_description)

        self.assertEqual(self.student6.labels.count(), 0)
        self.assertFalse(self.student6.is_at_risk)
        self.assertIsNone(self.student6.risk_description)

        self.assertEqual(self.student7.labels.count(), 0)
        self.assertFalse(self.student7.is_at_risk)
        self.assertIsNone(self.student7.risk_description)

        self.assertCountEqual(
            self.student8.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_1_LABEL))
        self.assertTrue(self.student8.is_at_risk)
        self.assertEqual(self.student8.risk_description,
                         '1-3 absențe nemotivate')

        self.assertEqual(self.student9.labels.count(), 0)
        self.assertFalse(self.student9.is_at_risk)
        self.assertFalse(self.catalog9.is_at_risk)
        self.assertIsNone(self.student9.risk_description)

        self.assertCountEqual(
            self.student10.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student10.is_at_risk)
        self.assertEqual(self.student10.risk_description,
                         '4 sau mai multe absențe nemotivate')

        self.assertCountEqual(
            self.student11.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student11.is_at_risk)
        self.assertEqual(self.student11.risk_description,
                         '4 sau mai multe absențe nemotivate')

        country_stats = StudentAtRiskCounts.objects.get(by_country=True,
                                                        year=2020,
                                                        month=1)
        self.assertEqual(country_stats.daily_counts[0]['count'], 5)
        school1_stats = StudentAtRiskCounts.objects.get(
            school_unit=self.school1, year=2020, month=1)
        self.assertEqual(school1_stats.daily_counts[0]['count'], 2)
        school2_stats = StudentAtRiskCounts.objects.get(
            school_unit=self.school2, year=2020, month=1)
        self.assertEqual(school2_stats.daily_counts[0]['count'], 3)
        study_class1_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class1, year=2020, month=1)
        self.assertEqual(study_class1_stats.daily_counts[0]['count'], 2)
        study_class2_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class2, year=2020, month=1)
        self.assertEqual(study_class2_stats.daily_counts[0]['count'], 0)
        study_class3_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class3, year=2020, month=1)
        self.assertEqual(study_class3_stats.daily_counts[0]['count'], 0)
        study_class4_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class4, year=2020, month=1)
        self.assertEqual(study_class4_stats.daily_counts[0]['count'], 1)
        study_class5_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class5, year=2020, month=1)
        self.assertEqual(study_class5_stats.daily_counts[0]['count'], 2)

        self.assertEqual(send_notification_mock.call_count, 0)
    def test_risk_levels_after_second_semester_technological_end(
            self, mocked_method):
        calculate_students_risk_level()
        self.refresh_objects_from_db([
            self.student1, self.student2, self.student3, self.student4,
            self.student5, self.student6, self.student7, self.student8,
            self.student9, self.student10, self.student11, self.catalog4,
            self.catalog5, self.catalog8, self.catalog9, self.catalog11
        ])

        self.assertEqual(self.student1.labels.count(), 0)
        self.assertFalse(self.student1.is_at_risk)

        self.assertEqual(self.student2.labels.count(), 0)
        self.assertFalse(self.student2.is_at_risk)

        self.assertEqual(self.student3.labels.count(), 0)
        self.assertFalse(self.student3.is_at_risk)

        self.assertCountEqual(
            self.student4.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_1_LABEL))
        self.assertTrue(self.student4.is_at_risk)
        self.assertTrue(self.catalog4.is_at_risk)
        self.assertEqual(self.student4.risk_description,
                         '5-6 medie Limba română sau Matematică')

        self.assertCountEqual(
            self.student5.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student5.is_at_risk)
        self.assertTrue(self.catalog5.is_at_risk)
        self.assertEqual(self.student5.risk_description,
                         'Medie Limba română sau Matematică sub 5')

        self.assertCountEqual(
            self.student6.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_1_LABEL))
        self.assertTrue(self.student6.is_at_risk)
        self.assertEqual(self.student6.risk_description, '8-9 notă purtare')

        self.assertCountEqual(
            self.student7.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student7.is_at_risk)
        self.assertEqual(self.student7.risk_description, 'Notă purtare sub 8')

        self.assertCountEqual(
            self.student8.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student8.is_at_risk)
        self.assertTrue(self.catalog8.is_at_risk)
        self.assertEqual(self.student8.risk_description,
                         'Medie Limba română sau Matematică sub 5')

        self.assertCountEqual(
            self.student9.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student9.is_at_risk)
        self.assertTrue(self.catalog9.is_at_risk)
        self.assertEqual(
            self.student9.risk_description,
            '5-6 medie Limba română sau Matematică și notă purtare sub 8')

        self.assertCountEqual(
            self.student10.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_1_LABEL))
        self.assertTrue(self.student10.is_at_risk)
        self.assertEqual(self.student10.risk_description, '8-9 notă purtare')

        self.assertCountEqual(
            self.student11.labels.all(),
            Label.objects.filter(text=ABANDONMENT_RISK_2_LABEL))
        self.assertTrue(self.student11.is_at_risk)
        self.assertTrue(self.catalog11.is_at_risk)
        self.assertEqual(
            self.student11.risk_description,
            'Medie Limba română sau Matematică sub 5 și notă purtare sub 8')

        country_stats = StudentAtRiskCounts.objects.get(by_country=True,
                                                        year=2020,
                                                        month=6)
        self.assertEqual(country_stats.daily_counts[3]['count'], 8)
        school1_stats = StudentAtRiskCounts.objects.get(
            school_unit=self.school1, year=2020, month=6)
        self.assertEqual(school1_stats.daily_counts[3]['count'], 4)
        school2_stats = StudentAtRiskCounts.objects.get(
            school_unit=self.school2, year=2020, month=6)
        self.assertEqual(school2_stats.daily_counts[3]['count'], 4)
        study_class1_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class1, year=2020, month=6)
        self.assertEqual(study_class1_stats.daily_counts[3]['count'], 0)
        study_class2_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class2, year=2020, month=6)
        self.assertEqual(study_class2_stats.daily_counts[3]['count'], 2)
        study_class3_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class3, year=2020, month=6)
        self.assertEqual(study_class3_stats.daily_counts[3]['count'], 2)
        study_class4_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class4, year=2020, month=6)
        self.assertEqual(study_class4_stats.daily_counts[3]['count'], 2)
        study_class5_stats = StudentAtRiskCounts.objects.get(
            study_class=self.study_class5, year=2020, month=6)
        self.assertEqual(study_class5_stats.daily_counts[3]['count'], 2)
示例#3
0
def calculate_students_risk_level_task():
    from edualert.catalogs.utils import calculate_students_risk_level
    calculate_students_risk_level()