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_school_unit_profile_list_success(self): self.client.login(username=self.admin_user.username, password='******') profile1 = SchoolUnitProfileFactory(name='profile 2') profile2 = SchoolUnitProfileFactory(name='profile 3') profile3 = SchoolUnitProfileFactory(name='profile 1') profile4 = SchoolUnitProfileFactory(name='profile 4', category=profile3.category) response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) results = response.data self.assertEqual(len(results), 4) self.assertEqual(profile3.id, results[0]['id']) self.assertEqual(profile1.id, results[1]['id']) self.assertEqual(profile2.id, results[2]['id']) self.assertEqual(profile4.id, results[3]['id']) expected_fields = ['id', 'name'] for result in results: self.assertCountEqual(result.keys(), expected_fields) # Search by name response = self.client.get(self.url, {'search': 'profile 1'}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 1) self.assertEqual(profile3.id, response.data[0]['id']) # Filter by one category response = self.client.get(self.url, {'category': profile3.category.id}) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) self.assertEqual(profile3.id, response.data[0]['id']) self.assertEqual(profile4.id, response.data[1]['id']) # Filter by multiple category response = self.client.get( self.url + '?category={}&category={}'.format( profile1.category.id, profile2.category.id)) self.assertEqual(response.status_code, status.HTTP_200_OK) self.assertEqual(len(response.data), 2) self.assertEqual(profile1.id, response.data[0]['id']) self.assertEqual(profile2.id, response.data[1]['id'])
def setUpTestData(cls): cls.admin_user = UserProfileFactory( user_role=UserProfile.UserRoles.ADMINISTRATOR) cls.calendar = AcademicYearCalendarFactory() cls.academic_profile = SchoolUnitProfileFactory() cls.url = reverse('schools:school-unit-list')
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_my_school_unit_success(self): self.client.login(username=self.principal.username, password='******') category = SchoolUnitCategoryFactory() academic_profile = SchoolUnitProfileFactory(category=category) self.rsu.categories.add(category) self.rsu.academic_profile = academic_profile self.rsu.save() response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) expected_fields = ['categories', 'academic_profile', 'phone_number', 'email', 'district', 'city', 'name', 'id', 'is_active', 'school_principal', 'address', ] self.assertCountEqual(response.data.keys(), expected_fields) for field in expected_fields: if field == 'categories': category_data = response.data[field][0] self.assertEqual(category.id, category_data['id']) self.assertEqual(category.name, category_data['name']) elif field == 'academic_profile': academic_profile_data = response.data[field] self.assertEqual(academic_profile.id, academic_profile_data['id']) self.assertEqual(academic_profile.name, academic_profile_data['name']) elif field == 'school_principal': principal_data = response.data[field] self.assertEqual(self.principal.id, principal_data['id']) self.assertEqual(self.principal.full_name, principal_data['full_name']) else: self.assertEqual(getattr(self.rsu, field), response.data[field])
def test_academic_program_create_invalid_academic_profile(self, mocked_method): self.client.login(username=self.principal.username, password='******') self.generic_academic_program.academic_profile = SchoolUnitProfileFactory() self.generic_academic_program.save() response = self.client.post(self.build_url(self.academic_year), self.data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual(response.data, {'generic_academic_program': ['Invalid generic academic program.']})
def setUpTestData(cls): cls.principal = UserProfileFactory( user_role=UserProfile.UserRoles.PRINCIPAL) cls.academic_profile = SchoolUnitProfileFactory() cls.category = cls.academic_profile.category cls.school_unit = RegisteredSchoolUnitFactory( school_principal=cls.principal, academic_profile=cls.academic_profile) cls.school_unit.categories.add(cls.category) cls.url = reverse( 'academic_programs:unregistered-academic-program-list')
def setUpTestData(cls): cls.calendar = AcademicYearCalendarFactory() cls.school_unit = RegisteredSchoolUnitFactory( academic_profile=SchoolUnitProfileFactory(name='Militar')) cls.study_class = StudyClassFactory(school_unit=cls.school_unit, class_grade='IX', class_grade_arabic=9) cls.student = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class) cls.url = reverse('statistics:own-subjects-at-risk')
def test_registered_school_unit_create_validate_academic_profile(self): self.client.login(username=self.admin_user.username, password='******') academic_profile2 = SchoolUnitProfileFactory() self.request_data['academic_profile'] = academic_profile2.id response = self.client.post(self.url, self.request_data) self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST) self.assertEqual( response.data, { 'academic_profile': [ 'The academic profile does not correspond with the school category.' ] })
def setUpTestData(cls): cls.school_unit = RegisteredSchoolUnitFactory( academic_profile=SchoolUnitProfileFactory(name='Artistic')) cls.study_class = StudyClassFactory(school_unit=cls.school_unit) cls.student = UserProfileFactory( user_role=UserProfile.UserRoles.STUDENT, school_unit=cls.school_unit, student_in_class=cls.study_class) cls.catalog = StudentCatalogPerSubjectFactory( student=cls.student, study_class=cls.study_class) cls.study_class.academic_program.core_subject = cls.catalog.subject cls.study_class.academic_program.save() cls.url = reverse('statistics:own-activity-history')
def test_registered_school_unit_list_success(self): self.client.login(username=self.admin_user.username, password='******') # Create two active registered school units and two inactive ones rsu1 = RegisteredSchoolUnitFactory(is_active=True, name='c') rsu2 = RegisteredSchoolUnitFactory(is_active=True, name='d') rsu3 = RegisteredSchoolUnitFactory(is_active=False, name='b') rsu4 = RegisteredSchoolUnitFactory(is_active=False, name='a') # Also add a category for one of the school units category = SchoolUnitCategoryFactory() academic_profile = SchoolUnitProfileFactory(category=category) rsu1.categories.add(category) rsu1.academic_profile = academic_profile rsu1.save() response = self.client.get(self.url) self.assertEqual(response.status_code, status.HTTP_200_OK) # The school units should be ordered by is_active, then name results = response.data['results'] self.assertEqual(results[0]['id'], rsu1.id) self.assertEqual(results[1]['id'], rsu2.id) self.assertEqual(results[2]['id'], rsu4.id) self.assertEqual(results[3]['id'], rsu3.id) expected_fields = [ 'id', 'name', 'categories', 'academic_profile', 'is_active', 'district', 'city' ] for result in results: self.assertCountEqual(result.keys(), expected_fields) if result['id'] == rsu1.id: self.assertCountEqual( result['categories'], [{ 'name': category.name, 'id': category.id, 'category_level': category.category_level }]) self.assertCountEqual(result['academic_profile'], { 'name': academic_profile.name, 'id': academic_profile.id })
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 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) cls.teacher = UserProfileFactory( user_role=UserProfile.UserRoles.TEACHER, school_unit=cls.school_unit) cls.study_class = StudyClassFactory(school_unit=cls.school_unit) cls.teacher_class_through = TeacherClassThroughFactory( study_class=cls.study_class, teacher=cls.teacher) another_study_class = StudyClassFactory(school_unit=cls.school_unit, class_grade='IX', class_grade_arabic=9) cls.another_school_unit = RegisteredSchoolUnitFactory( academic_profile=SchoolUnitProfileFactory(name='Militar')) cls.catalog1 = StudentCatalogPerYearFactory( student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student a', school_unit=cls.another_school_unit), study_class=StudyClassFactory(school_unit=cls.another_school_unit), avg_sem1=1, avg_sem2=1, avg_final=1, second_examinations_count=1, unfounded_abs_count_sem1=1, unfounded_abs_count_sem2=1, unfounded_abs_count_annual=1, behavior_grade_sem1=1, behavior_grade_sem2=1, behavior_grade_annual=1, ) cls.catalog2 = StudentCatalogPerYearFactory( student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student b', school_unit=cls.school_unit), study_class=another_study_class, avg_sem1=2, avg_sem2=2, avg_final=2, second_examinations_count=2, unfounded_abs_count_sem1=2, unfounded_abs_count_sem2=2, unfounded_abs_count_annual=2, behavior_grade_sem1=2, behavior_grade_sem2=2, behavior_grade_annual=2, ) cls.catalog3 = StudentCatalogPerYearFactory( student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student c', school_unit=cls.school_unit), study_class=cls.study_class, avg_sem1=3, avg_sem2=3, avg_final=3, second_examinations_count=3, unfounded_abs_count_sem1=3, unfounded_abs_count_sem2=3, unfounded_abs_count_annual=3, behavior_grade_sem1=3, behavior_grade_sem2=3, behavior_grade_annual=3, ) cls.catalog4 = StudentCatalogPerYearFactory( student=UserProfileFactory(user_role=UserProfile.UserRoles.STUDENT, full_name='Student d', school_unit=cls.school_unit), study_class=cls.study_class, avg_sem1=4, avg_sem2=4, avg_final=4, second_examinations_count=4, unfounded_abs_count_sem1=4, unfounded_abs_count_sem2=4, unfounded_abs_count_annual=4, behavior_grade_sem1=4, behavior_grade_sem2=4, behavior_grade_annual=4, ) cls.url = reverse('statistics:pupils-statistics')
def test_grade_create_second_examinations_count(self, timezone_mock): for avg in [4, 5, 6, 10]: StudentCatalogPerSubjectFactory(student=self.student, study_class=self.study_class, avg_sem1=avg, avg_sem2=avg) self.school_unit.academic_profile = SchoolUnitProfileFactory( name='Artistic') self.school_unit.save() self.study_class.class_grade = 'IX' self.study_class.class_grade_arabic = 9 self.study_class.save() ProgramSubjectThroughFactory(generic_academic_program=self.study_class. academic_program.generic_academic_program, subject=self.subject, weekly_hours_count=1) self.study_class.academic_program.core_subject = self.subject self.study_class.academic_program.save() self.catalog.avg_sem1 = 5 self.catalog.save() self.client.login(username=self.teacher.username, password='******') self.data['taken_at'] = date(2020, 4, 5) response = self.client.post(self.build_url(self.catalog.id), self.data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.catalog_per_year.refresh_from_db() self.assertEqual(self.catalog_per_year.second_examinations_count, 3) # Check labels catalog = StudentCatalogPerSubject.objects.get( student=self.student, study_class=self.study_class, avg_sem1=4, avg_sem2=4) catalog.avg_sem1 = 5 catalog.save() response = self.client.post(self.build_url(self.catalog.id), self.data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.catalog_per_year.refresh_from_db() self.assertEqual(self.catalog_per_year.second_examinations_count, 2) self.assertCountEqual( self.student.labels.all(), Label.objects.filter(text=FAILING_2_SUBJECTS_LABEL)) catalog.avg_sem2 = 5 catalog.save() response = self.client.post(self.build_url(self.catalog.id), self.data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.catalog_per_year.refresh_from_db() self.assertEqual(self.catalog_per_year.second_examinations_count, 1) self.assertCountEqual( self.student.labels.all(), Label.objects.filter(text=FAILING_1_SUBJECT_LABEL)) self.catalog.avg_sem1 = 6 self.catalog.save() response = self.client.post(self.build_url(self.catalog.id), self.data) self.assertEqual(response.status_code, status.HTTP_201_CREATED) self.catalog_per_year.refresh_from_db() self.assertEqual(self.catalog_per_year.second_examinations_count, 0) self.assertEqual(self.student.labels.count(), 0)