Exemple #1
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)
    def test_bulk_create_absence_validate_student(self, timezone_mock):
        self.client.login(username=self.teacher.username, password='******')

        self.request_data['taken_at'] = date(2019, 9, 20)
        self.request_data['student_absences'][0]['student'] = 0

        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_400_BAD_REQUEST)
        self.assertEqual(response.data['student_absences'][0]['student'], ['Invalid pk "0" - object does not exist.'])

        # Not student in class
        student1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit)
        # Not enrolled
        student2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit, student_in_class=self.study_class)
        StudentCatalogPerSubjectFactory(student=student2, study_class=self.study_class, teacher=self.teacher, subject=self.subject, is_enrolled=False)
        # Not active
        student3 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit,
                                      student_in_class=self.study_class, is_active=False)
        StudentCatalogPerSubjectFactory(student=student3, study_class=self.study_class, teacher=self.teacher, subject=self.subject)

        for student in [student1, student2, student3]:
            self.request_data['student_absences'][0]['student'] = student.id

            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_400_BAD_REQUEST)
            self.assertEqual(response.data['student'], [f'Invalid pk "{student.id}" - object does not exist.'])
    def setUpTestData(cls):
        cls.academic_calendar = AcademicYearCalendarFactory()
        cls.academic_year = cls.academic_calendar.academic_year
        cls.starts_at = datetime.date(2020, 10, 21)
        cls.ends_at = datetime.date(2020, 10, 27)

        cls.school = RegisteredSchoolUnitFactory()
        cls.study_class = StudyClassFactory(school_unit=cls.school)
        cls.student = UserProfileFactory(
            school_unit=cls.school,
            user_role=UserProfile.UserRoles.STUDENT,
            student_in_class=cls.study_class,
            full_name="Pop Ionut")

        cls.subject1 = SubjectFactory(name='Limba Romana')
        cls.subject2 = SubjectFactory(name='Matematica')

        cls.catalog1 = StudentCatalogPerSubjectFactory(
            student=cls.student,
            study_class=cls.study_class,
            subject=cls.subject1)
        cls.catalog2 = StudentCatalogPerSubjectFactory(
            student=cls.student,
            study_class=cls.study_class,
            subject=cls.subject2)
    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_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)
    def test_own_study_class_catalog_per_subject_ordering(self, ordering):
        self.client.login(username=self.teacher.username, password='******')

        StudentCatalogPerSubjectFactory(
            subject=self.subject,
            teacher=self.teacher,
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='a'),
            study_class=self.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
        )
        StudentCatalogPerSubjectFactory(
            subject=self.subject,
            teacher=self.teacher,
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='b'),
            study_class=self.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
        )
        StudentCatalogPerSubjectFactory(
            subject=self.subject,
            teacher=self.teacher,
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='c'),
            study_class=self.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
        )
        response = self.client.get(self.build_url(self.study_class.id, self.subject.id), {'ordering': ordering} if ordering else None)
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        if not ordering or ordering == 'student_name':
            ordering = 'student__full_name'

        if ordering == '-student_name':
            ordering = '-student__full_name'

        for catalog_data, catalog in zip(response.data, StudentCatalogPerSubject.objects.order_by(ordering)):
            self.assertEqual(catalog_data['id'], catalog.id)
Exemple #7
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)
    def test_catalog_settings_success(self):
        self.client.login(username=self.teacher.username, password='******')
        catalog1 = StudentCatalogPerSubjectFactory(
            subject=self.subject,
            teacher=self.teacher,
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='c'),
            study_class=self.study_class)

        catalog2 = StudentCatalogPerSubjectFactory(
            subject=self.subject,
            teacher=self.teacher,
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='a'),
            study_class=self.study_class)

        catalog3 = StudentCatalogPerSubjectFactory(
            subject=self.subject,
            teacher=self.teacher,
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='b'),
            study_class=self.study_class)
        StudentCatalogPerSubjectFactory(
            subject=self.subject,
            teacher=self.teacher,
            student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT,
                                       full_name='d',
                                       is_active=False),
            study_class=self.study_class)

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

        catalog_expected_fields = [
            'id', 'student', 'wants_level_testing_grade', 'wants_thesis',
            'wants_simulation', 'is_exempted', 'is_enrolled'
        ]
        student_expected_fields = ['id', 'full_name']

        for catalog_data in response.data:
            self.assertCountEqual(catalog_data.keys(), catalog_expected_fields)
            self.assertCountEqual(catalog_data['student'].keys(),
                                  student_expected_fields)

        self.assertEqual(response.data[0]['id'], catalog2.id)
        self.assertEqual(response.data[1]['id'], catalog3.id)
        self.assertEqual(response.data[2]['id'], catalog1.id)
    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)
