Example #1
0
    def setUpTestData(cls):
        cls.principal = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL)
        cls.school_unit = RegisteredSchoolUnitFactory(school_principal=cls.principal)

        cls.calendar = AcademicYearCalendarFactory()

        cls.subject1 = SubjectFactory()
        cls.subject2 = SubjectFactory()
        cls.coordination_subject = SubjectFactory(is_coordination=True)

        cls.academic_program = AcademicProgramFactory(school_unit=cls.school_unit)
        ProgramSubjectThroughFactory(generic_academic_program=cls.academic_program.generic_academic_program,
                                     subject=cls.subject1, class_grade='X', class_grade_arabic=10)
        ProgramSubjectThroughFactory(academic_program=cls.academic_program, subject=cls.subject2,
                                     is_mandatory=False, class_grade='X', class_grade_arabic=10)

        cls.teacher1 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
        cls.teacher2 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
        cls.teacher1.taught_subjects.add(cls.subject1)
        cls.teacher2.taught_subjects.add(cls.subject1)

        cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_master=cls.teacher1, academic_program=cls.academic_program,
                                            class_grade='X', class_grade_arabic=10, class_letter='A')

        cls.student1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class)
        StudentCatalogPerYearFactory(student=cls.student1, study_class=cls.study_class)
        cls.student2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class)
        StudentCatalogPerYearFactory(student=cls.student2, study_class=cls.study_class)

        cls.new_student = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit)
Example #2
0
    def test_academic_program_subject_list_success(self):
        self.client.login(username=self.principal.username, password='******')

        # Create a subject through with another class grade
        subject = SubjectFactory(name='Wrong class grade')
        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject,
            class_grade='X',
            class_grade_arabic=10)

        response = self.get_response()
        self.assertEqual(len(response.data), 2)
        self.assertCountEqual(
            [subject['subject_id'] for subject in response.data],
            [self.optional_subject.id, self.mandatory_subject.id])
        self.assertCountEqual(
            [subject['is_mandatory'] for subject in response.data],
            [False, True])

        # Create a mandatory subject from another generic academic program
        generic_academic_program = GenericAcademicProgramFactory()
        subject = SubjectFactory(name='Other generic academic program')
        ProgramSubjectThroughFactory(
            generic_academic_program=generic_academic_program,
            subject=subject,
            class_grade='IX',
            class_grade_arabic=9)
        response = self.get_response()
        self.assertEqual(len(response.data), 2)

        # Create another optional subject
        subject = SubjectFactory(name='Other optional')
        ProgramSubjectThroughFactory(academic_program=self.academic_program,
                                     subject=subject,
                                     class_grade='IX',
                                     class_grade_arabic=9,
                                     is_mandatory=False)
        response = self.get_response()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 3)

        # Create another mandatory subject
        subject = SubjectFactory(name='Other mandatory')
        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject,
            class_grade='IX',
            class_grade_arabic=9)
        response = self.get_response()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 4)
