def test_district_list_registered_school_units(self): self.client.login(username=self.admin_user.username, password='******') # Create some registered school units rsu1 = RegisteredSchoolUnitFactory(district='Bihor') rsu2 = RegisteredSchoolUnitFactory(district='Cluj') RegisteredSchoolUnitFactory(district='Cluj') # First test that registered school units aren't returned without the query param response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data, []) # Now send the registered_schools param response = self.client.get(self.url, {'registered_schools': 'true'}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [rsu1.district, rsu2.district]) # Search by district name response = self.client.get(self.url, { 'registered_schools': 'true', 'search': 'Bi' }) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertCountEqual(response.data, [ rsu1.district, ])
def test_registered_school_unit_list_filter(self, filter_kwargs): self.client.login(username=self.admin_user.username, password='******') if list(filter_kwargs.keys())[0] == 'categories': rsu1 = RegisteredSchoolUnitFactory() category = SchoolUnitCategoryFactory() rsu1.categories.add(category) filter_kwargs = {'categories': category.id} elif list(filter_kwargs.keys())[0] == 'academic_profile': category = SchoolUnitCategoryFactory() academic_profile = SchoolUnitProfileFactory(category=category) rsu1 = RegisteredSchoolUnitFactory( academic_profile=academic_profile) filter_kwargs = {'academic_profile': academic_profile.id} else: rsu1 = RegisteredSchoolUnitFactory(**filter_kwargs) RegisteredSchoolUnitFactory() response = self.client.get(self.url, filter_kwargs) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), 1) self.assertEqual(response.data['results'][0]['id'], rsu1.id)
def test_registered_school_unit_list_search(self): self.client.login(username=self.admin_user.username, password='******') RegisteredSchoolUnitFactory(name='rsu1') RegisteredSchoolUnitFactory(name='rsu2') response = self.client.get(self.url, {'search': 'rsu1'}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), 1) self.assertEqual(response.data['results'][0]['name'], 'rsu1')
def test_inactive_school_units_success(self): self.client.login(username=self.admin.username, password='******') expected_fields = ['id', 'name', 'last_change_in_catalog'] today = timezone.now().replace(tzinfo=utc) school1 = RegisteredSchoolUnitFactory(last_change_in_catalog=today - timedelta(days=31)) school2 = RegisteredSchoolUnitFactory(last_change_in_catalog=today - timedelta(days=30)) school3 = RegisteredSchoolUnitFactory(last_change_in_catalog=today - timedelta(days=15)) response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data['results']), 2) self.assertCountEqual(response.data['results'][0].keys(), expected_fields) self.assertEqual(response.data['results'][0]['id'], school2.id) self.assertEqual(response.data['results'][1]['id'], school1.id)
def test_unregistered_school_unit_list_success(self): self.client.login(username=self.admin_user.username, password='******') # Check the case where no registered school units are found su = SchoolUnitFactory(name='school1', city='city1', district='district1') response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(response.data[0]['id'], su.id) expected_fields = ['id', 'name', 'district', 'city'] self.assertCountEqual(response.data[0].keys(), expected_fields) # Check the case where a registered school unit with the same name district and city exists rsu = RegisteredSchoolUnitFactory(name='school1', city='city1', district='district1') response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 0) # Add a registered school with the same name, but in a different city in the same district unique_school = SchoolUnitFactory(name='school1', city='city2', district='district1') response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) # Add a registered school with the same name, and city but different district unique_school = SchoolUnitFactory(name='school1', city='city2', district='district3') response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2)
def setUpTestData(cls): AcademicYearCalendarFactory() cls.school_unit = RegisteredSchoolUnitFactory() cls.student = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit) cls.url = reverse('statistics:own-absences-evolution')
def setUpTestData(cls): cls.calendar = AcademicYearCalendarFactory() cls.principal = UserProfileFactory( user_role=UserProfile.UserRoles.PRINCIPAL) cls.school_unit = RegisteredSchoolUnitFactory( school_principal=cls.principal) cls.url = reverse('statistics:school-students-at-risk')
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 setUpTestData(cls): cls.academic_year_calendar = AcademicYearCalendarFactory() cls.school_unit = RegisteredSchoolUnitFactory() cls.principal = cls.school_unit.school_principal cls.subject1 = SubjectFactory() cls.subject2 = SubjectFactory() cls.subject3 = SubjectFactory() cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_grade_arabic=10, class_grade='X', class_letter='B') TeacherClassThroughFactory(study_class=cls.study_class, teacher=cls.study_class.class_master, subject=cls.subject1, is_class_master=True) TeacherClassThroughFactory(study_class=cls.study_class, teacher=cls.study_class.class_master, subject=cls.subject2, is_class_master=True) cls.source_study_class = StudyClassFactory(class_grade='X', class_grade_arabic=10, school_unit=cls.school_unit) cls.student = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.source_study_class) cls.expected_fields = [ 'id', 'class_grade', 'class_letter', 'academic_year', 'academic_program', 'academic_program_name', 'class_master', 'teachers_class_through', 'students', 'has_previous_catalog_data' ]
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 test_registered_school_unit_create_wrong_user_type(self, user_role): school_unit = RegisteredSchoolUnitFactory() user = UserProfileFactory(user_role=user_role, school_unit=school_unit) self.client.login(username=user.username, password='******') response = self.client.post(self.url, self.request_data) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
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_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_user_profile_my_account_retrieve_expected_fields(self): rsu = RegisteredSchoolUnitFactory() for user_role in [ UserProfile.UserRoles.ADMINISTRATOR, UserProfile.UserRoles.PRINCIPAL, UserProfile.UserRoles.TEACHER, UserProfile.UserRoles.PARENT, UserProfile.UserRoles.STUDENT ]: expected_fields = [ 'id', 'full_name', 'user_role', 'email', 'phone_number', 'use_phone_as_username', 'email_notifications_enabled', 'sms_notifications_enabled', 'push_notifications_enabled', 'school_unit' ] if user_role == UserProfile.UserRoles.STUDENT: expected_fields += [ 'class_grade', 'class_letter', 'personal_id_number', 'birth_date', 'address' ] if user_role == UserProfile.UserRoles.PARENT: expected_fields += ['address', 'children'] profile = UserProfileFactory( user_role=user_role, school_unit=rsu 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_200_OK) self.assertCountEqual(response.data.keys(), expected_fields) self.assertEqual(response.data['id'], profile.id) self.assertEqual( response.data['school_unit'], profile.school_unit.id if profile.school_unit else None)
def test_study_class_receiver_counts_study_class_from_another_school(self): self.client.login(username=self.principal.username, password='******') school_unit = RegisteredSchoolUnitFactory() study_class = StudyClassFactory(school_unit=school_unit) response = self.client.get(self.build_url(study_class.id)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_school_principal_list_wrong_user_type(self, user_role): school_unit = RegisteredSchoolUnitFactory() profile = UserProfileFactory(user_role=user_role, school_unit=school_unit) self.client.login(username=profile.username, password='******') response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
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)
def test_institutions_absences_wrong_user_type(self, user_role): school = RegisteredSchoolUnitFactory() user = UserProfileFactory(user_role=user_role, school_unit=school) self.client.login(username=user.username, password='******') response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
def test_registered_school_unit_create_validate_principal(self): self.client.login(username=self.admin_user.username, password='******') # Inexistent school principal self.request_data['school_principal'] = 0 response = self.client.post(self.url, self.request_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, {'school_principal': ['Invalid pk "0" - object does not exist.']}) # Inactive principal self.principal.is_active = False self.principal.save() self.request_data['school_principal'] = self.principal.id response = self.client.post(self.url, self.request_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, {'school_principal': ['Invalid user.']}) self.principal.is_active = True self.principal.save() # The school principal is already assigned to another school RegisteredSchoolUnitFactory(school_principal=self.principal) response = self.client.post(self.url, self.request_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, {'school_principal': ['This field must be unique.']})
def test_delete_user_principal_has_school(self): school_unit = RegisteredSchoolUnitFactory() self.client.login(username=self.admin.username, password='******') response = self.client.delete(self.build_url(school_unit.school_principal.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_study_class_create_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='******') # 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) # 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.post(self.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.post(self.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 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)
def test_move_student_study_class_does_not_belong_to_school(self): self.client.login(username=self.principal.username, password='******') self.study_class.school_unit = RegisteredSchoolUnitFactory() self.study_class.save() response = self.client.post( self.build_url(self.student.id, self.study_class.id), {}) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def test_city_by_district_list_wrong_user_type(self, user_role): school_unit = RegisteredSchoolUnitFactory() user = UserProfileFactory(user_role=user_role, school_unit=school_unit) self.client.login(username=user.username, password='******') response = self.client.get(self.build_url()) self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
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 setUpTestData(cls): cls.principal = UserProfileFactory( user_role=UserProfile.UserRoles.PRINCIPAL) cls.school_unit = RegisteredSchoolUnitFactory( school_principal=cls.principal) cls.academic_program = AcademicProgramFactory( school_unit=cls.school_unit)
def test_study_class_update_validate_academic_program(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='******') program1 = AcademicProgramFactory(school_unit=self.school_unit, academic_year=2010) program2 = AcademicProgramFactory(school_unit=RegisteredSchoolUnitFactory()) program3 = AcademicProgramFactory(school_unit=self.school_unit) program3.generic_academic_program.category.category_level = SchoolUnitCategory.CategoryLevels.PRIMARY_SCHOOL program3.generic_academic_program.category.save() for program in [program1, program2, program3]: self.highschool_request_data['academic_program'] = program.id url = self.build_url(self.study_class1.id) response = self.client.put(url, self.highschool_request_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, {'academic_program': ['Invalid academic program.']}) StudyClassFactory(school_unit=self.school_unit, class_master=self.teacher1, class_grade='IX', class_grade_arabic=9, academic_year=self.study_class1.academic_year - 1) self.highschool_request_data['academic_program'] = self.academic_program2.id self.highschool_request_data['class_grade'] = 'X' response = self.client.put(url, self.highschool_request_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data['academic_program'], ['Cannot change the academic program for a class that has previous catalog data.'])
def test_delete_academic_program_different_school(self): profile = UserProfileFactory(user_role=UserProfile.UserRoles.PRINCIPAL) RegisteredSchoolUnitFactory(school_principal=profile) self.client.login(username=profile.username, password='******') response = self.client.delete(self.build_url(self.academic_program.id)) self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
def setUpTestData(cls): cls.school_unit = RegisteredSchoolUnitFactory() cls.teacher = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit) cls.academic_year = 2020 cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_master=cls.teacher, class_grade='IX', class_grade_arabic=9) cls.coordination_subject = SubjectFactory(name='Dirigentie', is_coordination=True) TeacherClassThroughFactory(study_class=cls.study_class, teacher=cls.teacher, subject=cls.coordination_subject, is_class_master=True) cls.subject1 = SubjectFactory(name='Subject') cls.subject2 = SubjectFactory(name='Another Subject') cls.expected_fields = [ 'id', 'class_grade', 'class_letter', 'academic_year', 'academic_program_name', 'class_master', 'taught_subjects', 'is_class_master' ] cls.class_master_fields = ['id', 'full_name'] cls.taught_subject_fields = [ 'id', 'name', 'is_coordination', 'allows_exemption', 'is_optional' ]
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)