Exemple #10
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_get_grades_for_students(self):
        self.assertEqual(
            get_grades_for_students(self.student.id, self.starts_at,
                                    self.ends_at).count(), 0)
        catalog = StudentCatalogPerSubjectFactory(is_coordination_subject=True)

        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=self.catalog1,
                            taken_at=self.starts_at -
                            timezone.timedelta(days=1))
        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=self.catalog1,
                            taken_at=self.starts_at)
        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=self.catalog1,
                            taken_at=self.starts_at +
                            timezone.timedelta(days=1))
        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=self.catalog2,
                            taken_at=self.ends_at - timezone.timedelta(days=1))
        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=self.catalog2,
                            taken_at=self.ends_at)
        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=catalog,
                            taken_at=self.ends_at)
        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=self.catalog2,
                            taken_at=self.ends_at + timezone.timedelta(days=1))

        self.assertEqual(
            get_grades_for_students(self.student.id, self.starts_at,
                                    self.ends_at).count(), 4)
    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
        )
Exemple #13
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)
 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)
     cls.subject = SubjectFactory()
     cls.teacher_class_through = TeacherClassThroughFactory(study_class=cls.study_class, teacher=cls.teacher, subject=cls.subject)
     cls.catalog = StudentCatalogPerSubjectFactory(study_class=cls.study_class, teacher=cls.teacher, subject=cls.subject, student__full_name='a')
     cls.current_calendar = AcademicYearCalendarFactory()
    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)
Exemple #16
0
 def setUpTestData(cls):
     cls.school_unit = RegisteredSchoolUnitFactory()
     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 = StudentCatalogPerSubjectFactory(student=cls.student)
    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)
Exemple #18
0
    def test_create_absence_student_not_enrolled(self):
        self.client.login(username=self.teacher.username, password='******')
        catalog = StudentCatalogPerSubjectFactory(student=self.student,
                                                  study_class=self.study_class,
                                                  teacher=self.teacher,
                                                  is_enrolled=False)

        response = self.client.post(self.build_url(catalog.id),
                                    data=self.request_data)
        self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Exemple #19
0
 def setUp(self):
     self.catalog = StudentCatalogPerSubjectFactory(
         study_class=self.study_class,
         teacher=self.teacher,
         subject=self.subject,
         student=self.student,
         is_enrolled=True)
     self.study_class.refresh_from_db()
     self.teacher_class_through.refresh_from_db()
     self.data = {
         'Nume': self.student.full_name,
         'Etichete': 'good; v good',
         'Note sem. I': '',
         'Teză sem. I': '',
         'Note sem. II': '4-4-2020: 10; 5-4-2020: 10',
         'Teză sem. II': '4-4-2020: 7',
         'Diferență sem. I Oral Prof. I': '22-12-2019: 6',
         'Diferență sem. I Oral Prof. II': '22-12-2019: 7',
         'Diferență sem. I Scris Prof. I': '22-12-2019: 8',
         'Diferență sem. I Scris Prof. II': '22-12-2019: 9',
         'Diferență sem. II Oral Prof. I': '',
         'Diferență sem. II Oral Prof. II': '',
         'Diferență sem. II Scris Prof. I': '',
         'Diferență sem. II Scris Prof. II': '',
         'Diferență anuală Oral Prof. I': '',
         'Diferență anuală Oral Prof. II': '',
         'Diferență anuală Scris Prof. I': '',
         'Diferență anuală Scris Prof. II': '',
         'Corigență Oral Prof. I': '5-5-2020: 6',
         'Corigență Oral Prof. II': '5-5-2020: 7',
         'Corigență Scris Prof. I': '5-5-2020: 8',
         'Corigență Scris Prof. II': '5-5-2020: 9',
         'Absențe motivate sem. I': '12-12-2019; 13-12-2019',
         'Absențe motivate sem. II': '4-4-2020; 5-4-2020',
         'Absențe nemotivate sem. I': '12-12-2019; 13-12-2019',
         'Absențe nemotivate sem. II': '4-4-2020; 5-4-2020',
         'Observații': 'foarte bun elev',
         'Teste inițiale / finale': 'Da',
         'Teză': 'Da',
         'Simulări': 'Da',
         'Scutit': 'Nu',
         'Înregistrat opțional': 'Da'
     }
