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'
        ]
    def test_own_students_averages_second_semester(self, mocked_method):
        self.client.login(username=self.teacher.username, password='******')

        catalog1 = StudentCatalogPerYearFactory(student=UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            school_unit=self.school_unit,
            student_in_class=self.study_class),
                                                study_class=self.study_class,
                                                avg_sem1=9,
                                                avg_final=8)
        catalog2 = StudentCatalogPerYearFactory(student=UserProfileFactory(
            user_role=UserProfile.UserRoles.STUDENT,
            school_unit=self.school_unit,
            student_in_class=self.study_class),
                                                study_class=self.study_class,
                                                avg_sem1=8,
                                                avg_final=9)

        response = self.client.get(self.url)
        self.assertEqual(len(response.data['results']), 2)
        for catalog in response.data['results']:
            self.assertCountEqual(catalog.keys(), self.expected_fields)
            self.assertCountEqual(catalog['student'].keys(),
                                  self.student_expected_fields)

        self.assertEqual(response.data['results'][0]['id'], catalog2.id)
        self.assertEqual(response.data['results'][1]['id'], catalog1.id)
예제 #3
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)
 def setUpTestData(cls):
     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_master=cls.teacher)
     cls.teacher_class_through = TeacherClassThroughFactory(
         study_class=cls.study_class,
         teacher=cls.teacher,
         is_class_master=True,
     )
     cls.catalog1 = StudentCatalogPerYearFactory(
         student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='a'),
         study_class=cls.study_class,
         academic_year=2020,
         avg_sem1=1,
         avg_sem2=1,
         avg_final=1,
         abs_count_sem1=1,
         abs_count_sem2=1,
         abs_count_annual=1
     )
     cls.catalog2 = StudentCatalogPerYearFactory(
         student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='b'),
         study_class=cls.study_class,
         academic_year=2020,
         avg_sem1=2,
         avg_sem2=2,
         avg_final=2,
         abs_count_sem1=2,
         abs_count_sem2=2,
         abs_count_annual=2
     )
     cls.catalog3 = StudentCatalogPerYearFactory(
         student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='c'),
         study_class=cls.study_class,
         academic_year=2020,
         avg_sem1=3,
         avg_sem2=3,
         avg_final=3,
         abs_count_sem1=3,
         abs_count_sem2=3,
         abs_count_annual=3
     )
     cls.catalog4 = StudentCatalogPerYearFactory(
         student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='d'),
         study_class=cls.study_class,
         academic_year=2020,
         avg_sem1=4,
         avg_sem2=4,
         avg_final=4,
         abs_count_sem1=4,
         abs_count_sem2=4,
         abs_count_annual=4
     )
예제 #5
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)
예제 #6
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'
        ]
예제 #7
0
    def test_study_class_partially_update_move_student_from_different_school(self):
        self.client.login(username=self.principal.username, password='******')

        self.new_student.labels.add(
            LabelFactory(text=TRANSFERRED_LABEL, is_label_for_transfers_between_schools=True)
        )
        another_school_unit = RegisteredSchoolUnitFactory()
        another_school_profile = UserProfileFactory(school_unit=another_school_unit, full_name=self.new_student.full_name,
                                                    username='******'.format(another_school_unit.id, self.new_student.email),
                                                    email=self.new_student.email,
                                                    phone_number=self.new_student.phone_number, user_role=UserProfile.UserRoles.STUDENT)

        prev_study_class = StudyClassFactory(school_unit=self.school_unit, class_master=self.teacher1, academic_program=self.academic_program,
                                             class_grade='IX', class_grade_arabic=9, class_letter='A', academic_year=self.calendar.academic_year - 1)
        TeacherClassThroughFactory(study_class=prev_study_class, teacher=self.teacher1, subject=self.coordination_subject, is_class_master=True)
        TeacherClassThroughFactory(study_class=prev_study_class, teacher=self.teacher1, subject=self.subject1, is_class_master=True)
        TeacherClassThroughFactory(study_class=prev_study_class, teacher=self.teacher2, subject=self.subject2, is_class_master=True,
                                   is_optional_subject=True)

        student_prev_study_class = StudyClassFactory(school_unit=another_school_unit, class_grade='IX', class_grade_arabic=9,
                                                     academic_year=self.calendar.academic_year - 1)
        StudentCatalogPerYearFactory(student=another_school_profile, study_class=student_prev_study_class,
                                     avg_sem1=9, avg_sem2=9, avg_annual=9, avg_final=9)
        catalog1 = StudentCatalogPerSubjectFactory(student=another_school_profile, study_class=student_prev_study_class,
                                                   subject=self.coordination_subject, avg_sem1=8, avg_sem2=8, avg_annual=8, avg_final=8)
        SubjectGradeFactory(student=another_school_profile, catalog_per_subject=catalog1, grade=8)
        SubjectAbsenceFactory(student=another_school_profile, catalog_per_subject=catalog1, is_founded=True)

        catalog2 = StudentCatalogPerSubjectFactory(student=another_school_profile, study_class=student_prev_study_class, subject=self.subject2,
                                                   avg_sem1=10, avg_sem2=10, avg_annual=10, avg_final=10)
        ExaminationGradeFactory(student=another_school_profile, catalog_per_subject=catalog2)

        self.request_data = {
            "new_students": [self.new_student.id]
        }

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

        catalog_per_year = StudentCatalogPerYear.objects.get(student=self.new_student, study_class=prev_study_class)
        for average in [catalog_per_year.avg_sem1, catalog_per_year.avg_sem2, catalog_per_year.avg_annual, catalog_per_year.avg_final]:
            self.assertEqual(average, 9)

        new_catalog1 = StudentCatalogPerSubject.objects.get(student=self.new_student, study_class=prev_study_class,
                                                            subject=self.coordination_subject, teacher=self.teacher1)
        for average in [new_catalog1.avg_sem1, new_catalog1.avg_sem2, new_catalog1.avg_annual, new_catalog1.avg_final]:
            self.assertEqual(average, 8)
        self.assertEqual(new_catalog1.grades.count(), 1)
        self.assertEqual(new_catalog1.absences.count(), 1)

        new_catalog2 = StudentCatalogPerSubject.objects.get(student=self.new_student, study_class=prev_study_class,
                                                            subject=self.subject2, teacher=self.teacher2)
        for average in [new_catalog2.avg_sem1, new_catalog2.avg_sem2, new_catalog2.avg_annual, new_catalog2.avg_final]:
            self.assertEqual(average, 10)
        self.assertEqual(new_catalog2.examination_grades.count(), 1)

        new_catalog3 = StudentCatalogPerSubject.objects.get(student=self.new_student, study_class=prev_study_class,
                                                            subject=self.subject1, teacher=self.teacher1)
        for average in [new_catalog3.avg_sem1, new_catalog3.avg_sem2, new_catalog3.avg_annual, new_catalog3.avg_final]:
            self.assertEqual(average, None)