Example #3
0
    def setUpTestData(cls):
        cls.principal = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL)
        cls.school_unit = RegisteredSchoolUnitFactory(school_principal=cls.principal)

        cls.category1 = SchoolUnitCategoryFactory(category_level=SchoolUnitCategory.CategoryLevels.SECONDARY_SCHOOL)
        cls.category2 = SchoolUnitCategoryFactory(category_level=SchoolUnitCategory.CategoryLevels.HIGHSCHOOL)
        cls.school_unit.categories.add(cls.category1, cls.category2)

        cls.calendar = AcademicYearCalendarFactory()

        cls.subject1 = SubjectFactory()
        cls.subject2 = SubjectFactory()
        cls.coordination_subject = SubjectFactory(is_coordination=True)
        cls.academic_program = AcademicProgramFactory(school_unit=cls.school_unit)
        for class_grade, class_grade_arabic in zip(['VI', 'X'], [6, 10]):
            ProgramSubjectThroughFactory(academic_program=cls.academic_program, subject=cls.subject1,
                                         is_mandatory=False, class_grade=class_grade, class_grade_arabic=class_grade_arabic)
            ProgramSubjectThroughFactory(generic_academic_program=cls.academic_program.generic_academic_program,
                                         subject=cls.subject2, class_grade=class_grade, class_grade_arabic=class_grade_arabic)

        cls.teacher1 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
        cls.teacher2 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
        cls.teacher1.taught_subjects.add(cls.subject1, cls.subject2)
        cls.teacher2.taught_subjects.add(cls.subject1, cls.subject2)

        cls.study_class1 = StudyClassFactory(school_unit=cls.school_unit, class_master=cls.teacher1, academic_program=cls.academic_program,
                                             class_grade='X', class_grade_arabic=10, class_letter='A')
        TeacherClassThroughFactory(study_class=cls.study_class1, teacher=cls.teacher1, subject=cls.coordination_subject, is_class_master=True)
        cls.study_class2 = StudyClassFactory(school_unit=cls.school_unit, class_master=cls.teacher2, academic_program=cls.academic_program)
        TeacherClassThroughFactory(study_class=cls.study_class2, teacher=cls.teacher2, subject=cls.coordination_subject, is_class_master=True)

        TeacherClassThroughFactory(study_class=cls.study_class1, teacher=cls.teacher1, subject=cls.subject1, is_class_master=True)
        TeacherClassThroughFactory(study_class=cls.study_class1, teacher=cls.teacher2, subject=cls.subject2, is_class_master=False)
        TeacherClassThroughFactory(study_class=cls.study_class2, teacher=cls.teacher1, subject=cls.subject1, is_class_master=False)
        TeacherClassThroughFactory(study_class=cls.study_class2, teacher=cls.teacher2, subject=cls.subject2, is_class_master=True)

        cls.student1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class1)
        StudentCatalogPerYearFactory(student=cls.student1, study_class=cls.study_class1)
        cls.student2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class1)
        StudentCatalogPerYearFactory(student=cls.student2, study_class=cls.study_class1)
        cls.student3 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class2)
        StudentCatalogPerYearFactory(student=cls.student3, study_class=cls.study_class2)

        cls.academic_program2 = AcademicProgramFactory(school_unit=cls.school_unit)
        for class_grade, class_grade_arabic in zip(['VII', 'XI'], [7, 11]):
            ProgramSubjectThroughFactory(academic_program=cls.academic_program2, subject=cls.subject1,
                                         is_mandatory=False, class_grade=class_grade, class_grade_arabic=class_grade_arabic)
            ProgramSubjectThroughFactory(generic_academic_program=cls.academic_program2.generic_academic_program,
                                         subject=cls.subject2, class_grade=class_grade, class_grade_arabic=class_grade_arabic)

        cls.new_teacher = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
        cls.new_student = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit)
    def test_generate_next_year_academic_programs(self):
        current_calendar = AcademicYearCalendarFactory()

        program1 = AcademicProgramFactory(
            academic_year=current_calendar.academic_year - 1)
        ProgramSubjectThroughFactory(academic_program=program1,
                                     subject=SubjectFactory())

        program2 = AcademicProgramFactory(
            academic_year=current_calendar.academic_year - 1)
        ProgramSubjectThroughFactory(academic_program=program2,
                                     subject=SubjectFactory())

        generate_next_year_academic_programs()

        self.assertEqual(
            AcademicProgram.objects.filter(
                academic_year=current_calendar.academic_year).count(), 2)
        cloned_program1 = AcademicProgram.objects.filter(
            name=program1.name,
            academic_year=current_calendar.academic_year).first()
        self.assertIsNotNone(cloned_program1)
        cloned_program2 = AcademicProgram.objects.filter(
            name=program2.name,
            academic_year=current_calendar.academic_year).first()
        self.assertIsNotNone(cloned_program2)

        for field in [
                'avg_sem1', 'avg_sem2', 'avg_annual', 'unfounded_abs_avg_sem1',
                'unfounded_abs_avg_sem2', 'unfounded_abs_avg_annual'
        ]:
            self.assertIsNone(getattr(cloned_program1, field))
            self.assertIsNone(getattr(cloned_program2, field))
        for field in ['classes_count', 'students_at_risk_count']:
            self.assertEqual(getattr(cloned_program1, field), 0)
            self.assertEqual(getattr(cloned_program2, field), 0)

        self.assertEqual(ProgramSubjectThrough.objects.count(), 4)
        self.assertEqual(
            ProgramSubjectThrough.objects.filter(
                academic_program__academic_year=current_calendar.academic_year
            ).count(), 2)
        self.assertTrue(
            ProgramSubjectThrough.objects.filter(
                academic_program=cloned_program1).exists())
        self.assertTrue(
            ProgramSubjectThrough.objects.filter(
                academic_program=cloned_program2).exists())
 def setUpTestData(cls):
     cls.principal = UserProfileFactory(
         user_role=UserProfile.UserRoles.PRINCIPAL)
     cls.school_unit = RegisteredSchoolUnitFactory(
         school_principal=cls.principal)
     cls.generic_academic_program = GenericAcademicProgramFactory(
         optional_subjects_weekly_hours={
             "IX": 10,
             "X": 1
         },
         academic_profile=cls.school_unit.academic_profile,
     )
     cls.school_unit.categories.add(cls.generic_academic_program.category)
     cls.academic_year = 2020
     cls.academic_year_calendar = AcademicYearCalendarFactory(
         academic_year=cls.academic_year)
     cls.academic_program = AcademicProgramFactory(
         school_unit=cls.school_unit,
         generic_academic_program=cls.generic_academic_program,
         academic_year=cls.academic_year)
     cls.subject = SubjectFactory(name='Subject')
     cls.subject_through = ProgramSubjectThroughFactory(
         academic_program=cls.academic_program,
         subject=cls.subject,
         class_grade='IX',
         class_grade_arabic=9)
    def setUpTestData(cls):
        cls.academic_calendar = AcademicYearCalendarFactory()
        cls.corigente_event = SchoolEventFactory(event_type=SchoolEvent.EventTypes.CORIGENTE, academic_year_calendar=cls.academic_calendar,
                                                 starts_at=datetime.date(2020, 8, 20), ends_at=datetime.date(2020, 8, 27))
        cls.diferente_event = SchoolEventFactory(event_type=SchoolEvent.EventTypes.DIFERENTE, academic_year_calendar=cls.academic_calendar,
                                                 starts_at=datetime.date(2020, 9, 1), ends_at=datetime.date(2020, 9, 8))

        cls.school_unit = RegisteredSchoolUnitFactory()
        cls.school_stats = SchoolUnitStatsFactory(school_unit=cls.school_unit)

        cls.teacher = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_grade='IX', class_grade_arabic=9)
        cls.subject = SubjectFactory()
        ProgramSubjectThroughFactory(academic_program=cls.study_class.academic_program, class_grade='IX',
                                     subject=cls.subject, weekly_hours_count=3)

        cls.teacher_class_through = TeacherClassThroughFactory(
            study_class=cls.study_class,
            teacher=cls.teacher,
            subject=cls.subject
        )
        cls.student = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class)
        cls.catalog = StudentCatalogPerSubjectFactory(
            subject=cls.subject,
            teacher=cls.teacher,
            student=cls.student,
            study_class=cls.study_class,
            is_enrolled=True
        )
        cls.catalog_per_year = StudentCatalogPerYearFactory(
            student=cls.student,
            study_class=cls.study_class
        )
    def setUpTestData(cls):
        cls.calendar = AcademicYearCalendarFactory()
        cls.school_unit = RegisteredSchoolUnitFactory()
        cls.school_stats = SchoolUnitStatsFactory(school_unit=cls.school_unit)

        cls.teacher = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_master=cls.teacher)
        cls.subject = SubjectFactory()
        ProgramSubjectThroughFactory(academic_program=cls.study_class.academic_program, subject=cls.subject, weekly_hours_count=3,
                                     class_grade=cls.study_class.class_grade, class_grade_arabic=cls.study_class.class_grade_arabic)
        TeacherClassThroughFactory(teacher=cls.teacher, study_class=cls.study_class, is_class_master=True, subject=cls.subject)

        cls.student1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class)
        cls.catalog1 = StudentCatalogPerSubjectFactory(student=cls.student1, study_class=cls.study_class, teacher=cls.teacher, subject=cls.subject)
        cls.catalog_per_year1 = StudentCatalogPerYearFactory(student=cls.student1, study_class=cls.study_class)
        cls.student2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class)
        cls.catalog2 = StudentCatalogPerSubjectFactory(student=cls.student2, study_class=cls.study_class, teacher=cls.teacher, subject=cls.subject)
        cls.catalog_per_year2 = StudentCatalogPerYearFactory(student=cls.student2, study_class=cls.study_class)

        cls.expected_fields = [
            'id', 'student', 'avg_sem1', 'avg_sem2', 'avg_annual', 'avg_after_2nd_examination', 'avg_limit', 'abs_count_sem1', 'abs_count_sem2',
            'abs_count_annual', 'founded_abs_count_sem1', 'founded_abs_count_sem2', 'founded_abs_count_annual', 'unfounded_abs_count_sem1',
            'unfounded_abs_count_sem2', 'unfounded_abs_count_annual', 'grades_sem1', 'grades_sem2', 'abs_sem1', 'abs_sem2',
            'second_examination_grades', 'difference_grades_sem1', 'difference_grades_sem2', 'wants_thesis', 'is_exempted',
            'third_of_hours_count_sem1', 'third_of_hours_count_sem2', 'third_of_hours_count_annual', 'is_coordination_subject'
        ]
Example #8
0
    def setUpTestData(cls):
        cls.academic_calendar = AcademicYearCalendarFactory()
        cls.school_unit = RegisteredSchoolUnitFactory()
        cls.school_stats = SchoolUnitStatsFactory(school_unit=cls.school_unit)

        cls.teacher = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit)
        cls.subject = SubjectFactory()
        cls.teacher_class_through = TeacherClassThroughFactory(
            study_class=cls.study_class,
            teacher=cls.teacher,
            subject=cls.subject)
        ProgramSubjectThroughFactory(
            academic_program=cls.study_class.academic_program,
            subject=cls.subject,
            weekly_hours_count=1,
            class_grade=cls.study_class.class_grade,
            class_grade_arabic=cls.study_class.class_grade_arabic)

        cls.student = UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            full_name='a',
            student_in_class=cls.study_class)
        cls.catalog = StudentCatalogPerSubjectFactory(
            subject=cls.subject,
            teacher=cls.teacher,
            student=cls.student,
            study_class=cls.study_class,
            is_enrolled=True)
        cls.catalog_per_year = StudentCatalogPerYearFactory(
            student=cls.student, study_class=cls.study_class)
