Ejemplo n.º 1
0
    def test_study_class_partially_update_validate_class_master(self):
        self.client.login(username=self.principal.username, password='******')
        url = self.build_url(self.study_class.id)

        # Not a teacher
        profile1 = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT, school_unit=self.school_unit)
        # From a different school
        profile2 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=RegisteredSchoolUnitFactory())
        # Already a class master
        profile3 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=self.school_unit)
        StudyClassFactory(school_unit=self.school_unit, class_master=profile3, class_letter='B')
        # Inactive teacher
        profile4 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=self.school_unit, is_active=False)

        for profile in [profile1, profile2, profile3, profile4]:
            self.request_data['class_master'] = profile.id

            response = self.client.patch(url, self.request_data)
            self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
            self.assertEqual(response.data['class_master'], ['Invalid user.'])

        self.request_data['class_master'] = 0

        response = self.client.patch(url, self.request_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data['class_master'], ['Invalid pk "0" - object does not exist.'])
Ejemplo n.º 2
0
    def test_study_class_partially_update_validate_new_students(self):
        self.client.login(username=self.principal.username, password='******')
        url = self.build_url(self.study_class.id)

        # Not a student
        profile1 = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT, school_unit=self.school_unit)
        # Inactive student
        profile2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit, is_active=False)

        for profile_id in [profile1.id, profile2.id, 0]:
            self.request_data['new_students'] = [profile_id, ]

            response = self.client.patch(url, self.request_data)
            self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
            self.assertEqual(response.data['new_students'], [f'Invalid pk "{profile_id}" - object does not exist.'])

        # From a different school
        profile1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=RegisteredSchoolUnitFactory())
        # Already in a study class
        study_class = StudyClassFactory(school_unit=self.school_unit, class_letter='B')
        profile2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit, student_in_class=study_class)

        for profile_id in [profile1.id, profile2.id]:
            self.request_data['new_students'] = [profile_id, ]

            response = self.client.patch(url, self.request_data)
            self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
            self.assertEqual(response.data['new_students'], ['At least one student is invalid.'])
    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
        )
Ejemplo n.º 4
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)
Ejemplo n.º 5
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_user_profile_update_student_parent_validations(self):
        self.client.login(username=self.principal.username, password='******')
        url = self.build_url(self.student_profile.id)

        # Parents don't exist
        self.student_data['parents'] = [0]
        response = self.client.put(url, self.student_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'parents': ['Invalid pk "0" - object does not exist.']})

        # Parents don't belong to the same school
        other_school = RegisteredSchoolUnitFactory()
        parent = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT, school_unit=other_school)
        self.student_data['parents'] = [parent.id]

        response = self.client.put(url, self.student_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'parents': ["Parents must belong to the user's school unit."]})

        # Parents don't have a school
        parent.school_unit = None
        parent.save()
        response = self.client.put(url, self.student_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data, {'parents': ["Parents must belong to the user's school unit."]})
    def test_school_principal_list(self):
        self.client.login(username=self.admin_user.username, password='******')

        profile1 = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL, full_name='John Doe')
        profile2 = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL, full_name='Jane Doe')
        UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL, is_active=False)

        RegisteredSchoolUnitFactory(school_principal=profile2)

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual([profile2.id, profile1.id], [profile['id'] for profile in response.data])

        expected_fields = ['id', 'full_name', 'username']
        for profile in response.data:
            self.assertCountEqual(profile.keys(), expected_fields)

        response = self.client.get(self.url, {'search': 'Jane'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual([profile2.id, ], [profile['id'] for profile in response.data])

        response = self.client.get(self.url, {'has_school': 'false'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual([profile1.id, ], [profile['id'] for profile in response.data])

        response = self.client.get(self.url, {'has_school': 'false', 'search': 'Jane'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 0)
Ejemplo n.º 8
0
    def test_study_class_update_validate_class_master(self, timezone_mock):
        timezone_mock.return_value = datetime.datetime(self.calendar.academic_year, 9, 14, tzinfo=tz.UTC)
        self.client.login(username=self.principal.username, password='******')
        url = self.build_url(self.study_class2.id)

        # Not a teacher
        profile1 = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT, school_unit=self.school_unit)
        # From a different school
        profile2 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=RegisteredSchoolUnitFactory())
        # Already a class master
        profile3 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=self.school_unit)
        StudyClassFactory(school_unit=self.school_unit, class_master=profile3, class_letter='B')
        # Inactive teacher
        profile4 = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=self.school_unit, is_active=False)

        for profile in [profile1, profile2, profile3, profile4]:
            self.highschool_request_data['class_master'] = profile.id

            response = self.client.put(url, self.highschool_request_data)
            self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
            self.assertEqual(response.data['class_master'], ['Invalid user.'])

        self.highschool_request_data['class_master'] = 0

        response = self.client.put(url, self.highschool_request_data)
        self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
        self.assertEqual(response.data['class_master'], ['Invalid pk "0" - object does not exist.'])
    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.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'
        ]
