def setUpTestData(cls): cls.calendar = AcademicYearCalendarFactory() cls.school_unit = RegisteredSchoolUnitFactory() cls.teacher = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit) cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_master=cls.teacher) cls.expected_fields = [ 'id', 'student', 'behavior_grade_sem1', 'behavior_grade_annual', 'behavior_grade_limit' ] cls.student_expected_fields = ['id', 'full_name'] cls.url = reverse('statistics:own-students-behavior-grades')
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=1, 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.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, teacher=cls.teacher, subject=cls.subject) 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', 'abs_count_sem1', 'abs_count_sem2', 'abs_count_annual', 'avg_limit', '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', 'third_of_hours_count_sem1', 'third_of_hours_count_sem2', 'third_of_hours_count_annual', 'is_coordination_subject' ]
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)
def setUpTestData(cls): cls.school = RegisteredSchoolUnitFactory() cls.teacher = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school) cls.study_class = StudyClassFactory(school_unit=cls.school, class_grade='IX', class_grade_arabic=9, class_letter='A') cls.student = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school, student_in_class=cls.study_class) cls.subject = SubjectFactory() cls.teacher_class_through = TeacherClassThroughFactory( study_class=cls.study_class, teacher=cls.teacher, subject=cls.subject) cls.current_calendar = AcademicYearCalendarFactory() cls.label = LabelFactory(user_role=UserProfile.UserRoles.STUDENT, text='good') cls.label2 = LabelFactory(user_role=UserProfile.UserRoles.STUDENT, text='v good') cls.subject_through = ProgramSubjectThroughFactory( subject=cls.subject, class_grade='IX', class_grade_arabic=9, is_mandatory=True, generic_academic_program=cls.study_class.academic_program. generic_academic_program, weekly_hours_count=1, ) cls.differences_event = SchoolEventFactory( event_type=SchoolEvent.EventTypes.DIFERENTE, semester=cls.current_calendar.first_semester, academic_year_calendar=cls.current_calendar, starts_at=datetime.date(2019, 12, 21), ends_at=datetime.date(2019, 12, 23)) cls.second_examination_event = SchoolEventFactory( event_type=SchoolEvent.EventTypes.CORIGENTE, academic_year_calendar=cls.current_calendar, starts_at=datetime.date(2020, 5, 4), ends_at=datetime.date(2020, 5, 7)) cls.catalog_per_year = StudentCatalogPerYearFactory( study_class=cls.study_class, student=cls.student) cls.file_name = 'file.csv'
def setUpTestData(cls): cls.principal = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL) cls.school_unit = RegisteredSchoolUnitFactory(school_principal=cls.principal, academic_profile=SchoolUnitProfileFactory(name='Sportiv')) cls.generic_academic_program = GenericAcademicProgramFactory( optional_subjects_weekly_hours={ "IX": 10, "X": 1 }, academic_profile=cls.school_unit.academic_profile ) cls.school_unit.categories.add(cls.generic_academic_program.category) cls.subject = SubjectFactory(name='Subject') cls.mandatory_subject = SubjectFactory(name='Mandatory') cls.mandatory_through = ProgramSubjectThroughFactory( generic_academic_program=cls.generic_academic_program, subject=cls.mandatory_subject, class_grade='IX', class_grade_arabic=9 ) cls.academic_year = 2020 cls.academic_year_calendar = AcademicYearCalendarFactory(academic_year=cls.academic_year)
def test_unregistered_academic_program_list(self): self.client.login(username=self.principal.username, password='******') AcademicYearCalendarFactory() generic_program1 = GenericAcademicProgramFactory( name='Program B', category=self.category, academic_profile=self.academic_profile) generic_program2 = GenericAcademicProgramFactory( name='Program A', category=self.category, academic_profile=self.academic_profile) generic_program3 = GenericAcademicProgramFactory( name='Program C', category=self.category, academic_profile=self.academic_profile) GenericAcademicProgramFactory(name='Program D') AcademicProgramFactory(school_unit=self.school_unit, generic_academic_program=generic_program3) AcademicProgramFactory(school_unit=self.school_unit, generic_academic_program=generic_program2, academic_year=2018) response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) self.assertEqual(response.data[0]['id'], generic_program2.id) self.assertEqual(response.data[1]['id'], generic_program1.id) # Search by name response = self.client.get(self.url, {'search': 'Program B'}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) self.assertEqual(response.data[0]['id'], generic_program1.id) self.assertCountEqual(response.data[0].keys(), ['id', 'name'])
def test_generate_next_year_academic_calendar(self): current_calendar = AcademicYearCalendarFactory() event1 = SchoolEventFactory(semester=current_calendar.first_semester) event2 = SchoolEventFactory(semester=current_calendar.second_semester) event3 = SchoolEventFactory(academic_year_calendar=current_calendar) generate_next_year_academic_calendar() new_calendar = AcademicYearCalendar.objects.filter( academic_year=current_calendar.academic_year + 1).first() self.assertIsNotNone(new_calendar) self.assertTrue( SemesterCalendar.objects.filter( starts_at=current_calendar.first_semester.starts_at + relativedelta(years=1), ends_at=current_calendar.first_semester.ends_at + relativedelta(years=1), first_semester_academic_year_calendar=new_calendar).exists()) self.assertTrue( SemesterCalendar.objects.filter( starts_at=current_calendar.second_semester.starts_at + relativedelta(years=1), ends_at=current_calendar.second_semester.ends_at + relativedelta(years=1), second_semester_academic_year_calendar=new_calendar).exists()) for event in [event1, event2, event3]: self.assertTrue( SchoolEvent.objects.filter( starts_at=event.starts_at + relativedelta(years=1), ends_at=event.ends_at + relativedelta(years=1), academic_year_calendar=new_calendar if event.academic_year_calendar else None, semester=new_calendar.first_semester if event.semester == current_calendar.first_semester else new_calendar.second_semester if event.semester else None).exists())
def setUpTestData(cls): cls.calendar = AcademicYearCalendarFactory() cls.school_unit = RegisteredSchoolUnitFactory() cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_grade='IX', class_grade_arabic=9) cls.parent = UserProfileFactory(user_role=UserProfile.UserRoles.PARENT, school_unit=cls.school_unit) cls.student = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class) cls.student.parents.add(cls.parent) StudentCatalogPerYearFactory(student=cls.student, study_class=cls.study_class) cls.student_catalog_per_subject = StudentCatalogPerSubjectFactory( student=cls.student, study_class=cls.study_class) ProgramSubjectThroughFactory( academic_program=cls.study_class.academic_program, class_grade=cls.study_class.class_grade, subject=cls.student_catalog_per_subject.subject, weekly_hours_count=5)
def setUpTestData(cls): cls.calendar = AcademicYearCalendarFactory( first_semester__starts_at=datetime(2019, 9, 9), first_semester__ends_at=datetime(2020, 1, 12), second_semester__starts_at=datetime(2020, 1, 13), second_semester__ends_at=datetime(2020, 6, 12)) cls.create_semester_end_events(cls.calendar) subject = SubjectFactory(name='Matematică') cls.school1 = RegisteredSchoolUnitFactory() cls.study_class1 = StudyClassFactory(school_unit=cls.school1) # No risk cls.student1 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class1) StudentCatalogPerYearFactory(student=cls.student1, study_class=cls.study_class1) # Absences risk 1 cls.student2 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class1) StudentCatalogPerYearFactory(student=cls.student2, study_class=cls.study_class1, unfounded_abs_count_sem1=1, unfounded_abs_count_sem2=3) # Absences risk 2 cls.student3 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class1) StudentCatalogPerYearFactory(student=cls.student3, study_class=cls.study_class1, unfounded_abs_count_sem1=4, unfounded_abs_count_sem2=5) cls.study_class2 = StudyClassFactory(school_unit=cls.school1, class_grade='X', class_grade_arabic=10) # Grades risk 1 cls.student4 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class2) StudentCatalogPerYearFactory(student=cls.student4, study_class=cls.study_class2) cls.catalog4 = StudentCatalogPerSubjectFactory( student=cls.student4, study_class=cls.study_class2, subject=subject, avg_sem1=5, avg_sem2=6) # Grades risk 2 (sem II) cls.student5 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class2) StudentCatalogPerYearFactory(student=cls.student5, study_class=cls.study_class2) cls.catalog5 = StudentCatalogPerSubjectFactory( student=cls.student5, study_class=cls.study_class2, subject=subject, avg_sem1=7, avg_sem2=4) cls.study_class3 = StudyClassFactory(school_unit=cls.school1, class_grade='XII', class_grade_arabic=12) # Behavior grade risk 1 (sem II) cls.student6 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class3) StudentCatalogPerYearFactory(student=cls.student6, study_class=cls.study_class3, behavior_grade_sem1=10, behavior_grade_sem2=9) # Behavior grade risk 2 cls.student7 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class3) StudentCatalogPerYearFactory(student=cls.student7, study_class=cls.study_class3, behavior_grade_sem1=7, behavior_grade_sem2=6) cls.school2 = RegisteredSchoolUnitFactory() cls.school2.categories.add( SchoolUnitCategoryFactory(name='Liceu - Filieră Tehnologică')) cls.study_class4 = StudyClassFactory(school_unit=cls.school2, class_grade='VIII', class_grade_arabic=8) # Absences risk 1 + Grades risk 2 cls.student8 = UserProfileFactory( school_unit=cls.school2, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class4) StudentCatalogPerYearFactory(student=cls.student8, study_class=cls.study_class4, unfounded_abs_count_sem1=1, unfounded_abs_count_sem2=3) cls.catalog8 = StudentCatalogPerSubjectFactory( student=cls.student8, study_class=cls.study_class4, subject=subject, avg_sem1=4, avg_sem2=4) # Grades risk 1 + Behavior grade risk 2 (sem II) cls.student9 = UserProfileFactory( school_unit=cls.school2, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class4) StudentCatalogPerYearFactory(student=cls.student9, study_class=cls.study_class4, behavior_grade_sem1=10, behavior_grade_sem2=7) cls.catalog9 = StudentCatalogPerSubjectFactory( student=cls.student9, study_class=cls.study_class4, subject=subject, avg_sem1=7, avg_sem2=6) cls.study_class5 = StudyClassFactory(school_unit=cls.school2, class_grade='IX', class_grade_arabic=9) # Absences risk 2 (both sem) + Behavior grade risk 1 (sem II) cls.student10 = UserProfileFactory( school_unit=cls.school2, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class5) StudentCatalogPerYearFactory(student=cls.student10, study_class=cls.study_class5, behavior_grade_sem1=10, behavior_grade_sem2=9, unfounded_abs_count_sem1=4, unfounded_abs_count_sem2=5) # Absences risk 2 + Grades risk 2 + Behavior grade risk 2 cls.student11 = UserProfileFactory( school_unit=cls.school2, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class5) StudentCatalogPerYearFactory(student=cls.student11, study_class=cls.study_class5, behavior_grade_sem1=7, behavior_grade_sem2=6, unfounded_abs_count_sem1=4, unfounded_abs_count_sem2=6) cls.catalog11 = StudentCatalogPerSubjectFactory( student=cls.student11, study_class=cls.study_class5, subject=subject, avg_sem1=4, avg_sem2=3) cls.create_risk_stats()
def setUpTestData(cls): AcademicYearCalendarFactory() # Administrators cls.admin1 = UserProfileFactory( user_role=UserProfile.UserRoles.ADMINISTRATOR, full_name='B name') cls.admin2 = UserProfileFactory( user_role=UserProfile.UserRoles.ADMINISTRATOR, full_name='B name', is_active=False) cls.admin3 = UserProfileFactory( user_role=UserProfile.UserRoles.ADMINISTRATOR, full_name='D name', last_online=timezone.now()) # School principals cls.principal1 = UserProfileFactory( user_role=UserProfile.UserRoles.PRINCIPAL, full_name='C name', last_online=timezone.now()) cls.school_unit1 = RegisteredSchoolUnitFactory( school_principal=cls.principal1) cls.principal2 = UserProfileFactory( user_role=UserProfile.UserRoles.PRINCIPAL, full_name='A name', is_active=False) cls.school_unit2 = RegisteredSchoolUnitFactory( school_principal=cls.principal2) cls.principal3 = UserProfileFactory( user_role=UserProfile.UserRoles.PRINCIPAL, full_name='A name') # Teachers cls.teacher1 = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, full_name='C name', last_online=timezone.now(), school_unit=cls.school_unit1) cls.teacher2 = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, full_name='C name', is_active=False, school_unit=cls.school_unit1) UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, full_name='name', school_unit=cls.school_unit2) # Parents cls.parent1 = UserProfileFactory( user_role=UserProfile.UserRoles.PARENT, full_name='B name', school_unit=cls.school_unit1) cls.parent2 = UserProfileFactory( user_role=UserProfile.UserRoles.PARENT, full_name='A name', is_active=False, school_unit=cls.school_unit1) UserProfileFactory(user_role=UserProfile.UserRoles.PARENT, full_name='name', school_unit=cls.school_unit2) # Students cls.student1 = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, full_name='A name', school_unit=cls.school_unit1) cls.student2 = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, full_name='B name', is_active=False, school_unit=cls.school_unit1) UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='name', school_unit=cls.school_unit2) cls.url = reverse('users:user-profile-list') cls.expected_fields = [ 'id', 'full_name', 'user_role', 'is_active', 'last_online', 'labels', 'risk_description', 'school_unit', 'assigned_study_classes' ]
def setUpTestData(cls): cls.academic_year_calendar = AcademicYearCalendarFactory() cls.school_unit = RegisteredSchoolUnitFactory()
def setUpTestData(cls): cls.calendar = AcademicYearCalendarFactory( first_semester__starts_at=datetime(2019, 9, 9), first_semester__ends_at=datetime(2020, 1, 12), second_semester__starts_at=datetime(2020, 1, 13), second_semester__ends_at=datetime(2020, 6, 12)) cls.create_semester_end_events(cls.calendar) cls.subject = SubjectFactory(name='Matematică') cls.subject2 = SubjectFactory(name='Limba Romana') coordination_subject = SubjectFactory(is_coordination=True) cls.school1 = RegisteredSchoolUnitFactory() cls.study_class1 = StudyClassFactory(school_unit=cls.school1) # behavior grade for the 1st semester lower than 8 and subject average grade for the 1st semester lower than 5 cls.student1 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class1) cls.parent1 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.PARENT) cls.student1.parents.add(cls.parent1) StudentCatalogPerYearFactory(student=cls.student1, study_class=cls.study_class1) StudentCatalogPerSubjectFactory(student=cls.student1, study_class=cls.study_class1, subject=cls.subject, avg_sem1=4, avg_final=6) StudentCatalogPerSubjectFactory(student=cls.student1, study_class=cls.study_class1, subject=coordination_subject, avg_sem1=7, avg_final=9) cls.study_class2 = StudyClassFactory(school_unit=cls.school1, class_grade='XII', class_grade_arabic=12) # Average below limit (both sem) - 12th grade cls.student2 = UserProfileFactory( school_unit=cls.school1, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class2) StudentCatalogPerYearFactory(student=cls.student2, study_class=cls.study_class2) StudentCatalogPerSubjectFactory(student=cls.student2, study_class=cls.study_class2, subject=cls.subject) StudentCatalogPerSubjectFactory(student=cls.student2, study_class=cls.study_class2, subject=cls.subject, avg_sem1=4, avg_sem2=1) cls.school2 = RegisteredSchoolUnitFactory() cls.school2.categories.add( SchoolUnitCategoryFactory(name='Liceu - Filieră Tehnologică')) cls.study_class3 = StudyClassFactory(school_unit=cls.school2, class_grade='VIII', class_grade_arabic=8) # Average below limit (both sem) - 8th grade cls.student3 = UserProfileFactory( school_unit=cls.school2, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class3) StudentCatalogPerYearFactory(student=cls.student3, study_class=cls.study_class3) StudentCatalogPerSubjectFactory(student=cls.student3, study_class=cls.study_class3, subject=cls.subject, avg_sem1=4, avg_sem2=3) cls.study_class4 = StudyClassFactory(school_unit=cls.school2, class_grade='IX', class_grade_arabic=9) # Averages below limit (both sem) - 9th grade, technological cls.student4 = UserProfileFactory( school_unit=cls.school2, user_role=UserProfile.UserRoles.STUDENT, student_in_class=cls.study_class4) StudentCatalogPerYearFactory(student=cls.student4, study_class=cls.study_class4) StudentCatalogPerSubjectFactory(student=cls.student4, study_class=cls.study_class4, subject=cls.subject, avg_sem1=4, avg_sem2=2) StudentCatalogPerSubjectFactory(student=cls.student4, study_class=cls.study_class4, subject=cls.subject2, avg_sem1=3, avg_sem2=4)
def setUpTestData(cls): cls.academic_year_calendar = AcademicYearCalendarFactory() cls.create_semester_end_events(cls.academic_year_calendar) cls.second_semester_end_events = get_second_semester_end_events( cls.academic_year_calendar)
class CurrentAcademicYearCalendarUpdateTestCase(CommonAPITestCase): @classmethod def setUpTestData(cls): cls.url = reverse('academic_calendars:current-academic-year-calendar') cls.admin = UserProfileFactory( user_role=UserProfile.UserRoles.ADMINISTRATOR) cls.school_unit = RegisteredSchoolUnitFactory() cls.next_year = timezone.now().year + 1 def setUp(self): self.academic_year_calendar = AcademicYearCalendarFactory( first_semester__starts_at=datetime(self.next_year, 1, 10), first_semester__ends_at=datetime(self.next_year, 4, 3), second_semester__starts_at=datetime(self.next_year, 9, 9), second_semester__ends_at=datetime(self.next_year, 12, 11)) self.data = { 'first_semester': { 'id': self.academic_year_calendar.first_semester.id, 'starts_at': date(self.next_year, 1, 1), 'ends_at': date(self.next_year, 4, 4), 'events': [] }, 'second_semester': { 'id': self.academic_year_calendar.second_semester.id, 'starts_at': date(self.next_year, 9, 9), 'ends_at': date(self.next_year, 12, 12), 'events': [] }, 'events': [] } def test_current_academic_year_calendar_update_unauthenticated(self): response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_401_UNAUTHORIZED) @data( UserProfile.UserRoles.PRINCIPAL, UserProfile.UserRoles.STUDENT, UserProfile.UserRoles.PARENT, UserProfile.UserRoles.TEACHER, ) 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 test_current_academic_year_calendar_update_no_current_calendar(self): self.client.login(username=self.admin.username, password='******') self.academic_year_calendar.delete() response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND) def test_current_academic_year_calendar_update_required_fields(self): self.client.login(username=self.admin.username, password='******') # Missing required fields required_fields = ['first_semester', 'second_semester', 'events'] for field in required_fields: req_data = { required_field: self.data[required_field] for required_field in required_fields if required_field != field } response = self.client.put(self.url, req_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertCountEqual(response.data.values(), [['This field is required.']]) semester_required_fields = ['starts_at', 'ends_at', 'events'] for field in semester_required_fields: req_data = { 'first_semester': { expected_field: self.data['first_semester'][expected_field] for expected_field in semester_required_fields if expected_field != field }, 'second_semester': self.data['second_semester'] } response = self.client.put(self.url, req_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data['first_semester'][field], ['This field is required.']) event = SchoolEventFactory( semester=self.academic_year_calendar.first_semester) event_expected_fields_and_value = { 'event_type': event.event_type, 'starts_at': event.starts_at.strftime(settings.DATE_FORMAT), 'ends_at': event.ends_at.strftime(settings.DATE_FORMAT) } for field, value in event_expected_fields_and_value.items(): req_data = { 'first_semester': { 'id': self.academic_year_calendar.first_semester.id, 'starts_at': self.data['first_semester']['starts_at'], 'ends_at': self.data['first_semester']['ends_at'], 'events': [{ expected_field: event_expected_fields_and_value[expected_field] for expected_field in event_expected_fields_and_value.keys() if expected_field != field }] }, 'second_semester': self.data['second_semester'], 'events': [] } response = self.client.put(self.url, req_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'first_semester': { 'events': [{ field: ['This field is required.'] }] } }) @data('first_semester', None) def test_current_academic_year_calendar_update_event_validation( self, event_belongs_to): self.client.login(username=self.admin.username, password='******') # Event ID doesn't exist if event_belongs_to: data_dict = self.data['first_semester'] event_type = SchoolEvent.EventTypes.SPRING_HOLIDAY else: data_dict = self.data event_type = SchoolEvent.EventTypes.CORIGENTE data_dict['events'] = [{ 'id': 0, 'starts_at': date(self.next_year, 2, 2), 'ends_at': date(self.next_year, 2, 3), 'event_type': event_type }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) response_data = response.data if not event_belongs_to else response.data[ 'first_semester'] self.assertEqual(response_data, { 'events': { 'id': 'The events must belong to this academic year.' } }) # Start or end date are in the past # TODO uncomment this after it's implemented & tested on FE # last_year = timezone.now().year - 1 # data_dict['events'] = [{ # 'starts_at': date(last_year, 2, 2), # 'ends_at': date(last_year, 3, 3), # 'event_type': event_type # }] # response = self.client.put(self.url, self.data) # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # response_data = response.data if not event_type else response.data['first_semester'] # # self.assertEqual(response_data, {'events': [{'starts_at': ['The start date must be in the future.']}]}) # # data_dict['events'][0]['starts_at'] = date(self.next_year, 2, 2) # response = self.client.put(self.url, self.data) # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # response_data = response.data if not event_type else response.data['first_semester'] # self.assertEqual(response_data, {'events': [{'ends_at': ['The end date must be in the future.']}]}) # End date is before start date data_dict['events'] = [{ 'starts_at': date(self.next_year, 10, 10), 'ends_at': date(self.next_year, 10, 9), 'event_type': event_type }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) response_data = response.data if not event_belongs_to else response.data[ 'first_semester'] self.assertEqual( response_data, { 'events': [{ 'starts_at': ['The start date must be before the end date.'] }] }) # Events are outside the semester data_dict['events'] = [{ 'starts_at': date(self.next_year, 5, 5), 'ends_at': date(self.next_year, 6, 6), 'event_type': event_type }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) if event_belongs_to == 'first_semester': self.assertEqual( response.data['first_semester'], { 'events': { 'starts_at': "All events must be between the semester's start and end dates." } }) else: self.assertEqual( response.data, { 'events': { 'starts_at': f'{event_type.label} must be between the second semester end date and the end of the current year.' } }) # semester end events must belong to the second semester for event in [ SchoolEvent.EventTypes.SECOND_SEMESTER_END_VIII_GRADE, SchoolEvent.EventTypes.SECOND_SEMESTER_END_XII_XIII_GRADE ]: data_dict['events'] = [{ 'starts_at': date(self.next_year, 2, 2), 'ends_at': date(self.next_year, 2, 3), 'event_type': event }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) if not event_belongs_to: self.assertEqual( response.data, { 'events': { 'event_type': f"{event.label} must belong to a semester." } }) else: self.assertEqual( response.data['first_semester'], { 'events': { 'event_type': f"{event.label} must belong to the second semester." } }) def test_current_academic_year_calendar_update_semester_events_validation( self): self.client.login(username=self.admin.username, password='******') for bad_data in [[{ 'starts_at': date(self.next_year, 1, 2), 'ends_at': date(self.next_year, 3, 3), 'event_type': SchoolEvent.EventTypes.SPRING_HOLIDAY }, { 'starts_at': date(self.next_year, 2, 5), 'ends_at': date(self.next_year, 3, 2), 'event_type': SchoolEvent.EventTypes.LEGAL_PUBLIC_HOLIDAY }], [{ 'starts_at': date(self.next_year, 2, 2), 'ends_at': date(self.next_year, 3, 3), 'event_type': SchoolEvent.EventTypes.SPRING_HOLIDAY }, { 'starts_at': date(self.next_year, 3, 3), 'ends_at': date(self.next_year, 4, 1), 'event_type': SchoolEvent.EventTypes.LEGAL_PUBLIC_HOLIDAY }], [{ 'starts_at': date(self.next_year, 2, 2), 'ends_at': date(self.next_year, 2, 5), 'event_type': SchoolEvent.EventTypes.SPRING_HOLIDAY }, { 'starts_at': date(self.next_year, 2, 3), 'ends_at': date(self.next_year, 2, 4), 'event_type': SchoolEvent.EventTypes.LEGAL_PUBLIC_HOLIDAY }]]: self.data['first_semester']['events'] = bad_data response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, {'events': ['Events cannot overlap.']}) # CORIGENTE and DIFERENTE can't be added inside the semester for event_type in [ SchoolEvent.EventTypes.CORIGENTE, SchoolEvent.EventTypes.DIFERENTE ]: self.data['first_semester']['events'] = [{ 'starts_at': date(self.next_year, 3, 3), 'ends_at': date(self.next_year, 4, 4), 'event_type': event_type }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'first_semester': { 'events': [ f'{event_type.label} events cannot be inside semesters.' ] } }) # SECOND_SEMESTER_END_IX_XI_FILIERA_TEHNOLOGICA must be between second semester start and the end of the school year self.data['first_semester']['events'] = [] self.data['second_semester']['events'] = [{ 'starts_at': date(self.next_year, 5, 5), 'ends_at': date(self.next_year, 5, 6), 'event_type': SchoolEvent.EventTypes. SECOND_SEMESTER_END_IX_XI_FILIERA_TEHNOLOGICA }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'events': { 'starts_at': "Second semester end for Filiera Tehnologica" " must be between the second semester's start and the end of" " the current academic year." } }) def test_current_academic_year_calendar_update_year_events_validation( self): self.client.login(username=self.admin.username, password='******') for bad_data in [[{ 'starts_at': date(self.next_year, 12, 21), 'ends_at': date(self.next_year, 12, 23), 'event_type': SchoolEvent.EventTypes.CORIGENTE }, { 'starts_at': date(self.next_year, 12, 22), 'ends_at': date(self.next_year, 12, 25), 'event_type': SchoolEvent.EventTypes.CORIGENTE }], [{ 'starts_at': date(self.next_year, 12, 23), 'ends_at': date(self.next_year, 12, 25), 'event_type': SchoolEvent.EventTypes.DIFERENTE }, { 'starts_at': date(self.next_year, 12, 23), 'ends_at': date(self.next_year, 12, 26), 'event_type': SchoolEvent.EventTypes.CORIGENTE }], [{ 'starts_at': date(self.next_year, 12, 22), 'ends_at': date(self.next_year, 12, 25), 'event_type': SchoolEvent.EventTypes.DIFERENTE }, { 'starts_at': date(self.next_year, 12, 23), 'ends_at': date(self.next_year, 12, 24), 'event_type': SchoolEvent.EventTypes.DIFERENTE }]]: self.data['events'] = bad_data response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, {'events': ['Events cannot overlap.']}) def test_current_academic_year_calendar_update_semester_validation(self): self.client.login(username=self.admin.username, password='******') other_calendar = AcademicYearCalendarFactory(academic_year=2019) self.data['first_semester']['id'] = other_calendar.first_semester.id response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, { 'first_semester': ['The semester must belong to the academic year.'] }) self.data['first_semester'][ 'id'] = self.academic_year_calendar.first_semester.id self.data['first_semester']['starts_at'] = self.data['first_semester'][ 'ends_at'] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'first_semester': { 'starts_at': ['The start date must be before the end date.'] } }) self.data['first_semester']['starts_at'] = date(self.next_year, 1, 1) self.data['first_semester']['ends_at'] = date(self.next_year, 10, 10) self.data['second_semester']['starts_at'] = date(self.next_year, 5, 5) self.data['second_semester']['ends_at'] = date(self.next_year, 12, 12) response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'second_semester': [ 'Second semester must start after the end of the first semester.' ] }) self.data['first_semester']['starts_at'] = date(self.next_year, 1, 1) self.data['first_semester']['ends_at'] = date(self.next_year, 5, 5) self.data['second_semester']['starts_at'] = date(self.next_year, 6, 6) self.data['second_semester']['ends_at'] = date(self.next_year, 4, 4) response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'second_semester': { 'starts_at': ['The start date must be before the end date.'] } }) # TODO uncomment this after it's implemented & tested on FE # last_year = timezone.now().year - 1 # self.data['first_semester']['starts_at'] = date(last_year, 1, 1) # self.data['first_semester']['ends_at'] = date(last_year, 6, 6) # response = self.client.put(self.url, self.data) # self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) # self.assertEqual(response.data, {'first_semester': {'starts_at': ['The start date must be in the future.']}}) def test_current_academic_year_calendar_update_success(self): self.client.login(username=self.admin.username, password='******') response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.academic_year_calendar.refresh_from_db() expected_fields = [ 'first_semester', 'second_semester', 'academic_year', 'events' ] self.assertCountEqual(expected_fields, response.data.keys()) semester_expected_fields = ['id', 'starts_at', 'ends_at', 'events'] self.assertCountEqual(semester_expected_fields, response.data['first_semester']) self.assertCountEqual(semester_expected_fields, response.data['second_semester']) for semester in ['first_semester', 'second_semester']: self.assertEqual( getattr(self.academic_year_calendar, semester).starts_at.strftime(settings.DATE_FORMAT), self.data[semester]['starts_at']) # Try to add an event self.data['first_semester']['events'] = [{ 'starts_at': date(self.next_year, 2, 2), 'ends_at': date(self.next_year, 2, 3), 'event_type': SchoolEvent.EventTypes.LEGAL_PUBLIC_HOLIDAY }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_200_OK) event = self.academic_year_calendar.first_semester.school_events.first( ) self.assertEqual(event.starts_at, event.starts_at) # Update it self.data['first_semester']['events'] = [{ 'id': event.id, 'starts_at': date(self.next_year, 2, 2), 'ends_at': date(self.next_year, 2, 3), 'event_type': SchoolEvent.EventTypes.SPRING_HOLIDAY }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_200_OK) event.refresh_from_db() self.assertEqual(event.event_type, SchoolEvent.EventTypes.SPRING_HOLIDAY) # Add new ones self.data['first_semester']['events'] += [{ 'starts_at': date(self.next_year, 2, 6), 'ends_at': date(self.next_year, 2, 10), 'event_type': SchoolEvent.EventTypes.LEGAL_PUBLIC_HOLIDAY }, { 'starts_at': date(self.next_year, 3, 2), 'ends_at': date(self.next_year, 3, 3), 'event_type': SchoolEvent.EventTypes.LEGAL_PUBLIC_HOLIDAY }] response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( self.academic_year_calendar.first_semester.school_events.count(), 3) # Remove one of them self.data['first_semester']['events'].pop() response = self.client.put(self.url, self.data) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual( self.academic_year_calendar.first_semester.school_events.count(), 2)
def setUpTestData(cls): cls.principal = UserProfileFactory( user_role=UserProfile.UserRoles.PRINCIPAL) cls.school_unit = RegisteredSchoolUnitFactory( school_principal=cls.principal) cls.category1 = SchoolUnitCategoryFactory( category_level=SchoolUnitCategory.CategoryLevels.PRIMARY_SCHOOL) cls.category2 = SchoolUnitCategoryFactory( category_level=SchoolUnitCategory.CategoryLevels.SECONDARY_SCHOOL) cls.category3 = SchoolUnitCategoryFactory( category_level=SchoolUnitCategory.CategoryLevels.HIGHSCHOOL) cls.school_unit.categories.add(cls.category1, cls.category2, cls.category3) cls.calendar = AcademicYearCalendarFactory() cls.subject1 = SubjectFactory() cls.subject2 = SubjectFactory() cls.coordination_subject = SubjectFactory(is_coordination=True) cls.academic_program = AcademicProgramFactory( school_unit=cls.school_unit) for class_grade, class_grade_arabic in zip(['I', 'VI', 'IX'], [1, 6, 9]): ProgramSubjectThroughFactory(academic_program=cls.academic_program, subject=cls.subject1, is_mandatory=False, class_grade=class_grade, class_grade_arabic=class_grade_arabic) ProgramSubjectThroughFactory( generic_academic_program=cls.academic_program. generic_academic_program, subject=cls.subject2, class_grade=class_grade, class_grade_arabic=class_grade_arabic) cls.teacher1 = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit) cls.teacher2 = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit) cls.teacher1.taught_subjects.add(cls.subject1) cls.teacher2.taught_subjects.add(cls.subject2) cls.student1 = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit) cls.student2 = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit) cls.url = reverse('study_classes:study-class-list', kwargs={'academic_year': cls.calendar.academic_year}) cls.class_master = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit) cls.primary_school_request_data = { 'class_grade': 'I', 'class_letter': 'A', 'academic_program': cls.academic_program.id, "class_master": cls.class_master.id, "teachers_class_through": [{ "teacher": cls.teacher1.id, "subject": cls.subject1.id }, { "teacher": cls.teacher2.id, "subject": cls.subject2.id }], "students": [cls.student1.id, cls.student2.id] } cls.secondary_school_request_data = { 'class_grade': 'VI', 'class_letter': 'A1', 'academic_program': cls.academic_program.id, "class_master": cls.class_master.id, "teachers_class_through": [{ "teacher": cls.teacher1.id, "subject": cls.subject1.id }, { "teacher": cls.teacher2.id, "subject": cls.subject2.id }], "students": [cls.student1.id, cls.student2.id] }
def setUpTestData(cls): # generate subjects subject_names = [ 'Matematica', 'Limba Romana', 'Limba Engleza', 'Limba Franceza', 'Fizica', 'Chimie', 'Biologie', 'TIC', 'Educatie Fizica', 'Tehnologii generale in electronica -automatizari(M1)' ] all_subjects = [SubjectFactory(name=i) for i in subject_names] # declare helper for easier selection of subjects def select_subjects(*args): return [s for s in all_subjects if s.name in args] cls.current_calendar = AcademicYearCalendarFactory() # Generate a new school cls.school_unit1 = RegisteredSchoolUnitFactory() academic_program1 = AcademicProgramFactory( school_unit=cls.school_unit1) cls.unit1_class1 = StudyClassFactory( school_unit=cls.school_unit1, academic_program=academic_program1, class_grade='VI', class_grade_arabic=6, class_letter='A') cls.unit1_class2 = StudyClassFactory( school_unit=cls.school_unit1, academic_program=academic_program1, class_grade='VII', class_grade_arabic=7, class_letter='Z') # Add two more classes to test order cls.unit1_class3 = StudyClassFactory( school_unit=cls.school_unit1, academic_program=academic_program1, class_grade='VI', class_grade_arabic=6, class_letter='Z') cls.unit1_class4 = StudyClassFactory( school_unit=cls.school_unit1, academic_program=academic_program1, class_grade='VII', class_grade_arabic=7, class_letter='A') # Add a fifth class; this will not appear in the results since it doesn't have any `StudentCatalogPerSubject`s StudyClassFactory(school_unit=cls.school_unit1, academic_program=academic_program1, class_grade='X', class_grade_arabic=10, class_letter='A') # generate students and select subjects for the first school and class cls.unit1_class1._catalogs = [] for student in _gen_students(5): for subject in select_subjects('Matematica', 'Limba Romana', 'Limba Engleza', 'Limba Franceza'): cls.unit1_class1._catalogs.append( StudentCatalogPerSubjectFactory( study_class=cls.unit1_class1, subject=subject, student=student)) # generate students and select subjects for the first school and second class cls.unit1_class2._catalogs = [] for student in _gen_students(10): for subject in select_subjects( 'Matematica', 'Fizica', 'Tehnologii generale in electronica -automatizari(M1)'): cls.unit1_class2._catalogs.append( StudentCatalogPerSubjectFactory( study_class=cls.unit1_class2, subject=subject, student=student)) # generate students and select subjects for the first school for third and forth class for student in _gen_students(5): for subject in select_subjects('Matematica', 'Limba Romana', 'Limba Engleza', 'Biologie'): StudentCatalogPerSubjectFactory(study_class=cls.unit1_class3, subject=subject, student=student) StudentCatalogPerSubjectFactory(study_class=cls.unit1_class4, subject=subject, student=student) # Generate a new school cls.school_unit2 = RegisteredSchoolUnitFactory() academic_program2 = AcademicProgramFactory( school_unit=cls.school_unit2) cls.unit2_class1 = StudyClassFactory( school_unit=cls.school_unit2, academic_program=academic_program2, class_grade='VI', class_letter='A') cls.unit2_class2 = StudyClassFactory( school_unit=cls.school_unit2, academic_program=academic_program2, class_grade='VII', class_letter='Z') # generate students and select subjects for the second school and first class cls.unit2_class1._catalogs = [] for student in _gen_students(5): for subject in select_subjects('Matematica', 'Limba Romana', 'Limba Engleza', 'TIC'): cls.unit2_class1._catalogs.append( StudentCatalogPerSubjectFactory( study_class=cls.unit2_class1, subject=subject, student=student)) # generate students and select subjects for the second school and class cls.unit2_class2._catalogs = [] for student in _gen_students(5): for subject in select_subjects('Matematica', 'Fizica', 'Chimie', 'Educatie Fizica'): cls.unit2_class2._catalogs.append( StudentCatalogPerSubjectFactory( study_class=cls.unit2_class2, subject=subject, student=student))
def setUpTestData(cls): cls.admin = UserProfileFactory(user_role=UserProfile.UserRoles.ADMINISTRATOR) cls.url = reverse('statistics:institution-absences') cls.current_academic_calendar = AcademicYearCalendarFactory() cls.expected_fields = ['school_unit_name', 'unfounded_abs_avg_sem1', 'unfounded_abs_avg_annual']
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)
def setUpTestData(cls): cls.calendar = AcademicYearCalendarFactory() cls.school_unit = RegisteredSchoolUnitFactory() cls.teacher = UserProfileFactory(user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit) cls.url = reverse('statistics:own-students-at-risk')