예제 #8
0
    def test_move_student_possible_study_classes_no_possible_classes(self):
        self.client.login(username=self.principal.username, password='******')

        # No study classes in the current year
        study_class = StudyClassFactory(
            school_unit=self.school_unit,
            class_grade='IX',
            class_grade_arabic=9,
            academic_year=self.current_class.academic_year - 1
        )

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

        # No study classes with a low enough entry grade
        StudentCatalogPerYearFactory(
            study_class=study_class,
            academic_year=study_class.academic_year - 1,
            avg_final=5.1
        )

        response = self.client.get(self.build_url(self.student.id))
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data, [])
    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
        )
예제 #10
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)
예제 #11
0
 def setUpTestData(cls):
     cls.school_unit = RegisteredSchoolUnitFactory()
     cls.calendar = AcademicYearCalendarFactory()
     cls.student = UserProfileFactory(
         user_role=UserProfile.UserRoles.STUDENT,
         school_unit=cls.school_unit)
     cls.catalog = StudentCatalogPerYearFactory(student=cls.student)
     cls.url = reverse('statistics:own-statistics')
예제 #12
0
 def setUpTestData(cls):
     cls.school_unit = RegisteredSchoolUnitFactory()
     cls.calendar = AcademicYearCalendarFactory()
     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)
     cls.student.parents.add(cls.parent)
     cls.catalog = StudentCatalogPerYearFactory(student=cls.student)
예제 #13
0
    def test_move_student_not_having_required_avg(self):
        self.client.login(username=self.principal.username, password='******')
        previous_year = self.study_class.academic_year - 1
        StudentCatalogPerYearFactory(student=self.student,
                                     academic_year=previous_year,
                                     avg_final=7)
        previous_study_class = StudyClassFactory(school_unit=self.school_unit,
                                                 academic_year=previous_year,
                                                 class_grade='IX',
                                                 class_grade_arabic=9)
        StudentCatalogPerYearFactory(study_class=previous_study_class,
                                     avg_final=8)

        response = self.client.post(
            self.build_url(self.student.id, self.study_class.id), {})
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(
            response.data['message'],
            "This student doesn't have the required average for this study class."
        )
