Exemple #1
0
    def setUpTestData(cls):
        cls.calendar = AcademicYearCalendarFactory()
        cls.school_unit = RegisteredSchoolUnitFactory()
        cls.school_stats = SchoolUnitStatsFactory(school_unit=cls.school_unit)

        cls.class_master = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        cls.study_class = StudyClassFactory(school_unit=cls.school_unit,
                                            class_master=cls.class_master)

        cls.subject = SubjectFactory()
        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,
            school_unit=cls.school_unit,
            student_in_class=cls.study_class)
        cls.teacher = UserProfileFactory(
            user_role=UserProfile.UserRoles.TEACHER,
            school_unit=cls.school_unit)
        TeacherClassThroughFactory(teacher=cls.teacher,
                                   study_class=cls.study_class,
                                   is_class_master=False,
                                   subject=cls.subject)
        cls.catalog = StudentCatalogPerSubjectFactory(
            student=cls.student,
            study_class=cls.study_class,
            teacher=cls.teacher,
            subject=cls.subject,
            abs_count_sem1=1,
            abs_count_annual=1,
            unfounded_abs_count_sem1=1,
            unfounded_abs_count_annual=1)
        cls.catalog_per_year = StudentCatalogPerYearFactory(
            student=cls.student,
            study_class=cls.study_class,
            abs_count_sem1=1,
            abs_count_annual=1,
            unfounded_abs_count_sem1=1,
            unfounded_abs_count_annual=1)
        cls.absence = SubjectAbsenceFactory(student=cls.student,
                                            catalog_per_subject=cls.catalog)
        cls.expected_fields = [
            'id', 'student', 'avg_sem1', 'avg_sem2', 'avg_annual',
            'avg_after_2nd_examination', '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',
            'second_examination_grades', 'difference_grades_sem1',
            'difference_grades_sem2', 'abs_sem1', 'abs_sem2', 'wants_thesis',
            'is_exempted', 'is_coordination_subject'
        ]
Exemple #2
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())