Example #9
0
    def setUpTestData(cls):
        cls.academic_calendar = AcademicYearCalendarFactory()
        cls.corigente_event = SchoolEventFactory(
            event_type=SchoolEvent.EventTypes.CORIGENTE,
            academic_year_calendar=cls.academic_calendar,
            starts_at=datetime.date(2020, 8, 20),
            ends_at=datetime.date(2020, 8, 27))
        cls.diferente_event = SchoolEventFactory(
            event_type=SchoolEvent.EventTypes.DIFERENTE,
            academic_year_calendar=cls.academic_calendar,
            starts_at=datetime.date(2020, 9, 1),
            ends_at=datetime.date(2020, 9, 8))

        cls.school_unit = RegisteredSchoolUnitFactory()
        cls.school_stats = SchoolUnitStatsFactory(school_unit=cls.school_unit)

        cls.teacher = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit,
                                            class_grade='IX',
                                            class_grade_arabic=9)
        cls.subject = SubjectFactory()
        ProgramSubjectThroughFactory(
            academic_program=cls.study_class.academic_program,
            class_grade='IX',
            subject=cls.subject,
            weekly_hours_count=3)

        cls.student = UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class)
        cls.teacher_class_through = TeacherClassThroughFactory(
            study_class=cls.study_class,
            teacher=cls.teacher,
            subject=cls.subject)
        cls.catalog = StudentCatalogPerSubjectFactory(
            subject=cls.subject,
            teacher=cls.teacher,
            student=cls.student,
            study_class=cls.study_class)
        cls.catalog_per_year = StudentCatalogPerYearFactory(
            student=cls.student, study_class=cls.study_class)

        cls.expected_fields = [
            'id', 'student', 'avg_sem1', 'avg_sem2', 'avg_annual',
            'avg_after_2nd_examination', 'avg_limit', 'abs_count_sem1',
            'abs_count_sem2', 'abs_count_annual', 'founded_abs_count_sem1',
            'founded_abs_count_sem2', 'founded_abs_count_annual',
            'unfounded_abs_count_sem1', 'unfounded_abs_count_sem2',
            'unfounded_abs_count_annual', 'grades_sem1', 'grades_sem2',
            'abs_sem1', 'abs_sem2', 'second_examination_grades',
            'difference_grades_sem1', 'difference_grades_sem2', 'wants_thesis',
            'is_exempted', 'third_of_hours_count_sem1',
            'third_of_hours_count_sem2', 'third_of_hours_count_annual',
            'is_coordination_subject'
        ]
        cls.examination_grade_fields = [
            'id', 'examination_type', 'taken_at', 'grade1', 'grade2', 'created'
        ]
    def test_own_child_school_situation_success(self):
        self.client.login(username=self.parent.username, password='******')
        another_catalog = StudentCatalogPerSubjectFactory(
            student=self.student,
            study_class=self.study_class,
            academic_year=self.calendar.academic_year)
        ProgramSubjectThroughFactory(
            academic_program=self.study_class.academic_program,
            class_grade=self.study_class.class_grade,
            subject=another_catalog.subject,
            weekly_hours_count=5)
        StudentCatalogPerSubjectFactory(
            student=self.student,
            academic_year=self.calendar.academic_year - 1)

        expected_fields = [
            'id', 'full_name', 'study_class', 'labels', 'risk_description',
            'catalogs_per_subjects'
        ]
        expected_study_class_fields = [
            'id', 'class_grade', 'class_letter', 'academic_program_name',
            'class_master'
        ]
        expected_class_master_fields = ['id', 'full_name']
        expected_catalog_fields = [
            'id', 'subject_name', 'teacher', 'avg_sem1', 'avg_sem2',
            'avg_annual', 'avg_after_2nd_examination', 'avg_limit',
            'grades_sem1', 'grades_sem2', 'second_examination_grades',
            'difference_grades_sem1', 'difference_grades_sem2',
            'abs_count_sem1', 'abs_count_sem2', 'abs_count_annual',
            'founded_abs_count_sem1', 'founded_abs_count_sem2',
            'founded_abs_count_annual', 'unfounded_abs_count_sem1',
            'unfounded_abs_count_sem2', 'unfounded_abs_count_annual',
            'third_of_hours_count_sem1', 'third_of_hours_count_sem2',
            'third_of_hours_count_annual', 'abs_sem1', 'abs_sem2',
            'wants_thesis', 'is_exempted', 'is_coordination_subject'
        ]

        response = self.client.get(self.build_url(self.student.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertCountEqual(response.data.keys(), expected_fields)
        self.assertCountEqual(response.data['study_class'].keys(),
                              expected_study_class_fields)
        self.assertCountEqual(
            response.data['study_class']['class_master'].keys(),
            expected_class_master_fields)
        self.assertEqual(len(response.data['catalogs_per_subjects']), 2)

        for catalog in response.data['catalogs_per_subjects']:
            self.assertCountEqual(catalog.keys(), expected_catalog_fields)
            self.assertEqual(catalog['avg_limit'], 5)
            self.assertEqual(catalog['third_of_hours_count_sem1'], 25)
            self.assertEqual(catalog['third_of_hours_count_sem2'], 25)
            self.assertEqual(catalog['third_of_hours_count_annual'], 50)
Example #11
0
 def setUpTestData(cls):
     cls.principal = UserProfileFactory(
         user_role=UserProfile.UserRoles.PRINCIPAL)
     cls.school_unit = RegisteredSchoolUnitFactory(
         school_principal=cls.principal)
     cls.generic_academic_program = GenericAcademicProgramFactory()
     cls.academic_program = AcademicProgramFactory(
         school_unit=cls.school_unit,
         generic_academic_program=cls.generic_academic_program)
     cls.mandatory_subject = SubjectFactory(name='Mandatory')
     cls.optional_subject = SubjectFactory(name='Optional')
     cls.mandatory_through = ProgramSubjectThroughFactory(
         generic_academic_program=cls.generic_academic_program,
         subject=cls.mandatory_subject,
         class_grade='IX',
         class_grade_arabic=9)
     cls.optional_through = ProgramSubjectThroughFactory(
         academic_program=cls.academic_program,
         subject=cls.optional_subject,
         class_grade='IX',
         class_grade_arabic=9,
         is_mandatory=False)
    def test_generic_academic_program_detail(self):
        self.client.login(username=self.principal.username, password='******')

        subject1 = SubjectFactory(name='Subject B')
        subject2 = SubjectFactory(name='Subject C')
        subject3 = SubjectFactory(name='Subject A')
        subject_through1 = ProgramSubjectThroughFactory(
            generic_academic_program=self.program, subject=subject1)
        subject_through2 = ProgramSubjectThroughFactory(
            generic_academic_program=self.program,
            subject=subject2,
            class_grade='X',
            class_grade_arabic=10)
        subject_through3 = ProgramSubjectThroughFactory(
            generic_academic_program=self.program, subject=subject3)

        response = self.client.get(self.build_url(self.program.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertCountEqual(
            response.data.keys(),
            ['id', 'subjects', 'optional_subjects_weekly_hours'])

        subjects_response = response.data['subjects']
        self.assertEqual(len(subjects_response.keys()), 2)
        self.assertTrue(
            all([
                'IX' in subjects_response.keys(), 'X'
                in subjects_response.keys()
            ]))
        self.assertEqual([
            subject_through['id']
            for subject_through in subjects_response['IX']
        ], [subject_through3.id, subject_through1.id])
        self.assertEqual([
            subject_through['id'] for subject_through in subjects_response['X']
        ], [
            subject_through2.id,
        ])
    def test_academic_program_detail(self):
        self.client.login(username=self.principal.username, password='******')

        subject1 = SubjectFactory(name='Subject A')
        subject2 = SubjectFactory(name='Subject C')
        subject3 = SubjectFactory(name='Subject B')
        subject_through1 = ProgramSubjectThroughFactory(
            academic_program=self.academic_program,
            subject=subject1,
            is_mandatory=False,
            class_grade='IX',
            class_grade_arabic=9)
        subject_through2 = ProgramSubjectThroughFactory(
            academic_program=self.academic_program,
            subject=subject2,
            class_grade='X',
            class_grade_arabic=10,
            is_mandatory=False)
        subject_through3 = ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject3,
            is_mandatory=True,
            class_grade='IX',
            class_grade_arabic=9)

        response = self.client.get(self.build_url(self.academic_program.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['optional_subjects_weekly_hours'],
                         self.optional_subjects_weekly_hours)

        subjects = response.data['subjects']
        self.assertCountEqual(subjects.keys(), ['IX', 'X'])
        self.assertEqual(subjects['IX']['optional_subjects'][0]['id'],
                         subject_through1.id)
        self.assertEqual(subjects['X']['optional_subjects'][0]['id'],
                         subject_through2.id)
        self.assertEqual(subjects['IX']['mandatory_subjects'][0]['id'],
                         subject_through3.id)
 def setUpTestData(cls):
     cls.calendar = AcademicYearCalendarFactory()
     cls.school_unit = RegisteredSchoolUnitFactory()
     cls.teacher = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit)
     cls.student = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit)
     cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_grade='IX', class_grade_arabic=9)
     cls.subject = SubjectFactory()
     cls.teacher_class_through = TeacherClassThroughFactory(
         study_class=cls.study_class,
         teacher=cls.teacher,
         subject=cls.subject
     )
     ProgramSubjectThroughFactory(academic_program=cls.study_class.academic_program, class_grade='IX',
                                  subject=cls.subject, weekly_hours_count=3)
    def test_academic_program_detail_expected_fields(self):
        self.client.login(username=self.principal.username, password='******')

        expected_fields = [
            'id', 'name', 'classes_count', 'academic_year', 'core_subject',
            'optional_subjects_weekly_hours', 'subjects'
        ]
        subjects_expected_fields = ['mandatory_subjects', 'optional_subjects']
        subject_expected_fields = [
            'subject_id', 'subject_name', 'id', 'weekly_hours_count'
        ]

        subject1 = SubjectFactory(name='Subject A')
        ProgramSubjectThroughFactory(class_grade='X',
                                     academic_program=self.academic_program,
                                     subject=subject1,
                                     is_mandatory=False,
                                     class_grade_arabic=10)
        subject2 = SubjectFactory(name='Subject B')
        ProgramSubjectThroughFactory(academic_program=self.academic_program,
                                     subject=subject2,
                                     class_grade='X',
                                     is_mandatory=True,
                                     class_grade_arabic=10)

        response = self.client.get(self.build_url(self.academic_program.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertCountEqual(response.data.keys(), expected_fields)
        self.assertEqual(len(response.data['subjects']), 1)
        self.assertCountEqual(response.data['subjects']['X'].keys(),
                              subjects_expected_fields)
        for subject in response.data['subjects']['X']['optional_subjects']:
            self.assertCountEqual(subject.keys(), subject_expected_fields)
        for subject in response.data['subjects']['X']['mandatory_subjects']:
            self.assertCountEqual(subject.keys(), subject_expected_fields)
    def setUpTestData(cls):
        AcademicYearCalendarFactory()
        cls.school_unit = RegisteredSchoolUnitFactory()
        cls.teacher = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit,
                                            class_grade='IX',
                                            class_grade_arabic=9)
        cls.subject = SubjectFactory()
        ProgramSubjectThroughFactory(
            academic_program=cls.study_class.academic_program,
            subject=cls.subject,
            weekly_hours_count=1)

        cls.teacher_class_through = TeacherClassThroughFactory(
            study_class=cls.study_class,
            teacher=cls.teacher,
            subject=cls.subject)

        cls.student1 = UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class)
        cls.catalog1 = StudentCatalogPerSubjectFactory(
            subject=cls.subject,
            teacher=cls.teacher,
            student=cls.student1,
            study_class=cls.study_class,
            avg_sem1=10,
            avg_sem2=10,
            avg_annual=10,
            avg_final=10)
        for semester in [1, 2]:
            for i in range(2):
                SubjectGradeFactory(student=cls.student1,
                                    catalog_per_subject=cls.catalog1,
                                    semester=semester)

        cls.student2 = UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class)
        cls.catalog2 = StudentCatalogPerSubjectFactory(
            subject=cls.subject,
            teacher=cls.teacher,
            student=cls.student2,
            study_class=cls.study_class)