예제 #14
0
    def test_move_student_possible_study_classes_success(self):
        self.client.login(username=self.principal.username, password='******')

        study_class = StudyClassFactory(school_unit=self.school_unit, class_grade='X', class_letter='B', class_grade_arabic=10)
        past_class = StudyClassFactory(school_unit=self.school_unit, class_grade='IX', class_letter='B', class_grade_arabic=9, academic_year=2019)
        StudentCatalogPerYearFactory(study_class=past_class, avg_final=4.8, academic_year=2019)
        StudentCatalogPerYearFactory(study_class=past_class, avg_final=5.1, academic_year=2019)

        other_study_class = StudyClassFactory(school_unit=self.school_unit, class_grade='X', class_letter='C', class_grade_arabic=10)
        past_class = StudyClassFactory(school_unit=self.school_unit, class_grade='IX', class_letter='C', class_grade_arabic=9, academic_year=2019)
        StudentCatalogPerYearFactory(study_class=past_class, avg_final=4.8, academic_year=2019)

        other_study_class1 = StudyClassFactory(school_unit=self.school_unit, class_grade='X', class_letter='D', class_grade_arabic=10)
        past_class = StudyClassFactory(school_unit=self.school_unit, class_grade='IX', class_letter='D', class_grade_arabic=9, academic_year=2019)
        StudentCatalogPerYearFactory(study_class=past_class, avg_final=5.1, academic_year=2019)

        other_study_class2 = StudyClassFactory(school_unit=self.school_unit, class_grade='X', class_letter='E', class_grade_arabic=10)
        past_class = StudyClassFactory(school_unit=self.school_unit, class_grade='IX', class_letter='E', class_grade_arabic=9, academic_year=2019)
        StudentCatalogPerYearFactory(study_class=past_class, avg_final=4.8, academic_year=2019)

        other_study_class3 = StudyClassFactory(school_unit=self.school_unit, class_grade='XI', class_letter='A', class_grade_arabic=11)
        past_class = StudyClassFactory(school_unit=self.school_unit, class_grade='X', class_letter='A', class_grade_arabic=10, academic_year=2019)
        StudentCatalogPerYearFactory(study_class=past_class, avg_final=4.8, academic_year=2019)

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

        self.assertCountEqual([study_class['id'] for study_class in response.data], [study_class.id, other_study_class.id, other_study_class2.id])
        expected_fields = ['id', 'class_grade', 'class_letter']
        for study_class_data in response.data:
            self.assertCountEqual(study_class_data.keys(), expected_fields)

        self.assertEqual(response.data[0]['id'], study_class.id)
        self.assertEqual(response.data[1]['id'], other_study_class.id)
        self.assertEqual(response.data[2]['id'], other_study_class2.id)
예제 #15
0
    def test_move_student_ninth_grade(self):
        self.client.login(username=self.principal.username, password='******')
        for study_class in [self.study_class, self.source_study_class]:
            study_class.class_grade = 'IX'
            study_class.class_grade_arabic = 9
            study_class.save()
        catalog_per_year = StudentCatalogPerYearFactory(
            student=self.student, study_class=self.source_study_class)
        catalog_per_subject1 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.source_study_class.class_master,
            study_class=self.source_study_class,
            subject=self.subject1)
        catalog_per_subject2 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.source_study_class.class_master,
            study_class=self.source_study_class,
            subject=self.subject3)

        response = self.client.post(
            self.build_url(self.student.id, self.study_class.id), {})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertCountEqual(response.data.keys(), self.expected_fields)
        self.assertEqual(response.data['id'], self.source_study_class.id)

        self.refresh_objects_from_db([
            self.student, self.principal, self.school_unit, catalog_per_year,
            catalog_per_subject1, catalog_per_subject2
        ])
        self.assertEqual(self.student.student_in_class, self.study_class)
        self.assertEqual(catalog_per_year.study_class, self.study_class)

        self.assertTrue(catalog_per_subject1.is_enrolled)
        self.assertEqual(catalog_per_subject1.teacher,
                         self.study_class.class_master)
        self.assertEqual(catalog_per_subject1.study_class, self.study_class)

        self.assertFalse(catalog_per_subject2.is_enrolled)
        self.assertEqual(catalog_per_subject2.teacher,
                         self.source_study_class.class_master)
        self.assertEqual(catalog_per_subject2.study_class,
                         self.source_study_class)

        self.assertTrue(
            StudentCatalogPerSubject.objects.filter(
                student=self.student,
                teacher=self.study_class.class_master,
                study_class=self.study_class,
                subject=self.subject2).exists())

        self.assertIsNotNone(self.principal.last_change_in_catalog)
        self.assertIsNotNone(self.school_unit.last_change_in_catalog)
예제 #16
0
 def setUpTestData(cls):
     cls.principal = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL)
     cls.school_unit = RegisteredSchoolUnitFactory(school_principal=cls.principal)
     cls.student = UserProfileFactory(
         user_role=UserProfile.UserRoles.STUDENT,
         student_in_class=StudyClassFactory(class_grade='X', class_grade_arabic=10, academic_year=2020),
         school_unit=cls.school_unit
     )
     cls.current_class = cls.student.student_in_class
     cls.previous_catalog = StudentCatalogPerYearFactory(
         student=cls.student,
         study_class=cls.current_class,
         academic_year=cls.current_class.academic_year - 1,
         avg_final=5.0,
     )