Ejemplo n.º 11
0
    def test_study_class_update_validate_students(self, timezone_mock):
        timezone_mock.return_value = datetime.datetime(self.calendar.academic_year, 9, 14, tzinfo=tz.UTC)
        self.client.login(username=self.principal.username, password='******')
        url = self.build_url(self.study_class2.id)

        # Not a student
        profile1 = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT, school_unit=self.school_unit)
        # Inactive student
        profile2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit, is_active=False)

        for profile_id in [profile1.id, profile2.id, 0]:
            self.highschool_request_data['students'] = [profile_id, ]

            response = self.client.put(url, self.highschool_request_data)
            self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
            self.assertEqual(response.data['students'], [f'Invalid pk "{profile_id}" - object does not exist.'])

        # From a different school
        profile1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=RegisteredSchoolUnitFactory())
        # Already in a study class
        study_class = StudyClassFactory(school_unit=self.school_unit, class_letter='B')
        profile2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit, student_in_class=study_class)

        for profile_id in [profile1.id, profile2.id]:
            self.highschool_request_data['students'] = [profile_id, ]

            response = self.client.put(url, self.highschool_request_data)
            self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
            self.assertEqual(response.data['students'], ['At least one student is invalid.'])
    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)
 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)
Ejemplo n.º 14
0
    def setUpTestData(cls):
        cls.admin_user = UserProfileFactory(
            user_role=UserProfile.UserRoles.ADMINISTRATOR)
        cls.principal = UserProfileFactory(
            user_role=UserProfile.UserRoles.PRINCIPAL)
        cls.other_principal = UserProfileFactory(
            user_role=UserProfile.UserRoles.PRINCIPAL)
        cls.academic_profile1 = SchoolUnitProfileFactory()
        category = SchoolUnitCategoryFactory(
            category_level=SchoolUnitCategory.CategoryLevels.SECONDARY_SCHOOL)
        cls.academic_profile2 = SchoolUnitProfileFactory(category=category)

        cls.school_unit = RegisteredSchoolUnitFactory(
            address='original address',
            phone_number='+890882333',
            email='*****@*****.**',
            district='original district',
            city='original city',
            name='original name',
            school_principal=cls.principal,
            academic_profile=cls.academic_profile1)
        cls.school_unit.categories.add(cls.academic_profile1.category)

        cls.url = reverse('schools:school-unit-detail',
                          kwargs={'id': cls.school_unit.id})
    def test_study_class_cloned_to_next_year_wrong_user_type(self, user_role):
        if user_role == UserProfile.UserRoles.ADMINISTRATOR:
            user = UserProfileFactory(user_role=user_role)
        else:
            user = UserProfileFactory(user_role=user_role, school_unit=self.school_unit)
        self.client.login(username=user.username, password='******')

        response = self.client.get(self.build_url(self.study_class.id))
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Ejemplo n.º 16
0
 def setUpTestData(cls):
     AcademicYearCalendarFactory()
     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)