Example #17
0
 def setUpTestData(cls):
     cls.school = RegisteredSchoolUnitFactory()
     cls.teacher = UserProfileFactory(
         user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school)
     cls.study_class = StudyClassFactory(school_unit=cls.school,
                                         class_grade='IX',
                                         class_grade_arabic=9,
                                         class_letter='A')
     cls.student = UserProfileFactory(
         user_role=UserProfile.UserRoles.STUDENT,
         school_unit=cls.school,
         student_in_class=cls.study_class)
     cls.subject = SubjectFactory()
     cls.teacher_class_through = TeacherClassThroughFactory(
         study_class=cls.study_class,
         teacher=cls.teacher,
         subject=cls.subject)
     cls.current_calendar = AcademicYearCalendarFactory()
     cls.label = LabelFactory(user_role=UserProfile.UserRoles.STUDENT,
                              text='good')
     cls.label2 = LabelFactory(user_role=UserProfile.UserRoles.STUDENT,
                               text='v good')
     cls.subject_through = ProgramSubjectThroughFactory(
         subject=cls.subject,
         class_grade='IX',
         class_grade_arabic=9,
         is_mandatory=True,
         generic_academic_program=cls.study_class.academic_program.
         generic_academic_program,
         weekly_hours_count=1,
     )
     cls.differences_event = SchoolEventFactory(
         event_type=SchoolEvent.EventTypes.DIFERENTE,
         semester=cls.current_calendar.first_semester,
         academic_year_calendar=cls.current_calendar,
         starts_at=datetime.date(2019, 12, 21),
         ends_at=datetime.date(2019, 12, 23))
     cls.second_examination_event = SchoolEventFactory(
         event_type=SchoolEvent.EventTypes.CORIGENTE,
         academic_year_calendar=cls.current_calendar,
         starts_at=datetime.date(2020, 5, 4),
         ends_at=datetime.date(2020, 5, 7))
     cls.catalog_per_year = StudentCatalogPerYearFactory(
         study_class=cls.study_class, student=cls.student)
     cls.file_name = 'file.csv'
    def test_own_child_school_situation_filter_by_academic_year(self):
        self.client.login(username=self.parent.username, password='******')

        StudentCatalogPerSubjectFactory(
            student=self.student, academic_year=self.calendar.academic_year)
        past_study_class = StudyClassFactory(
            school_unit=self.school_unit,
            class_grade='IX',
            class_grade_arabic=9,
            academic_year=self.calendar.academic_year - 1)
        StudentCatalogPerYearFactory(student=self.student,
                                     study_class=past_study_class)
        past_catalog = StudentCatalogPerSubjectFactory(
            student=self.student,
            study_class=past_study_class,
            academic_year=self.calendar.academic_year - 1)
        ProgramSubjectThroughFactory(
            academic_program=past_study_class.academic_program,
            class_grade=past_study_class.class_grade,
            subject=past_catalog.subject,
            weekly_hours_count=4)

        response = self.client.get(
            self.build_url(self.student.id),
            {'academic_year': self.calendar.academic_year - 1})
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertEqual(response.data['study_class']['class_grade'], 'IX')
        self.assertEqual(response.data['study_class']['academic_program_name'],
                         past_study_class.academic_program_name)
        self.assertEqual(len(response.data['catalogs_per_subjects']), 1)
        self.assertEqual(response.data['catalogs_per_subjects'][0]['id'],
                         past_catalog.id)
        self.assertEqual(
            response.data['catalogs_per_subjects'][0]['avg_limit'], 5)
        self.assertEqual(
            response.data['catalogs_per_subjects'][0]
            ['third_of_hours_count_sem1'], 20)
        self.assertEqual(
            response.data['catalogs_per_subjects'][0]
            ['third_of_hours_count_sem2'], 20)
        self.assertEqual(
            response.data['catalogs_per_subjects'][0]
            ['third_of_hours_count_annual'], 40)