Exemple #20
0
    def test_grade_update_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,
                                        avg_sem1=10)

        SubjectGradeFactory(student=self.student,
                            catalog_per_subject=self.catalog,
                            semester=1,
                            grade=9)
        grade = self.create_grade(semester=1)
        self.catalog.avg_sem1 = 10
        self.catalog.save()

        self.data['taken_at'] = date(2019, 11, 10)
        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.school_stats
        ])
        self.assertEqual(self.catalog.avg_sem1, 9)
        self.assertIsNone(self.catalog.avg_sem2)
        self.assertIsNone(self.catalog.avg_annual)
        self.assertIsNone(self.catalog.avg_final)
        self.assertIsNone(self.catalog_per_year.avg_final)
        for obj in [
                self.catalog_per_year, self.study_class, self.school_stats
        ]:
            self.assertEqual(obj.avg_sem1, Decimal('9.33'))
            self.assertIsNone(obj.avg_sem2)
            self.assertIsNone(obj.avg_annual)
Exemple #21
0
    def setUpTestData(cls):
        cls.school_unit = RegisteredSchoolUnitFactory(
            academic_profile=SchoolUnitProfileFactory(name='Artistic'))
        cls.study_class = StudyClassFactory(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.catalog = StudentCatalogPerSubjectFactory(
            student=cls.student, study_class=cls.study_class)
        cls.study_class.academic_program.core_subject = cls.catalog.subject
        cls.study_class.academic_program.save()

        cls.url = reverse('statistics:own-activity-history')
Exemple #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())
 def test_own_study_class_catalog_per_subject_is_not_enrolled(self):
     StudentCatalogPerSubjectFactory(
         subject=self.subject,
         teacher=self.teacher,
         student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='a'),
         study_class=self.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,
         is_enrolled=False
     )
     self.client.login(username=self.teacher.username, password='******')
     response = self.client.get(self.build_url(self.study_class.id, self.subject.id))
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(len(response.data), 0)
Exemple #24
0
 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)
     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 = StudentCatalogPerSubjectFactory(
         subject=cls.subject,
         teacher=cls.teacher,
         student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='a'),
         study_class=cls.study_class,
         academic_year=2020,
         is_enrolled=True
     )
    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)
Exemple #26
0
    def setUp(self):
        self.teacher_class_through1 = TeacherClassThroughFactory(study_class=self.study_class, teacher=self.teacher1,
                                                                 subject=self.coordination_subject, is_class_master=True)
        self.teacher_class_through2 = TeacherClassThroughFactory(study_class=self.study_class, teacher=self.teacher1, subject=self.subject1,
                                                                 is_class_master=True)
        self.teacher_class_through3 = TeacherClassThroughFactory(study_class=self.study_class, teacher=self.teacher2, subject=self.subject2,
                                                                 is_class_master=False, is_optional_subject=True)

        self.subject_catalog1 = StudentCatalogPerSubjectFactory(student=self.student1, teacher=self.teacher1,
                                                                study_class=self.study_class, subject=self.coordination_subject)
        self.subject_catalog2 = StudentCatalogPerSubjectFactory(student=self.student1, teacher=self.teacher1,
                                                                study_class=self.study_class, subject=self.subject1)
        self.subject_catalog3 = StudentCatalogPerSubjectFactory(student=self.student1, teacher=self.teacher2,
                                                                study_class=self.study_class, subject=self.subject2)
        self.subject_catalog4 = StudentCatalogPerSubjectFactory(student=self.student2, teacher=self.teacher1,
                                                                study_class=self.study_class, subject=self.coordination_subject)
        self.subject_catalog5 = StudentCatalogPerSubjectFactory(student=self.student2, teacher=self.teacher1,
                                                                study_class=self.study_class, subject=self.subject1)
        self.subject_catalog6 = StudentCatalogPerSubjectFactory(student=self.student2, teacher=self.teacher2,
                                                                study_class=self.study_class, subject=self.subject2)

        self.request_data = {
            "class_master": self.teacher2.id,
            "updated_teachers": [
                {
                    "id": self.teacher_class_through2.id,
                    "teacher": self.teacher2.id,
                },
                {
                    "id": self.teacher_class_through3.id,
                    "teacher": self.teacher1.id,
                }
            ],
            "new_students": [
                self.new_student.id
            ],
            "deleted_students": [
                self.student2.id
            ]
        }