예제 #17
0
    def test_grade_create_secondary_school_averages(self, mocked_method):
        # This is for a subject with weekly hours count = 1 and no thesis (1st semester)
        self.client.login(username=self.teacher.username, password='******')
        # Add a few more catalogs per subject for this student
        StudentCatalogPerSubjectFactory(student=self.student,
                                        study_class=self.study_class,
                                        avg_sem1=9)
        StudentCatalogPerSubjectFactory(student=self.student,
                                        study_class=self.study_class,
                                        is_enrolled=False)
        StudentCatalogPerSubjectFactory(student=self.student,
                                        study_class=self.study_class,
                                        is_exempted=True)
        # Add year catalog for a different student
        StudentCatalogPerYearFactory(study_class=self.study_class, avg_sem1=9)

        self.data['taken_at'] = date(2019, 11, 10)

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

        # because the student doesn't have enough grades, the average shouldn't be computed yet
        self.catalog.refresh_from_db()
        self.assertIsNone(self.catalog.avg_sem1)
        self.assertIsNone(self.catalog.avg_sem2)
        self.assertIsNone(self.catalog.avg_annual)
        self.assertIsNone(self.catalog.avg_final)

        # Add another grade, so we can compute the average
        self.data['grade'] = 9

        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.school_stats
        ])
        self.assertEqual(self.catalog.avg_sem1, 10)
        self.assertEqual(self.catalog_per_year.avg_sem1, 9.5)
        for catalog in [self.catalog, self.catalog_per_year]:
            self.assertIsNone(catalog.avg_sem2)
            self.assertIsNone(catalog.avg_annual)
            self.assertIsNone(catalog.avg_final)
        for obj in [self.study_class, self.school_stats]:
            self.assertEqual(obj.avg_sem1, 9.25)
            self.assertIsNone(obj.avg_sem2)
            self.assertIsNone(obj.avg_annual)
예제 #18
0
 def setUpTestData(cls):
     cls.calendar = 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,
                                         class_master=cls.teacher)
     cls.student = UserProfileFactory(
         user_role=UserProfile.UserRoles.STUDENT,
         school_unit=cls.school_unit,
         student_in_class=cls.study_class)
     StudentCatalogPerYearFactory(student=cls.student,
                                  study_class=cls.study_class)
 def setUpTestData(cls):
     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_master=cls.teacher)
     cls.subject = SubjectFactory()
     cls.teacher.taught_subjects.add(cls.subject)
     cls.teacher_class_through = TeacherClassThroughFactory(
         study_class=cls.study_class,
         teacher=cls.teacher,
         subject=cls.subject
     )
     cls.catalog = StudentCatalogPerYearFactory(
         student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='a'),
         study_class=cls.study_class,
         academic_year=2020
     )
