コード例 #1
0
    def test_retrieve_curriculum_with_child_programs(
            self, django_assert_num_queries):
        parent_program = self.create_program(courses=[])
        curriculum = self.create_curriculum(parent_program)

        child_program1 = self.create_program()
        child_program2 = self.create_program()
        CurriculumProgramMembershipFactory(program=child_program1,
                                           curriculum=curriculum)
        CurriculumProgramMembershipFactory(program=child_program2,
                                           curriculum=curriculum)

        with django_assert_num_queries(FuzzyInt(63, 2)):
            response = self.assert_retrieve_success(parent_program)
        assert response.data == self.serialize_program(parent_program)
コード例 #2
0
    def setUp(self):
        super().setUp()
        self.pk_generator = itertools.count(1)

        stored_site, created = Site.objects.get_or_create(  # pylint: disable=unused-variable
            domain='example.com')
        self.default_partner = Partner.objects.create(site=stored_site,
                                                      name='edX',
                                                      short_code='edx')

        SeatType.objects.all().delete()
        ProgramType.objects.all().delete()

        self.partner = PartnerFactory(name='Test')
        self.organization = OrganizationFactory(partner=self.partner)
        self.seat_type_verified = SeatTypeFactory(name='Verified',
                                                  slug='verified')
        self.program_type_masters = ProgramTypeFactory(
            name='Masters',
            name_t='Masters',
            slug='masters',
            applicable_seat_types=[self.seat_type_verified])
        self.program_type_masters_translation = self.program_type_masters.translations.all(
        )[0]

        self.program_type_mm = ProgramTypeFactory(
            name='MicroMasters',
            name_t='MicroMasters',
            slug='micromasters',
            applicable_seat_types=[self.seat_type_verified])
        self.program_type_mm_translation = self.program_type_mm.translations.all(
        )[0]

        self.course = CourseFactory(
            partner=self.partner, authoring_organizations=[self.organization])
        self.course_run = CourseRunFactory(course=self.course)
        self.program = ProgramFactory(
            type=self.program_type_masters,
            partner=self.partner,
            authoring_organizations=[self.organization])
        self.course_mm = CourseFactory(
            partner=self.partner, authoring_organizations=[self.organization])
        self.course_run_mm = CourseRunFactory(course=self.course)
        self.program_mm = ProgramFactory(
            type=self.program_type_mm,
            partner=self.partner,
            authoring_organizations=[self.organization],
            courses=[self.course_mm])
        self.curriculum = CurriculumFactory(program=self.program)
        self.curriculum_course_membership = CurriculumCourseMembershipFactory(
            course=self.course, curriculum=self.curriculum)
        self.curriculum_program_membership = CurriculumProgramMembershipFactory(
            program=self.program_mm, curriculum=self.curriculum)

        self.program_2 = ProgramFactory(
            type=self.program_type_masters,
            partner=self.partner,
            authoring_organizations=[self.organization])

        self._mock_oauth_request()
コード例 #3
0
    def test_retrieve_curriculum_with_child_programs(self, django_assert_num_queries):
        parent_program = self.create_program(courses=[])
        curriculum = self.create_curriculum(parent_program)

        child_program1 = self.create_program()
        child_program2 = self.create_program()
        CurriculumProgramMembershipFactory(
            program=child_program1,
            curriculum=curriculum
        )
        CurriculumProgramMembershipFactory(
            program=child_program2,
            curriculum=curriculum
        )

        # Notes on query count:
        # 46 queries to get program with single curriculum (test_retrieve_basic_curriculum)
        # +6 for first child program
        # +1 for additional child program
        # +8 for 1 or more first child program courses
        # +3 for 1 or more additional child program courses
        with django_assert_num_queries(FuzzyInt(64, 2)):
            response = self.assert_retrieve_success(parent_program)
        assert response.data == self.serialize_program(parent_program)