Exemple #27
0
    def test_own_child_activity_history_exam_grades(self):
        self.client.login(username=self.parent.username, password='******')
        yesterday = (timezone.now() -
                     timezone.timedelta(days=1)).replace(tzinfo=utc)
        two_days_ago = (timezone.now() - timezone.timedelta(days=2)).date()
        three_days_ago = (timezone.now() - timezone.timedelta(days=3)).date()
        four_days_ago = (timezone.now() - timezone.timedelta(days=3)).date()

        with patch('django.utils.timezone.now',
                   return_value=yesterday) as mocked_method:
            # 2nd examinations
            ExaminationGradeFactory(student=self.student,
                                    catalog_per_subject=self.catalog,
                                    taken_at=yesterday.date())
            ExaminationGradeFactory(
                student=self.student,
                catalog_per_subject=self.catalog,
                taken_at=yesterday.date(),
                examination_type=ExaminationGrade.ExaminationTypes.ORAL)
            # difference for 1st semester
            ExaminationGradeFactory(
                student=self.student,
                catalog_per_subject=self.catalog,
                taken_at=three_days_ago,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                semester=1)
            ExaminationGradeFactory(
                student=self.student,
                catalog_per_subject=self.catalog,
                taken_at=three_days_ago,
                examination_type=ExaminationGrade.ExaminationTypes.ORAL,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                semester=1)
            # difference for 2nd semester
            ExaminationGradeFactory(
                student=self.student,
                catalog_per_subject=self.catalog,
                taken_at=two_days_ago,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                semester=2)
            ExaminationGradeFactory(
                student=self.student,
                catalog_per_subject=self.catalog,
                taken_at=two_days_ago,
                examination_type=ExaminationGrade.ExaminationTypes.ORAL,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                semester=2)
            # difference for whole year for a previous year
            study_class = StudyClassFactory(class_grade='V',
                                            class_grade_arabic=5,
                                            academic_year=2018)
            catalog2 = StudentCatalogPerSubjectFactory(
                student=self.student,
                study_class=study_class,
                is_coordination_subject=True)
            ExaminationGradeFactory(
                student=self.student,
                catalog_per_subject=catalog2,
                taken_at=four_days_ago,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE,
                grade1=9,
                grade2=9)
            ExaminationGradeFactory(
                student=self.student,
                catalog_per_subject=catalog2,
                taken_at=four_days_ago,
                examination_type=ExaminationGrade.ExaminationTypes.ORAL,
                grade_type=ExaminationGrade.GradeTypes.DIFFERENCE)

        self.catalog.avg_after_2nd_examination = 10
        self.catalog.avg_annual = 10
        self.catalog.avg_sem1 = 10
        self.catalog.avg_sem2 = 10
        self.catalog.save()
        catalog2.avg_annual = 9.5
        catalog2.save()

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

        self.assertEqual(response.data[0]['date'],
                         yesterday.date().strftime('%d-%m-%Y'))
        self.assertEqual(response.data[0]['subject_name'],
                         self.catalog.subject_name)
        self.assertEqual(response.data[0]['event_type'],
                         'SECOND_EXAMINATION_AVERAGE')
        self.assertEqual(response.data[0]['event'],
                         'Second examination average 10')
        self.assertEqual(response.data[0]['grade_limit'], 5)
        self.assertEqual(response.data[0]['grade_value'], 10)

        self.assertEqual(response.data[1]['date'],
                         two_days_ago.strftime('%d-%m-%Y'))
        self.assertEqual(response.data[1]['subject_name'],
                         self.catalog.subject_name)
        self.assertEqual(response.data[1]['event_type'], 'DIFFERENCE_AVERAGE')
        self.assertEqual(response.data[1]['event'],
                         'Difference average 10 for class VI, semester 2')
        self.assertEqual(response.data[1]['grade_limit'], 5)
        self.assertEqual(response.data[1]['grade_value'], 10)

        self.assertEqual(response.data[2]['date'],
                         three_days_ago.strftime('%d-%m-%Y'))
        self.assertEqual(response.data[2]['subject_name'],
                         self.catalog.subject_name)
        self.assertEqual(response.data[2]['event_type'], 'DIFFERENCE_AVERAGE')
        self.assertEqual(response.data[2]['event'],
                         'Difference average 10 for class VI, semester 1')
        self.assertEqual(response.data[2]['grade_limit'], 5)
        self.assertEqual(response.data[2]['grade_value'], 10)

        self.assertEqual(response.data[3]['date'],
                         three_days_ago.strftime('%d-%m-%Y'))
        self.assertEqual(response.data[3]['subject_name'],
                         catalog2.subject_name)
        self.assertEqual(response.data[3]['event_type'], 'DIFFERENCE_AVERAGE')
        self.assertEqual(response.data[3]['event'],
                         'Difference average 9.5 for class V')
        self.assertEqual(response.data[3]['grade_limit'], 6)
        self.assertEqual(response.data[3]['grade_value'], 9.5)
