Esempio n. 1
0
    def test_academic_program_list_filter_by_category(self):
        self.client.login(username=self.principal.username, password='******')
        highschool_category = SchoolUnitCategoryFactory()
        self.school_unit.categories.add(highschool_category)

        AcademicProgramFactory(
            academic_year=self.academic_year,
            name='program',
            school_unit=self.school_unit,
            generic_academic_program=GenericAcademicProgramFactory(
                category=highschool_category))
        AcademicProgramFactory(
            academic_year=self.academic_year,
            name='other',
            school_unit=self.school_unit,
            generic_academic_program=GenericAcademicProgramFactory(
                category=highschool_category))

        response = self.client.get(self.build_url(self.academic_year),
                                   {'class_grade': 'IX'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 2)

        response = self.client.get(self.build_url(self.academic_year),
                                   {'class_grade': 'IV'})
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 0)
 def setUpTestData(cls):
     cls.principal = UserProfileFactory(
         user_role=UserProfile.UserRoles.PRINCIPAL)
     cls.school_unit = RegisteredSchoolUnitFactory(
         school_principal=cls.principal)
     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.academic_year = 2020
     cls.academic_year_calendar = AcademicYearCalendarFactory(
         academic_year=cls.academic_year)
     cls.academic_program = AcademicProgramFactory(
         school_unit=cls.school_unit,
         generic_academic_program=cls.generic_academic_program,
         academic_year=cls.academic_year)
     cls.subject = SubjectFactory(name='Subject')
     cls.subject_through = ProgramSubjectThroughFactory(
         academic_program=cls.academic_program,
         subject=cls.subject,
         class_grade='IX',
         class_grade_arabic=9)
 def setUpTestData(cls):
     cls.principal = UserProfileFactory(
         user_role=UserProfile.UserRoles.PRINCIPAL)
     cls.school_unit = RegisteredSchoolUnitFactory(
         school_principal=cls.principal)
     cls.program = GenericAcademicProgramFactory(
         optional_subjects_weekly_hours={
             "IX": 10,
             "X": 1
         })
Esempio n. 4
0
    def test_academic_program_subject_list_success(self):
        self.client.login(username=self.principal.username, password='******')

        # Create a subject through with another class grade
        subject = SubjectFactory(name='Wrong class grade')
        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject,
            class_grade='X',
            class_grade_arabic=10)

        response = self.get_response()
        self.assertEqual(len(response.data), 2)
        self.assertCountEqual(
            [subject['subject_id'] for subject in response.data],
            [self.optional_subject.id, self.mandatory_subject.id])
        self.assertCountEqual(
            [subject['is_mandatory'] for subject in response.data],
            [False, True])

        # Create a mandatory subject from another generic academic program
        generic_academic_program = GenericAcademicProgramFactory()
        subject = SubjectFactory(name='Other generic academic program')
        ProgramSubjectThroughFactory(
            generic_academic_program=generic_academic_program,
            subject=subject,
            class_grade='IX',
            class_grade_arabic=9)
        response = self.get_response()
        self.assertEqual(len(response.data), 2)

        # Create another optional subject
        subject = SubjectFactory(name='Other optional')
        ProgramSubjectThroughFactory(academic_program=self.academic_program,
                                     subject=subject,
                                     class_grade='IX',
                                     class_grade_arabic=9,
                                     is_mandatory=False)
        response = self.get_response()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 3)

        # Create another mandatory subject
        subject = SubjectFactory(name='Other mandatory')
        ProgramSubjectThroughFactory(
            generic_academic_program=self.generic_academic_program,
            subject=subject,
            class_grade='IX',
            class_grade_arabic=9)
        response = self.get_response()
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(len(response.data), 4)
    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 setUpTestData(cls):
     cls.principal = UserProfileFactory(
         user_role=UserProfile.UserRoles.PRINCIPAL)
     cls.school_unit = RegisteredSchoolUnitFactory(
         school_principal=cls.principal)
     cls.optional_subjects_weekly_hours = {
         'IX': 10,
         'X': 8,
         'XI': 6,
         'XII': 6
     }
     cls.generic_academic_program = GenericAcademicProgramFactory(
         optional_subjects_weekly_hours=cls.optional_subjects_weekly_hours)
     cls.academic_program = AcademicProgramFactory(
         generic_academic_program=cls.generic_academic_program,
         school_unit=cls.school_unit)
    def test_academic_program_create_secondary_school_success(self, mocked_method):
        self.client.login(username=self.principal.username, password='******')
        category = SchoolUnitCategoryFactory(category_level=SchoolUnitCategory.CategoryLevels.SECONDARY_SCHOOL)
        generic_academic_program = GenericAcademicProgramFactory(
            category=category,
            optional_subjects_weekly_hours={
                "VI": 1,
                "VII": 1
            }
        )
        self.school_unit.categories.add(category)
        self.school_unit.academic_profile = None
        self.school_unit.save()

        self.data = {
            "generic_academic_program": generic_academic_program.id,
            "optional_subjects": [
                {
                    "class_grade": "VI",
                    "subject": self.subject.name,
                    "weekly_hours_count": 1
                },
                {
                    "class_grade": "VII",
                    "subject": self.subject.name,
                    "weekly_hours_count": 1
                }
            ]
        }

        response = self.client.post(self.build_url(self.academic_year), self.data)
        self.assertEqual(response.status_code, status.HTTP_201_CREATED)

        academic_program = AcademicProgram.objects.get(id=response.data['id'])
        self.assertEqual(academic_program.name, generic_academic_program.name)
        self.assertEqual(academic_program.school_unit, self.school_unit)
        self.assertEqual(academic_program.academic_year, self.academic_year)
        self.assertEqual(ProgramSubjectThrough.objects.filter(academic_program=academic_program).count(), 2)

        self.assertCountEqual(response.data['subjects'].keys(), ['VI', 'VII'])
        self.assertEqual(len(response.data['subjects']['VI']['mandatory_subjects']), 0)
        self.assertEqual(len(response.data['subjects']['VI']['optional_subjects']), 1)
        self.assertEqual(len(response.data['subjects']['VII']['mandatory_subjects']), 0)
        self.assertEqual(len(response.data['subjects']['VII']['optional_subjects']), 1)
Esempio n. 8
0
 def setUpTestData(cls):
     cls.principal = UserProfileFactory(
         user_role=UserProfile.UserRoles.PRINCIPAL)
     cls.school_unit = RegisteredSchoolUnitFactory(
         school_principal=cls.principal)
     cls.generic_academic_program = GenericAcademicProgramFactory()
     cls.academic_program = AcademicProgramFactory(
         school_unit=cls.school_unit,
         generic_academic_program=cls.generic_academic_program)
     cls.mandatory_subject = SubjectFactory(name='Mandatory')
     cls.optional_subject = SubjectFactory(name='Optional')
     cls.mandatory_through = ProgramSubjectThroughFactory(
         generic_academic_program=cls.generic_academic_program,
         subject=cls.mandatory_subject,
         class_grade='IX',
         class_grade_arabic=9)
     cls.optional_through = ProgramSubjectThroughFactory(
         academic_program=cls.academic_program,
         subject=cls.optional_subject,
         class_grade='IX',
         class_grade_arabic=9,
         is_mandatory=False)