예제 #20
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)
예제 #22
0
    def test_examination_grade_create_differences_per_previous_year_success(
            self, mocked_method):
        self.client.login(username=self.teacher.username, password='******')
        study_class = StudyClassFactory(school_unit=self.school_unit,
                                        class_grade='IX',
                                        class_grade_arabic=9,
                                        academic_year=2019)
        catalog = StudentCatalogPerSubjectFactory(subject=self.subject,
                                                  teacher=self.teacher,
                                                  student=self.student,
                                                  study_class=study_class)
        catalog_per_year = StudentCatalogPerYearFactory(
            student=self.student, study_class=study_class)
        school_stats = SchoolUnitStatsFactory(school_unit=self.school_unit,
                                              academic_year=2019)

        self.data['grade_type'] = ExaminationGrade.GradeTypes.DIFFERENCE
        self.data['taken_at'] = date(2020, 9, 7)

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

        self.data['examination_type'] = ExaminationGrade.ExaminationTypes.ORAL
        response = self.client.post(self.build_url(catalog.id), self.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        self.assertEqual(len(response.data['second_examination_grades']), 0)
        self.assertEqual(len(response.data['difference_grades_sem1']), 0)
        self.assertEqual(len(response.data['difference_grades_sem2']), 2)

        self.refresh_objects_from_db([
            catalog, catalog_per_year, study_class,
            study_class.academic_program, school_stats, self.teacher,
            self.teacher.school_unit
        ])
        for catalog in [catalog, catalog_per_year]:
            self.assertEqual(catalog.avg_annual, Decimal('9.5'))
            self.assertEqual(catalog.avg_final, Decimal('9.5'))
        for obj in [study_class, study_class.academic_program, school_stats]:
            self.assertEqual(obj.avg_annual, Decimal('9.5'))

        self.assertEqual(self.teacher.last_change_in_catalog, timezone.now())
        self.assertEqual(self.teacher.school_unit.last_change_in_catalog,
                         timezone.now())
예제 #23
0
    def test_own_students_at_risk_success(self):
        self.client.login(username=self.teacher.username, password='******')

        study_class = StudyClassFactory(class_master=self.teacher, school_unit=self.school_unit)

        catalog1 = StudentCatalogPerYearFactory(student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, student_in_class=study_class,
                                                                           school_unit=self.school_unit, is_at_risk=True, full_name='b'),
                                                study_class=study_class, unfounded_abs_count_sem1=2, unfounded_abs_count_annual=2)
        catalog2 = StudentCatalogPerYearFactory(student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, student_in_class=study_class,
                                                                           school_unit=self.school_unit, is_at_risk=True, full_name='c'),
                                                study_class=study_class, unfounded_abs_count_sem1=1, unfounded_abs_count_annual=1)
        catalog3 = StudentCatalogPerYearFactory(student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, student_in_class=study_class,
                                                                           school_unit=self.school_unit, is_at_risk=True, full_name='e'),
                                                study_class=study_class,  unfounded_abs_count_sem1=3, unfounded_abs_count_annual=3,
                                                behavior_grade_sem1=8, behavior_grade_annual=8)
        catalog4 = StudentCatalogPerYearFactory(student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, student_in_class=study_class,
                                                                           school_unit=self.school_unit, is_at_risk=True, full_name='d'),
                                                study_class=study_class, unfounded_abs_count_sem1=3, unfounded_abs_count_annual=3,
                                                behavior_grade_sem1=9, behavior_grade_annual=9)
        catalog5 = StudentCatalogPerYearFactory(student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, student_in_class=study_class,
                                                                           school_unit=self.school_unit, is_at_risk=True, full_name='a'),
                                                study_class=study_class, unfounded_abs_count_sem1=2, unfounded_abs_count_annual=2)
        StudentCatalogPerYearFactory(student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, student_in_class=study_class), study_class=study_class)
        StudentCatalogPerYearFactory(student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, is_at_risk=True))

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data['results']), 5)

        expected_fields = ['id', 'student', 'avg_sem1', 'avg_final', 'unfounded_abs_count_sem1', 'unfounded_abs_count_annual',
                           'second_examinations_count', 'behavior_grade_sem1', 'behavior_grade_annual', 'behavior_grade_limit']
        expected_student_fields = ['id', 'full_name']
        for result in response.data['results']:
            self.assertCountEqual(result.keys(), expected_fields)
            self.assertCountEqual(result['student'].keys(), expected_student_fields)

        self.assertEqual(response.data['results'][0]['id'], catalog4.id)
        self.assertEqual(response.data['results'][1]['id'], catalog3.id)
        self.assertEqual(response.data['results'][2]['id'], catalog5.id)
        self.assertEqual(response.data['results'][3]['id'], catalog1.id)
        self.assertEqual(response.data['results'][4]['id'], catalog2.id)
    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 setUpTestData(cls):
        cls.admin = UserProfileFactory(
            user_role=UserProfile.UserRoles.ADMINISTRATOR)
        cls.principal = UserProfileFactory(
            user_role=UserProfile.UserRoles.PRINCIPAL)
        cls.school_unit = RegisteredSchoolUnitFactory(
            school_principal=cls.principal)

        cls.teacher = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit)
        cls.teacher_class_through = TeacherClassThroughFactory(
            study_class=cls.study_class, teacher=cls.teacher)
        another_study_class = StudyClassFactory(school_unit=cls.school_unit,
                                                class_grade='IX',
                                                class_grade_arabic=9)

        cls.another_school_unit = RegisteredSchoolUnitFactory(
            academic_profile=SchoolUnitProfileFactory(name='Militar'))
        cls.catalog1 = StudentCatalogPerYearFactory(
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='Student a',
                                       school_unit=cls.another_school_unit),
            study_class=StudyClassFactory(school_unit=cls.another_school_unit),
            avg_sem1=1,
            avg_sem2=1,
            avg_final=1,
            second_examinations_count=1,
            unfounded_abs_count_sem1=1,
            unfounded_abs_count_sem2=1,
            unfounded_abs_count_annual=1,
            behavior_grade_sem1=1,
            behavior_grade_sem2=1,
            behavior_grade_annual=1,
        )
        cls.catalog2 = StudentCatalogPerYearFactory(
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='Student b',
                                       school_unit=cls.school_unit),
            study_class=another_study_class,
            avg_sem1=2,
            avg_sem2=2,
            avg_final=2,
            second_examinations_count=2,
            unfounded_abs_count_sem1=2,
            unfounded_abs_count_sem2=2,
            unfounded_abs_count_annual=2,
            behavior_grade_sem1=2,
            behavior_grade_sem2=2,
            behavior_grade_annual=2,
        )
        cls.catalog3 = StudentCatalogPerYearFactory(
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='Student c',
                                       school_unit=cls.school_unit),
            study_class=cls.study_class,
            avg_sem1=3,
            avg_sem2=3,
            avg_final=3,
            second_examinations_count=3,
            unfounded_abs_count_sem1=3,
            unfounded_abs_count_sem2=3,
            unfounded_abs_count_annual=3,
            behavior_grade_sem1=3,
            behavior_grade_sem2=3,
            behavior_grade_annual=3,
        )
        cls.catalog4 = StudentCatalogPerYearFactory(
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='Student d',
                                       school_unit=cls.school_unit),
            study_class=cls.study_class,
            avg_sem1=4,
            avg_sem2=4,
            avg_final=4,
            second_examinations_count=4,
            unfounded_abs_count_sem1=4,
            unfounded_abs_count_sem2=4,
            unfounded_abs_count_annual=4,
            behavior_grade_sem1=4,
            behavior_grade_sem2=4,
            behavior_grade_annual=4,
        )

        cls.url = reverse('statistics:pupils-statistics')
    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)