Exemple #28
0
    def test_own_absences_evolution_success(self, mocked_method):
        self.client.login(username=self.student.username, password='******')

        catalog1 = StudentCatalogPerSubjectFactory(student=self.student)
        for day in [5, 10]:
            absence = SubjectAbsenceFactory(student=self.student,
                                            catalog_per_subject=catalog1,
                                            is_founded=True,
                                            taken_at=datetime.date(
                                                2020, 6, day))
            absence.created = datetime.datetime(2020, 6,
                                                day).replace(tzinfo=utc)
            absence.save()
        catalog2 = StudentCatalogPerSubjectFactory(student=self.student)
        for day in [5, 11]:
            absence = SubjectAbsenceFactory(student=self.student,
                                            catalog_per_subject=catalog2,
                                            is_founded=False,
                                            taken_at=datetime.date(
                                                2020, 6, day))
            absence.created = datetime.datetime(2020, 6,
                                                day).replace(tzinfo=utc)
            absence.save()
        SubjectAbsenceFactory(student=self.student,
                              catalog_per_subject=catalog2,
                              is_founded=True,
                              taken_at=datetime.date(2020, 6, 16))

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 30)

        self.assertEqual(response.data[4]['day'], 5)
        self.assertEqual(response.data[4]['weekday'], 'Vi')
        self.assertEqual(response.data[4]['total_count'], 2)

        self.assertEqual(response.data[9]['day'], 10)
        self.assertEqual(response.data[9]['weekday'], 'Mi')
        self.assertEqual(response.data[9]['total_count'], 1)

        self.assertEqual(response.data[10]['day'], 11)
        self.assertEqual(response.data[10]['weekday'], 'Jo')
        self.assertEqual(response.data[10]['total_count'], 1)

        response = self.client.get(self.url, {'by_category': 'true'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 30)

        self.assertEqual(response.data[4]['day'], 5)
        self.assertEqual(response.data[4]['weekday'], 'Vi')
        self.assertEqual(response.data[4]['founded_count'], 1)
        self.assertEqual(response.data[4]['unfounded_count'], 1)

        self.assertEqual(response.data[9]['day'], 10)
        self.assertEqual(response.data[9]['weekday'], 'Mi')
        self.assertEqual(response.data[9]['founded_count'], 1)
        self.assertEqual(response.data[9]['unfounded_count'], 0)

        self.assertEqual(response.data[10]['day'], 11)
        self.assertEqual(response.data[10]['weekday'], 'Jo')
        self.assertEqual(response.data[10]['founded_count'], 0)
        self.assertEqual(response.data[10]['unfounded_count'], 1)
    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)