Example #19
0
    def test_grade_update_highschool_school_averages(self, mocked_method):
        # This is for an optional subject with weekly hours count = 3 and with thesis (2nd semester)
        self.client.login(username=self.teacher.username, password='******')

        self.study_class.class_grade = 'IX'
        self.study_class.class_grade_arabic = 9
        self.study_class.save()
        ProgramSubjectThroughFactory(
            academic_program=self.study_class.academic_program,
            subject=self.subject,
            weekly_hours_count=3)
        for i in range(3):
            SubjectGradeFactory(student=self.student,
                                catalog_per_subject=self.catalog,
                                semester=2,
                                grade=9)
        grade = SubjectGradeFactory(student=self.student,
                                    catalog_per_subject=self.catalog,
                                    semester=2,
                                    grade=6,
                                    grade_type=SubjectGrade.GradeTypes.THESIS)
        self.catalog.avg_sem1 = 9
        self.catalog.avg_sem2 = 8
        self.catalog.avg_annual = 8.5
        self.catalog.avg_final = 8.5
        self.catalog.wants_thesis = True
        self.catalog.save()

        response = self.client.put(self.build_url(grade.id), self.data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.refresh_objects_from_db([
            self.catalog, self.catalog_per_year, self.study_class,
            self.study_class.academic_program, self.school_stats
        ])
        for obj in [
                self.catalog, self.catalog_per_year, self.study_class,
                self.study_class.academic_program, self.school_stats
        ]:
            self.assertEqual(obj.avg_sem1, 9)
            self.assertEqual(obj.avg_sem2, 9)
            self.assertEqual(obj.avg_annual, 9)
        self.assertEqual(self.catalog.avg_final, 9)
        self.assertEqual(self.catalog_per_year.avg_final, 9)
    def test_grade_create_highschool_averages(self, mocked_method):
        # This is for a required subject with weekly hours count = 3 and with thesis (2nd semester)
        self.study_class.class_grade = 'IX'
        self.study_class.class_grade_arabic = 9
        self.study_class.save()
        ProgramSubjectThroughFactory(generic_academic_program=self.study_class.
                                     academic_program.generic_academic_program,
                                     subject=self.subject,
                                     weekly_hours_count=3)
        self.catalog.avg_sem1 = 10
        self.catalog.wants_thesis = True
        self.catalog.save()

        for i in range(3):
            SubjectGradeFactory(student=self.student,
                                catalog_per_subject=self.catalog,
                                semester=2,
                                grade=9)

        self.client.login(username=self.teacher.username, password='******')
        self.data['taken_at'] = date(2020, 4, 5)
        self.data['grade_type'] = SubjectGrade.GradeTypes.THESIS

        response = self.client.post(self.build_url(self.catalog.id), self.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.refresh_objects_from_db([
            self.catalog, self.catalog_per_year, self.study_class,
            self.study_class.academic_program, self.school_stats
        ])
        for catalog in [self.catalog, self.catalog_per_year]:
            self.assertEqual(catalog.avg_sem1, 10)
            self.assertEqual(catalog.avg_sem2, 9)
            self.assertEqual(catalog.avg_annual, 9.5)
            self.assertEqual(catalog.avg_final, 9.5)
        for obj in [
                self.study_class, self.study_class.academic_program,
                self.school_stats
        ]:
            self.assertEqual(obj.avg_sem1, 10)
            self.assertEqual(obj.avg_sem2, 9)
            self.assertEqual(obj.avg_annual, 9.5)
    def setUpTestData(cls):
        cls.calendar = AcademicYearCalendarFactory()
        cls.school_unit = RegisteredSchoolUnitFactory()
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit,
                                            class_grade='IX',
                                            class_grade_arabic=9)

        cls.parent = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT,
                                        school_unit=cls.school_unit)
        cls.student = UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            school_unit=cls.school_unit,
            student_in_class=cls.study_class)
        cls.student.parents.add(cls.parent)

        StudentCatalogPerYearFactory(student=cls.student,
                                     study_class=cls.study_class)
        cls.student_catalog_per_subject = StudentCatalogPerSubjectFactory(
            student=cls.student, study_class=cls.study_class)
        ProgramSubjectThroughFactory(
            academic_program=cls.study_class.academic_program,
            class_grade=cls.study_class.class_grade,
            subject=cls.student_catalog_per_subject.subject,
            weekly_hours_count=5)
    def test_difference_subject_list_success(self, today):
        self.client.login(username=self.principal.username, password='******')
        semester = 1 if today == timezone.datetime(2019, 12, 1) else 2

        subject1 = SubjectFactory()
        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject1,
            class_grade_arabic=9,
            class_grade='IX')

        subject2 = SubjectFactory()
        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject2,
            class_grade_arabic=9,
            class_grade='IX')
        StudentCatalogPerSubjectFactory(student=self.student,
                                        study_class=StudyClassFactory(
                                            class_grade='IX',
                                            class_grade_arabic=9),
                                        subject=subject2)

        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject2,
            class_grade_arabic=10,
            class_grade='X')

        subject4 = SubjectFactory()
        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject4,
            class_grade_arabic=10,
            class_grade='X')

        subject5 = SubjectFactory()
        ProgramSubjectThroughFactory(
            subject=subject5,
            generic_academic_program=self.generic_academic_program,
            class_grade_arabic=11,
            class_grade='XI')

        subject6 = SubjectFactory()
        ProgramSubjectThroughFactory(
            subject=subject6,
            generic_academic_program=self.generic_academic_program,
            class_grade_arabic=12,
            class_grade='XII')

        with patch('django.utils.timezone.now',
                   return_value=today.replace(tzinfo=utc)) as mocked_method:
            response = self.client.get(
                self.build_url(self.student.id, self.study_class.id))

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        if semester == 1:
            expected_grades = ['IX', 'X']
            self.assertCountEqual(
                [subject['id'] for subject in response.data['IX']],
                [subject1.id])
            self.assertCountEqual(
                [subject['id'] for subject in response.data['X']],
                [subject2.id, subject4.id])
        else:
            expected_grades = ['IX', 'X', 'XI']
            self.assertCountEqual(
                [subject['id'] for subject in response.data['IX']],
                [subject1.id])
            self.assertCountEqual(
                [subject['id'] for subject in response.data['X']],
                [subject2.id, subject4.id])
            self.assertCountEqual(
                [subject['id'] for subject in response.data['XI']],
                [subject5.id])

        self.assertCountEqual(response.data.keys(), expected_grades)
        subject_expected_fields = ['id', 'name']
        for subject_list in response.data.values():
            for subject in subject_list:
                self.assertCountEqual(subject.keys(), subject_expected_fields)

        StudentCatalogPerSubjectFactory(student=self.student,
                                        study_class=StudyClassFactory(
                                            class_grade='X',
                                            class_grade_arabic=10),
                                        subject=subject4)

        with patch('django.utils.timezone.now',
                   return_value=today.replace(tzinfo=utc)) as mocked_method:
            response = self.client.get(
                self.build_url(self.student.id, self.study_class.id))

        self.assertEqual(response.status_code, status.HTTP_200_OK)
        if semester == 1:
            expected_grades = ['IX', 'X']
        else:
            expected_grades = ['IX', 'X', 'XI']

        self.assertCountEqual(
            [subject['id'] for subject in response.data['X']], [subject2.id])
        self.assertCountEqual(response.data.keys(), expected_grades)