예제 #27
0
    def test_move_student_success(self):
        self.client.login(username=self.principal.username, password='******')

        catalog_per_year1 = StudentCatalogPerYearFactory(
            student=self.student, study_class=self.source_study_class)
        catalog_per_subject1 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.source_study_class.class_master,
            study_class=self.source_study_class,
            subject=self.subject1)
        catalog_per_subject2 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.source_study_class.class_master,
            study_class=self.source_study_class,
            subject=self.subject3)

        previous_study_class = StudyClassFactory(
            school_unit=self.school_unit,
            academic_year=self.study_class.academic_year - 1,
            class_grade_arabic=9,
            class_grade='IX',
            class_letter='B',
            class_master=self.study_class.class_master)
        TeacherClassThroughFactory(study_class=previous_study_class,
                                   teacher=self.study_class.class_master,
                                   subject=self.subject1,
                                   is_class_master=True)
        TeacherClassThroughFactory(study_class=previous_study_class,
                                   teacher=self.study_class.class_master,
                                   subject=self.subject2,
                                   is_class_master=True)
        optional_subject = SubjectFactory()
        TeacherClassThroughFactory(study_class=previous_study_class,
                                   teacher=self.study_class.class_master,
                                   subject=optional_subject,
                                   is_class_master=True,
                                   is_optional_subject=True)

        own_previous_study_class = StudyClassFactory(
            school_unit=self.school_unit,
            academic_year=self.source_study_class.academic_year - 1,
            class_grade='IX',
            class_grade_arabic=9,
            class_master=self.source_study_class.class_master)
        catalog_per_year2 = StudentCatalogPerYearFactory(
            student=self.student, study_class=own_previous_study_class)
        catalog_per_subject3 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.source_study_class.class_master,
            study_class=own_previous_study_class,
            subject=self.subject1)
        catalog_per_subject4 = StudentCatalogPerSubjectFactory(
            student=self.student,
            teacher=self.source_study_class.class_master,
            study_class=own_previous_study_class,
            subject=self.subject3)

        response = self.client.post(
            self.build_url(self.student.id, self.study_class.id), {})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertCountEqual(response.data.keys(), self.expected_fields)
        self.assertEqual(response.data['id'], self.source_study_class.id)

        self.refresh_objects_from_db([
            self.student, self.principal, self.school_unit, catalog_per_year1,
            catalog_per_year2, catalog_per_subject1, catalog_per_subject2,
            catalog_per_subject3, catalog_per_subject4
        ])
        self.assertEqual(self.student.student_in_class, self.study_class)

        self.assertEqual(catalog_per_year1.study_class, self.study_class)
        self.assertEqual(catalog_per_year2.study_class, previous_study_class)

        self.assertTrue(catalog_per_subject1.is_enrolled)
        self.assertEqual(catalog_per_subject1.teacher,
                         self.study_class.class_master)
        self.assertEqual(catalog_per_subject1.study_class, self.study_class)

        self.assertFalse(catalog_per_subject2.is_enrolled)
        self.assertEqual(catalog_per_subject2.teacher,
                         self.source_study_class.class_master)
        self.assertEqual(catalog_per_subject2.study_class,
                         self.source_study_class)

        self.assertTrue(catalog_per_subject3.is_enrolled)
        self.assertEqual(catalog_per_subject3.teacher,
                         own_previous_study_class.class_master)
        self.assertEqual(catalog_per_subject3.study_class,
                         previous_study_class)

        self.assertFalse(catalog_per_subject4.is_enrolled)
        self.assertEqual(catalog_per_subject4.teacher,
                         own_previous_study_class.class_master)
        self.assertEqual(catalog_per_subject4.study_class,
                         own_previous_study_class)

        self.assertTrue(
            StudentCatalogPerSubject.objects.filter(
                student=self.student,
                teacher=self.study_class.class_master,
                study_class=self.study_class,
                subject=self.subject2).exists())
        self.assertTrue(
            StudentCatalogPerSubject.objects.filter(
                student=self.student,
                teacher=previous_study_class.class_master,
                study_class=previous_study_class,
                subject=self.subject2).exists())
        self.assertTrue(
            StudentCatalogPerSubject.objects.filter(
                student=self.student,
                subject=optional_subject,
                is_enrolled=False).exists())
    def test_user_profile_update_taught_subjects(self):
        self.client.login(username=self.principal.username, password='******')
        url = self.build_url(self.teacher_profile.id)

        # Create a few taught subjects
        subject1 = SubjectFactory(name='Sport')
        subject2 = SubjectFactory(name='Religie')

        self.teacher_data['user_role'] = UserProfile.UserRoles.TEACHER
        self.teacher_data['taught_subjects'] = [subject1.id, subject2.id]

        response = self.client.put(url, self.teacher_data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        self.teacher_profile.refresh_from_db()
        for attr_name, value in self.teacher_data.items():
            if attr_name not in ['labels', 'taught_subjects']:
                self.assertEqual(getattr(self.teacher_profile, attr_name), value)

        self.assertCountEqual(self.teacher_profile.taught_subjects.values_list('id', flat=True), [subject1.id, subject2.id])

        study_class1 = StudyClassFactory(school_unit=self.school_unit, class_grade='I', class_grade_arabic=1)
        teacher_class_through1 = TeacherClassThroughFactory(study_class=study_class1, teacher=self.teacher_profile,
                                                            subject=subject1, is_class_master=False)

        study_class2 = StudyClassFactory(school_unit=self.school_unit, class_master=self.teacher_profile)
        teacher_class_through2 = TeacherClassThroughFactory(study_class=study_class2, teacher=self.teacher_profile,
                                                            subject=subject2, is_class_master=True)
        self.student_profile.student_in_class = study_class2
        self.student_profile.save()
        StudentCatalogPerYearFactory(student=self.student_profile, study_class=study_class2)
        catalog = StudentCatalogPerSubjectFactory(student=self.student_profile, teacher=self.teacher_profile,
                                                  study_class=study_class2, subject=subject2)

        new_teacher = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=self.school_unit)
        new_teacher.taught_subjects.add(subject2)

        self.teacher_data['taught_subjects'] = [subject1.id]
        self.teacher_data['new_teachers'] = [
            {
                'id': teacher_class_through2.id,
                'teacher': new_teacher.id
            }
        ]

        response = self.client.put(url, self.teacher_data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.refresh_objects_from_db([teacher_class_through2, catalog])

        self.assertEqual(teacher_class_through2.teacher, new_teacher)
        self.assertFalse(teacher_class_through2.is_class_master)
        self.assertEqual(catalog.teacher, new_teacher)

        self.teacher_data['taught_subjects'] = []
        self.teacher_data['new_teachers'] = [
            {
                'id': teacher_class_through1.id,
                'teacher': study_class1.class_master.id
            }
        ]

        response = self.client.put(url, self.teacher_data)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        teacher_class_through1.refresh_from_db()

        self.assertEqual(teacher_class_through1.teacher, study_class1.class_master)
        self.assertTrue(teacher_class_through1.is_class_master)
예제 #29
0
    def test_study_class_detail_success(self):
        self.client.login(username=self.principal.username, password='******')
        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)
        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)
        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)

        teacher1 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER)
        teacher2 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER)
        teacher3 = self.study_class.class_master
        subject1 = SubjectFactory(name='Subject B')
        subject2 = SubjectFactory(name='Subject C')
        subject3 = SubjectFactory(name='Subject A')
        subject4 = SubjectFactory(name='Dirigentie', is_coordination=True)
        teacher_class_through1 = TeacherClassThroughFactory(
            study_class=self.study_class, teacher=teacher1, subject=subject1)
        teacher_class_through2 = TeacherClassThroughFactory(
            study_class=self.study_class, teacher=teacher2, subject=subject2)
        teacher_class_through3 = TeacherClassThroughFactory(
            study_class=self.study_class, teacher=teacher3, subject=subject3)
        TeacherClassThroughFactory(study_class=self.study_class,
                                   teacher=teacher3,
                                   subject=subject4)

        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(), [
            'id', 'class_grade', 'class_letter', 'academic_year',
            'academic_program', 'academic_program_name', 'class_master',
            'teachers_class_through', 'students', 'has_previous_catalog_data'
        ])
        self.assertCountEqual(response.data['class_master'].keys(),
                              ['id', 'full_name'])

        teachers_class_through_response = response.data[
            'teachers_class_through']
        self.assertEqual(len(teachers_class_through_response), 3)
        self.assertCountEqual(teachers_class_through_response[0].keys(),
                              ['id', 'teacher', 'subject_id', 'subject_name'])
        self.assertCountEqual(
            teachers_class_through_response[0]['teacher'].keys(),
            ['id', 'full_name'])
        self.assertEqual(teachers_class_through_response[0]['id'],
                         teacher_class_through3.id)
        self.assertEqual(teachers_class_through_response[1]['id'],
                         teacher_class_through1.id)
        self.assertEqual(teachers_class_through_response[2]['id'],
                         teacher_class_through2.id)

        students_response = response.data['students']
        self.assertEqual(len(students_response), 3)
        self.assertCountEqual(students_response[0].keys(), ['id', 'full_name'])
        self.assertEqual(students_response[0]['id'], student3.id)
        self.assertEqual(students_response[1]['id'], student1.id)
        self.assertEqual(students_response[2]['id'], student2.id)
    def setUpTestData(cls):
        cls.calendar = AcademicYearCalendarFactory(
            first_semester__starts_at=datetime(2019, 9, 9),
            first_semester__ends_at=datetime(2020, 1, 12),
            second_semester__starts_at=datetime(2020, 1, 13),
            second_semester__ends_at=datetime(2020, 6, 12))
        cls.create_semester_end_events(cls.calendar)
        subject = SubjectFactory(name='Matematică')

        cls.school1 = RegisteredSchoolUnitFactory()

        cls.study_class1 = StudyClassFactory(school_unit=cls.school1)

        # No risk
        cls.student1 = UserProfileFactory(
            school_unit=cls.school1,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class1)
        StudentCatalogPerYearFactory(student=cls.student1,
                                     study_class=cls.study_class1)
        # Absences risk 1
        cls.student2 = UserProfileFactory(
            school_unit=cls.school1,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class1)
        StudentCatalogPerYearFactory(student=cls.student2,
                                     study_class=cls.study_class1,
                                     unfounded_abs_count_sem1=1,
                                     unfounded_abs_count_sem2=3)
        # Absences risk 2
        cls.student3 = UserProfileFactory(
            school_unit=cls.school1,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class1)
        StudentCatalogPerYearFactory(student=cls.student3,
                                     study_class=cls.study_class1,
                                     unfounded_abs_count_sem1=4,
                                     unfounded_abs_count_sem2=5)

        cls.study_class2 = StudyClassFactory(school_unit=cls.school1,
                                             class_grade='X',
                                             class_grade_arabic=10)

        # Grades risk 1
        cls.student4 = UserProfileFactory(
            school_unit=cls.school1,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class2)
        StudentCatalogPerYearFactory(student=cls.student4,
                                     study_class=cls.study_class2)
        cls.catalog4 = StudentCatalogPerSubjectFactory(
            student=cls.student4,
            study_class=cls.study_class2,
            subject=subject,
            avg_sem1=5,
            avg_sem2=6)
        # Grades risk 2 (sem II)
        cls.student5 = UserProfileFactory(
            school_unit=cls.school1,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class2)
        StudentCatalogPerYearFactory(student=cls.student5,
                                     study_class=cls.study_class2)
        cls.catalog5 = StudentCatalogPerSubjectFactory(
            student=cls.student5,
            study_class=cls.study_class2,
            subject=subject,
            avg_sem1=7,
            avg_sem2=4)

        cls.study_class3 = StudyClassFactory(school_unit=cls.school1,
                                             class_grade='XII',
                                             class_grade_arabic=12)

        # Behavior grade risk 1 (sem II)
        cls.student6 = UserProfileFactory(
            school_unit=cls.school1,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class3)
        StudentCatalogPerYearFactory(student=cls.student6,
                                     study_class=cls.study_class3,
                                     behavior_grade_sem1=10,
                                     behavior_grade_sem2=9)
        # Behavior grade risk 2
        cls.student7 = UserProfileFactory(
            school_unit=cls.school1,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class3)
        StudentCatalogPerYearFactory(student=cls.student7,
                                     study_class=cls.study_class3,
                                     behavior_grade_sem1=7,
                                     behavior_grade_sem2=6)

        cls.school2 = RegisteredSchoolUnitFactory()
        cls.school2.categories.add(
            SchoolUnitCategoryFactory(name='Liceu - Filieră Tehnologică'))

        cls.study_class4 = StudyClassFactory(school_unit=cls.school2,
                                             class_grade='VIII',
                                             class_grade_arabic=8)

        # Absences risk 1 + Grades risk 2
        cls.student8 = UserProfileFactory(
            school_unit=cls.school2,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class4)
        StudentCatalogPerYearFactory(student=cls.student8,
                                     study_class=cls.study_class4,
                                     unfounded_abs_count_sem1=1,
                                     unfounded_abs_count_sem2=3)
        cls.catalog8 = StudentCatalogPerSubjectFactory(
            student=cls.student8,
            study_class=cls.study_class4,
            subject=subject,
            avg_sem1=4,
            avg_sem2=4)
        # Grades risk 1 + Behavior grade risk 2 (sem II)
        cls.student9 = UserProfileFactory(
            school_unit=cls.school2,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class4)
        StudentCatalogPerYearFactory(student=cls.student9,
                                     study_class=cls.study_class4,
                                     behavior_grade_sem1=10,
                                     behavior_grade_sem2=7)
        cls.catalog9 = StudentCatalogPerSubjectFactory(
            student=cls.student9,
            study_class=cls.study_class4,
            subject=subject,
            avg_sem1=7,
            avg_sem2=6)

        cls.study_class5 = StudyClassFactory(school_unit=cls.school2,
                                             class_grade='IX',
                                             class_grade_arabic=9)

        # Absences risk 2 (both sem) + Behavior grade risk 1 (sem II)
        cls.student10 = UserProfileFactory(
            school_unit=cls.school2,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class5)
        StudentCatalogPerYearFactory(student=cls.student10,
                                     study_class=cls.study_class5,
                                     behavior_grade_sem1=10,
                                     behavior_grade_sem2=9,
                                     unfounded_abs_count_sem1=4,
                                     unfounded_abs_count_sem2=5)

        # Absences risk 2 + Grades risk 2 + Behavior grade risk 2
        cls.student11 = UserProfileFactory(
            school_unit=cls.school2,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class5)
        StudentCatalogPerYearFactory(student=cls.student11,
                                     study_class=cls.study_class5,
                                     behavior_grade_sem1=7,
                                     behavior_grade_sem2=6,
                                     unfounded_abs_count_sem1=4,
                                     unfounded_abs_count_sem2=6)
        cls.catalog11 = StudentCatalogPerSubjectFactory(
            student=cls.student11,
            study_class=cls.study_class5,
            subject=subject,
            avg_sem1=4,
            avg_sem2=3)

        cls.create_risk_stats()