Ejemplo n.º 17
0
 def setUpTestData(cls):
     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.academic_year = 2020
Ejemplo n.º 18
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)
Ejemplo n.º 19
0
 def setUpTestData(cls):
     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.url = reverse('notifications:my-sent-message-list')
Ejemplo n.º 20
0
    def test_current_academic_year_calendar_update_wrong_user_type(
            self, user_role):
        profile = UserProfileFactory(user_role=user_role,
                                     school_unit=self.school_unit)
        self.client.login(username=profile.username, password='******')

        response = self.client.put(self.url, self.data)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        profile.delete()
 def setUpTestData(cls):
     AcademicYearCalendarFactory()
     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.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=StudyClassFactory(school_unit=cls.school_unit))
     cls.subject = SubjectFactory()
 def test_user_profile_update_forbidden_user_role(self, user_role, forbidden_roles):
     self.client.login(username=UserProfile.objects.filter(user_role=user_role).first().username, password='******')
     for forbidden_role in forbidden_roles:
         profile = UserProfileFactory(user_role=forbidden_role)
         if forbidden_role != UserProfile.UserRoles.ADMINISTRATOR:
             profile.school_unit = self.school_unit
             profile.save()
         self.data['user_role'] = forbidden_role
         response = self.client.put(self.build_url(profile.id), self.data)
         self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
Ejemplo n.º 23
0
    def test_parent_list_wrong_user_type(self, user_role):
        profile = UserProfileFactory(
            user_role=user_role,
            school_unit=self.school_unit
            if user_role != UserProfile.UserRoles.ADMINISTRATOR else None)
        self.client.login(username=profile.username, password='******')

        response = self.client.get(self.url)
        self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)

        profile.delete()
 def setUpTestData(cls):
     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)
     TeacherClassThroughFactory(teacher=cls.teacher,
                                study_class=cls.study_class)
    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)
 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
     )
    def setUpTestData(cls):
        cls.url = reverse('users:my-account')
        cls.administrator = UserProfileFactory(user_role=UserProfile.UserRoles.ADMINISTRATOR)
        cls.principal = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL)
        cls.teacher = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER)
        cls.parent = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT)
        cls.student = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT)
        cls.registered_school_unit = RegisteredSchoolUnitFactory(school_principal=cls.principal)

        for user in UserProfile.objects.exclude(user_role=UserProfile.UserRoles.ADMINISTRATOR):
            user.school_unit = cls.registered_school_unit
            user.save()
    def test_delete_user_student_has_data(self):
        self.client.login(username=self.principal.username, password='******')
        student1 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit)
        SubjectGradeFactory(student=student1)
        student2 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit)
        SubjectAbsenceFactory(student=student2)
        student3 = UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, school_unit=self.school_unit)
        ExaminationGradeFactory(student=student3)

        for student in [student1, student2, student3]:
            response = self.client.delete(self.build_url(student.id))
            self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
            self.assertEqual(response.data['message'], "This user cannot be deleted because it's either active or has data.")
    def test_deactivate_user_no_request_data_success(self, login_user, user_role):
        self.client.login(username=getattr(self, login_user).username, password='******')
        profile = UserProfileFactory(
            user_role=user_role, is_active=True,
            school_unit=self.school_unit if user_role not in [UserProfile.UserRoles.ADMINISTRATOR, UserProfile.UserRoles.PRINCIPAL] else None
        )

        response = self.client.post(self.build_url(profile.id), data={})
        self.assertEqual(response.status_code, status.HTTP_200_OK)

        profile.refresh_from_db()
        self.assertFalse(profile.is_active)
        self.assertFalse(profile.user.is_active)
    def setUpTestData(cls):
        cls.calendar = AcademicYearCalendarFactory()
        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.url = reverse('statistics:study-classes-at-risk')
        cls.expected_fields = [
            'id', 'class_grade', 'class_letter', 'students_at_risk_count'
        ]