Example #23
0
    def test_bulk_create_grade_highschool_averages(self, timezone_mock):
        # This is for a required subject with weekly hours count = 3 and with thesis (2nd semester)
        self.study_class.class_grade = 'IX'
        self.study_class.class_grade_arabic = 9
        self.study_class.save()
        ProgramSubjectThroughFactory(generic_academic_program=self.study_class.
                                     academic_program.generic_academic_program,
                                     subject=self.subject,
                                     weekly_hours_count=3)
        for catalog in [self.catalog1, self.catalog2]:
            catalog.avg_sem1 = 10
            catalog.wants_thesis = True
            catalog.save()
        SubjectGradeFactory(student=self.student1,
                            catalog_per_subject=self.catalog1,
                            semester=2,
                            grade=10,
                            grade_type=SubjectGrade.GradeTypes.THESIS)
        SubjectGradeFactory(student=self.student2,
                            catalog_per_subject=self.catalog2,
                            semester=2,
                            grade=10,
                            grade_type=SubjectGrade.GradeTypes.THESIS)

        self.client.login(username=self.teacher.username, password='******')
        self.request_data = {
            "taken_at":
            date(2020, 4, 5),
            "student_grades": [{
                "student": self.student1.id,
                "grade": 10
            }, {
                "student": self.student1.id,
                "grade": 9
            }, {
                "student": self.student1.id,
                "grade": 9
            }, {
                "student": self.student2.id,
                "grade": 10
            }]
        }

        response = self.client.post(self.build_url(self.study_class.id,
                                                   self.subject.id),
                                    data=self.request_data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.refresh_objects_from_db([
            self.catalog1, self.catalog2, self.catalog_per_year1,
            self.catalog_per_year2, self.study_class,
            self.study_class.academic_program, self.school_stats
        ])
        for catalog in [self.catalog1, self.catalog_per_year1]:
            self.assertEqual(catalog.avg_sem1, 10)
            # This is a 9.49 situation
            self.assertEqual(catalog.avg_sem2, 9)
            self.assertEqual(catalog.avg_annual, 9.5)
            self.assertEqual(catalog.avg_final, 9.5)
        for catalog in [self.catalog2, self.catalog_per_year2]:
            self.assertEqual(catalog.avg_sem1, 10)
            self.assertIsNone(catalog.avg_sem2)
            self.assertIsNone(catalog.avg_annual)
            self.assertIsNone(catalog.avg_final)
        for obj in [
                self.study_class, self.study_class.academic_program,
                self.school_stats
        ]:
            self.assertEqual(obj.avg_sem1, Decimal('10'))
            self.assertEqual(obj.avg_sem2, Decimal('9'))
            self.assertEqual(obj.avg_annual, Decimal('9.5'))
    def test_study_class_cloned_to_next_year_success(self):
        self.client.login(username=self.principal.username, password='******')

        subject1 = SubjectFactory(name='Subject B')
        subject2 = SubjectFactory(name='Subject C')
        subject3 = SubjectFactory(name='Subject A')
        ProgramSubjectThroughFactory(subject=subject1, academic_program=self.current_year_program, class_grade='VII', class_grade_arabic=7, is_mandatory=False)
        ProgramSubjectThroughFactory(subject=subject2, academic_program=self.current_year_program, class_grade='VII', class_grade_arabic=7, is_mandatory=False)
        ProgramSubjectThroughFactory(subject=subject3, generic_academic_program=self.current_year_program.generic_academic_program,
                                     class_grade='VII', class_grade_arabic=7)

        student1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student B', student_in_class=self.study_class)
        StudentCatalogPerYearFactory(student=student1, study_class=self.study_class)

        # Behavior grade below 6
        student2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student C', student_in_class=self.study_class)
        StudentCatalogPerYearFactory(student=student2, study_class=self.study_class, behavior_grade_annual=5)

        student3 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student A', student_in_class=self.study_class)
        StudentCatalogPerYearFactory(student=student3, study_class=self.study_class)

        # No average
        student4 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student E', student_in_class=self.study_class)
        StudentCatalogPerYearFactory(student=student4, study_class=self.study_class)
        StudentCatalogPerSubjectFactory(student=student4, subject=subject1, study_class=self.study_class)

        # Average below 5
        student5 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student D', student_in_class=self.study_class)
        StudentCatalogPerYearFactory(student=student5, study_class=self.study_class)
        StudentCatalogPerSubjectFactory(student=student5, subject=subject2, study_class=self.study_class, avg_final=4)

        response = self.client.get(self.build_url(self.study_class.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.assertCountEqual(response.data.keys(), ['class_grade', 'class_letter', 'academic_program', 'academic_program_name',
                                                     'class_master', 'subjects', 'students'])
        self.assertCountEqual(response.data['class_master'].keys(), ['id', 'full_name'])
        for subject in response.data['subjects']:
            self.assertCountEqual(subject.keys(), ['subject_id', 'subject_name', 'is_mandatory'])
        for subject in response.data['students']:
            self.assertCountEqual(subject.keys(), ['id', 'full_name'])

        self.assertEqual(response.data['class_grade'], 'VII')
        self.assertEqual(response.data['class_letter'], 'A')
        self.assertEqual(response.data['academic_program'], self.current_year_program.id)
        self.assertEqual(response.data['academic_program_name'], self.current_year_program.name)
        self.assertEqual(response.data['class_master']['id'], self.study_class.class_master_id)

        subjects_response = response.data['subjects']
        self.assertEqual(len(subjects_response), 3)
        self.assertEqual(subjects_response[0]['subject_id'], subject3.id)
        self.assertTrue(subjects_response[0]['is_mandatory'])
        self.assertEqual(subjects_response[1]['subject_id'], subject1.id)
        self.assertFalse(subjects_response[1]['is_mandatory'])
        self.assertEqual(subjects_response[2]['subject_id'], subject2.id)
        self.assertFalse(subjects_response[2]['is_mandatory'])

        students_response = response.data['students']
        self.assertEqual(len(students_response), 2)
        self.assertEqual(students_response[0]['id'], student3.id)
        self.assertEqual(students_response[1]['id'], student1.id)
    def test_own_child_subjects_at_risk_success(self):
        self.client.login(username=self.parent.username, password='******')

        subject1 = SubjectFactory(name='B')
        catalog1 = StudentCatalogPerSubjectFactory(
            student=self.student,
            subject=subject1,
            study_class=self.study_class,
            is_at_risk=True,
            unfounded_abs_count_sem1=2,
            unfounded_abs_count_annual=2)
        ProgramSubjectThroughFactory(
            academic_program=self.study_class.academic_program,
            class_grade=self.study_class.class_grade,
            subject=subject1,
            weekly_hours_count=5)

        subject2 = SubjectFactory(name='A', is_coordination=True)
        catalog2 = StudentCatalogPerSubjectFactory(
            student=self.student,
            subject=subject2,
            is_coordination_subject=True,
            study_class=self.study_class,
            is_at_risk=True,
            unfounded_abs_count_sem1=1,
            unfounded_abs_count_annual=1)
        ProgramSubjectThroughFactory(
            academic_program=self.study_class.academic_program,
            class_grade=self.study_class.class_grade,
            subject=subject2,
            weekly_hours_count=1)

        StudentCatalogPerSubjectFactory(student=self.student,
                                        study_class=self.study_class,
                                        is_at_risk=False)

        expected_fields = [
            'id', 'subject_name', 'avg_sem1', 'avg_final', 'avg_limit',
            'unfounded_abs_count_sem1', 'unfounded_abs_count_annual',
            'third_of_hours_count_sem1', 'third_of_hours_count_annual'
        ]

        response = self.client.get(self.build_url(self.student.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 2)
        for catalog in response.data['results']:
            self.assertCountEqual(catalog.keys(), expected_fields)

        self.assertEqual(response.data['results'][0]['id'], catalog1.id)
        self.assertEqual(response.data['results'][0]['avg_limit'], 5)
        self.assertEqual(
            response.data['results'][0]['third_of_hours_count_sem1'], 25)
        self.assertEqual(
            response.data['results'][0]['third_of_hours_count_annual'], 50)

        self.assertEqual(response.data['results'][1]['id'], catalog2.id)
        self.assertEqual(response.data['results'][1]['avg_limit'], 6)
        self.assertEqual(
            response.data['results'][1]['third_of_hours_count_sem1'], 5)
        self.assertEqual(
            response.data['results'][1]['third_of_hours_count_annual'], 10)
    def test_grade_create_second_examinations_count(self, timezone_mock):
        for avg in [4, 5, 6, 10]:
            StudentCatalogPerSubjectFactory(student=self.student,
                                            study_class=self.study_class,
                                            avg_sem1=avg,
                                            avg_sem2=avg)

        self.school_unit.academic_profile = SchoolUnitProfileFactory(
            name='Artistic')
        self.school_unit.save()
        self.study_class.class_grade = 'IX'
        self.study_class.class_grade_arabic = 9
        self.study_class.save()
        ProgramSubjectThroughFactory(generic_academic_program=self.study_class.
                                     academic_program.generic_academic_program,
                                     subject=self.subject,
                                     weekly_hours_count=1)
        self.study_class.academic_program.core_subject = self.subject
        self.study_class.academic_program.save()
        self.catalog.avg_sem1 = 5
        self.catalog.save()

        self.client.login(username=self.teacher.username, password='******')
        self.data['taken_at'] = date(2020, 4, 5)

        response = self.client.post(self.build_url(self.catalog.id), self.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.catalog_per_year.refresh_from_db()
        self.assertEqual(self.catalog_per_year.second_examinations_count, 3)

        # Check labels
        catalog = StudentCatalogPerSubject.objects.get(
            student=self.student,
            study_class=self.study_class,
            avg_sem1=4,
            avg_sem2=4)
        catalog.avg_sem1 = 5
        catalog.save()

        response = self.client.post(self.build_url(self.catalog.id), self.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.catalog_per_year.refresh_from_db()
        self.assertEqual(self.catalog_per_year.second_examinations_count, 2)
        self.assertCountEqual(
            self.student.labels.all(),
            Label.objects.filter(text=FAILING_2_SUBJECTS_LABEL))

        catalog.avg_sem2 = 5
        catalog.save()

        response = self.client.post(self.build_url(self.catalog.id), self.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.catalog_per_year.refresh_from_db()
        self.assertEqual(self.catalog_per_year.second_examinations_count, 1)
        self.assertCountEqual(
            self.student.labels.all(),
            Label.objects.filter(text=FAILING_1_SUBJECT_LABEL))

        self.catalog.avg_sem1 = 6
        self.catalog.save()

        response = self.client.post(self.build_url(self.catalog.id), self.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.catalog_per_year.refresh_from_db()
        self.assertEqual(self.catalog_per_year.second_examinations_count, 0)
        self.assertEqual(self.student.labels.count(), 0)
Example #27
0
    def test_own_study_class_pupil_detail_success(self):
        self.client.login(username=self.teacher.username, password='******')
        parent = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT,
                                    school_unit=self.school_unit)
        self.student.parents.add(parent)
        label = LabelFactory(user_role=UserProfile.UserRoles.STUDENT)
        self.student.labels.add(label)

        coordination_subject = SubjectFactory(name='Dirigentie',
                                              is_coordination=True)
        subject1 = SubjectFactory(name='Subject')
        subject2 = SubjectFactory(name='Another Subject')
        subject3 = SubjectFactory(name='Optional Subject')
        teacher2 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER,
                                      school_unit=self.school_unit)

        TeacherClassThroughFactory(study_class=self.study_class,
                                   teacher=self.teacher,
                                   subject=coordination_subject,
                                   is_class_master=True)
        TeacherClassThroughFactory(study_class=self.study_class,
                                   teacher=self.teacher,
                                   subject=subject1,
                                   is_class_master=True)
        TeacherClassThroughFactory(study_class=self.study_class,
                                   teacher=teacher2,
                                   subject=subject2)
        TeacherClassThroughFactory(study_class=self.study_class,
                                   teacher=teacher2,
                                   subject=subject3)

        catalog1 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.teacher,
            study_class=self.study_class,
            subject=coordination_subject)
        catalog2 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.teacher,
            study_class=self.study_class,
            subject=subject1)
        catalog3 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=teacher2,
            study_class=self.study_class,
            subject=subject2)
        StudentCatalogPerSubjectFactory(student=self.student,
                                        teacher=teacher2,
                                        study_class=self.study_class,
                                        subject=subject3,
                                        is_enrolled=False)
        for subject in [subject1, subject2]:
            ProgramSubjectThroughFactory(
                academic_program=self.study_class.academic_program,
                class_grade=self.study_class.class_grade,
                subject=subject,
                weekly_hours_count=1)

        yesterday = timezone.now().date() - timezone.timedelta(days=1)
        grade1 = SubjectGradeFactory(student=self.student,
                                     catalog_per_subject=catalog2)
        grade2 = SubjectGradeFactory(student=self.student,
                                     catalog_per_subject=catalog2,
                                     taken_at=yesterday)
        grade3 = SubjectGradeFactory(student=self.student,
                                     catalog_per_subject=catalog2,
                                     semester=2,
                                     taken_at=yesterday)
        grade4 = SubjectGradeFactory(student=self.student,
                                     catalog_per_subject=catalog2,
                                     semester=2)

        exam_grade1 = ExaminationGradeFactory(student=self.student,
                                              catalog_per_subject=catalog2)
        exam_grade2 = ExaminationGradeFactory(
            student=self.student,
            catalog_per_subject=catalog2,
            examination_type=ExaminationGrade.ExaminationTypes.ORAL)
        exam_grade3 = ExaminationGradeFactory(
            student=self.student,
            catalog_per_subject=catalog2,
            taken_at=yesterday,
            grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
            semester=1)
        exam_grade4 = ExaminationGradeFactory(
            student=self.student,
            catalog_per_subject=catalog2,
            examination_type=ExaminationGrade.ExaminationTypes.ORAL,
            grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
            semester=1)
        exam_grade5 = ExaminationGradeFactory(
            student=self.student,
            catalog_per_subject=catalog2,
            semester=2,
            grade_type=ExaminationGrade.GradeTypes.DIFFERENCE)
        exam_grade6 = ExaminationGradeFactory(
            student=self.student,
            catalog_per_subject=catalog2,
            taken_at=yesterday,
            semester=2,
            examination_type=ExaminationGrade.ExaminationTypes.ORAL,
            grade_type=ExaminationGrade.GradeTypes.DIFFERENCE)

        abs1 = SubjectAbsenceFactory(student=self.student,
                                     catalog_per_subject=catalog2)
        abs2 = SubjectAbsenceFactory(student=self.student,
                                     catalog_per_subject=catalog2,
                                     taken_at=yesterday)
        abs3 = SubjectAbsenceFactory(student=self.student,
                                     catalog_per_subject=catalog2,
                                     semester=2,
                                     taken_at=yesterday)
        abs4 = SubjectAbsenceFactory(student=self.student,
                                     catalog_per_subject=catalog2,
                                     semester=2)

        response = self.client.get(
            self.build_url(self.study_class.id, self.student.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        expected_fields = [
            'id', 'full_name', 'parents', 'labels', 'risk_description',
            'study_class', 'catalogs_per_subjects'
        ]
        catalog_expected_fields = [
            'id', 'subject_name', 'teacher', 'avg_sem1', 'avg_sem2',
            'avg_annual', 'avg_after_2nd_examination', 'avg_limit',
            'grades_sem1', 'grades_sem2', 'second_examination_grades',
            'difference_grades_sem1', 'difference_grades_sem2',
            'abs_count_sem1', 'abs_count_sem2', 'abs_count_annual',
            'founded_abs_count_sem1', 'founded_abs_count_sem2',
            'founded_abs_count_annual', 'unfounded_abs_count_sem1',
            'unfounded_abs_count_sem2', 'unfounded_abs_count_annual',
            'third_of_hours_count_sem1', 'third_of_hours_count_sem2',
            'third_of_hours_count_annual', 'abs_sem1', 'abs_sem2',
            'wants_thesis', 'is_exempted', 'is_coordination_subject'
        ]
        profile_expected_fields = ['id', 'full_name']
        label_expected_fields = ['id', 'text']
        study_class_expected_fields = ['id', 'class_grade', 'class_letter']
        grade_expected_fields = [
            'id', 'grade', 'taken_at', 'grade_type', 'created'
        ]
        absence_expected_fields = ['id', 'taken_at', 'is_founded', 'created']
        exam_grade_expected_fields = [
            'id', 'examination_type', 'grade1', 'grade2', 'taken_at', 'created'
        ]

        self.assertCountEqual(response.data.keys(), expected_fields)
        self.assertEqual(len(response.data['parents']), 1)
        self.assertCountEqual(response.data['parents'][0].keys(),
                              profile_expected_fields)
        self.assertEqual(len(response.data['labels']), 1)
        self.assertCountEqual(response.data['labels'][0].keys(),
                              label_expected_fields)
        self.assertCountEqual(response.data['study_class'].keys(),
                              study_class_expected_fields)
        catalogs_per_subjects = response.data['catalogs_per_subjects']
        self.assertEqual(len(catalogs_per_subjects), 3)

        for catalog_data in catalogs_per_subjects:
            self.assertCountEqual(catalog_data.keys(), catalog_expected_fields)
            self.assertCountEqual(catalog_data['teacher'].keys(),
                                  profile_expected_fields)
            self.assertEqual(catalog_data['avg_limit'],
                             6 if catalog_data['id'] == catalog1.id else 5)
            self.assertEqual(catalog_data['third_of_hours_count_sem1'], 5)
            self.assertEqual(catalog_data['third_of_hours_count_sem2'], 5)
            self.assertEqual(catalog_data['third_of_hours_count_annual'], 10)

        self.assertEqual(catalogs_per_subjects[0]['id'], catalog1.id)
        self.assertEqual(catalogs_per_subjects[0]['teacher']['id'],
                         self.teacher.id)
        self.assertEqual(catalogs_per_subjects[0]['subject_name'],
                         coordination_subject.name)
        self.assertEqual(catalogs_per_subjects[1]['id'], catalog3.id)
        self.assertEqual(catalogs_per_subjects[1]['teacher']['id'],
                         teacher2.id)
        self.assertEqual(catalogs_per_subjects[1]['subject_name'],
                         subject2.name)
        self.assertEqual(catalogs_per_subjects[2]['id'], catalog2.id)
        self.assertEqual(catalogs_per_subjects[2]['teacher']['id'],
                         self.teacher.id)
        self.assertEqual(catalogs_per_subjects[2]['subject_name'],
                         subject1.name)

        for grade_data in catalogs_per_subjects[2][
                'grades_sem1'] + catalogs_per_subjects[2]['grades_sem2']:
            self.assertCountEqual(grade_data.keys(), grade_expected_fields)

        for abs_data in catalogs_per_subjects[2][
                'abs_sem1'] + catalogs_per_subjects[2]['abs_sem2']:
            self.assertCountEqual(abs_data.keys(), absence_expected_fields)

        for exam_grade_data in catalogs_per_subjects[2]['second_examination_grades'] + \
                               catalogs_per_subjects[2]['difference_grades_sem1'] + catalogs_per_subjects[2]['difference_grades_sem2']:
            self.assertCountEqual(exam_grade_data.keys(),
                                  exam_grade_expected_fields)

        self.assertEqual(catalogs_per_subjects[2]['grades_sem1'][0]['id'],
                         grade1.id)
        self.assertEqual(catalogs_per_subjects[2]['grades_sem1'][1]['id'],
                         grade2.id)
        self.assertEqual(catalogs_per_subjects[2]['grades_sem2'][0]['id'],
                         grade4.id)
        self.assertEqual(catalogs_per_subjects[2]['grades_sem2'][1]['id'],
                         grade3.id)

        self.assertEqual(catalogs_per_subjects[2]['abs_sem1'][0]['id'],
                         abs1.id)
        self.assertEqual(catalogs_per_subjects[2]['abs_sem1'][1]['id'],
                         abs2.id)
        self.assertEqual(catalogs_per_subjects[2]['abs_sem2'][0]['id'],
                         abs4.id)
        self.assertEqual(catalogs_per_subjects[2]['abs_sem2'][1]['id'],
                         abs3.id)

        self.assertEqual(
            catalogs_per_subjects[2]['second_examination_grades'][0]['id'],
            exam_grade2.id)
        self.assertEqual(
            catalogs_per_subjects[2]['second_examination_grades'][1]['id'],
            exam_grade1.id)
        self.assertEqual(
            catalogs_per_subjects[2]['difference_grades_sem1'][0]['id'],
            exam_grade4.id)
        self.assertEqual(
            catalogs_per_subjects[2]['difference_grades_sem1'][1]['id'],
            exam_grade3.id)
        self.assertEqual(
            catalogs_per_subjects[2]['difference_grades_sem2'][0]['id'],
            exam_grade5.id)
        self.assertEqual(
            catalogs_per_subjects[2]['difference_grades_sem2'][1]['id'],
            exam_grade6.id)
    def setUpTestData(cls):
        cls.principal = UserProfileFactory(
            user_role=UserProfile.UserRoles.PRINCIPAL)
        cls.school_unit = RegisteredSchoolUnitFactory(
            school_principal=cls.principal)

        cls.category1 = SchoolUnitCategoryFactory(
            category_level=SchoolUnitCategory.CategoryLevels.PRIMARY_SCHOOL)
        cls.category2 = SchoolUnitCategoryFactory(
            category_level=SchoolUnitCategory.CategoryLevels.SECONDARY_SCHOOL)
        cls.category3 = SchoolUnitCategoryFactory(
            category_level=SchoolUnitCategory.CategoryLevels.HIGHSCHOOL)
        cls.school_unit.categories.add(cls.category1, cls.category2,
                                       cls.category3)

        cls.calendar = AcademicYearCalendarFactory()

        cls.subject1 = SubjectFactory()
        cls.subject2 = SubjectFactory()
        cls.coordination_subject = SubjectFactory(is_coordination=True)
        cls.academic_program = AcademicProgramFactory(
            school_unit=cls.school_unit)
        for class_grade, class_grade_arabic in zip(['I', 'VI', 'IX'],
                                                   [1, 6, 9]):
            ProgramSubjectThroughFactory(academic_program=cls.academic_program,
                                         subject=cls.subject1,
                                         is_mandatory=False,
                                         class_grade=class_grade,
                                         class_grade_arabic=class_grade_arabic)
            ProgramSubjectThroughFactory(
                generic_academic_program=cls.academic_program.
                generic_academic_program,
                subject=cls.subject2,
                class_grade=class_grade,
                class_grade_arabic=class_grade_arabic)

        cls.teacher1 = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.teacher2 = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.teacher1.taught_subjects.add(cls.subject1)
        cls.teacher2.taught_subjects.add(cls.subject2)

        cls.student1 = UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            school_unit=cls.school_unit)
        cls.student2 = UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            school_unit=cls.school_unit)

        cls.url = reverse('study_classes:study-class-list',
                          kwargs={'academic_year': cls.calendar.academic_year})

        cls.class_master = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.primary_school_request_data = {
            'class_grade':
            'I',
            'class_letter':
            'A',
            'academic_program':
            cls.academic_program.id,
            "class_master":
            cls.class_master.id,
            "teachers_class_through": [{
                "teacher": cls.teacher1.id,
                "subject": cls.subject1.id
            }, {
                "teacher": cls.teacher2.id,
                "subject": cls.subject2.id
            }],
            "students": [cls.student1.id, cls.student2.id]
        }
        cls.secondary_school_request_data = {
            'class_grade':
            'VI',
            'class_letter':
            'A1',
            'academic_program':
            cls.academic_program.id,
            "class_master":
            cls.class_master.id,
            "teachers_class_through": [{
                "teacher": cls.teacher1.id,
                "subject": cls.subject1.id
            }, {
                "teacher": cls.teacher2.id,
                "subject": cls.subject2.id
            }],
            "students": [cls.student1.id, cls.student2.id]
        }