Example #1
0
 def setUpClass(cls):
     """ Sets up program data. """
     super(TestGetProgramsByType, cls).setUpClass()
     cls.site = SiteFactory()
     cls.other_site = SiteFactory()
     cls.masters_program_1 = ProgramFactory.create(
         type='Masters',
         type_attrs=ProgramTypeAttrsFactory.create(slug="masters")
     )
     cls.masters_program_2 = ProgramFactory.create(
         type='Masters',
         type_attrs=ProgramTypeAttrsFactory.create(slug="masters")
     )
     cls.masters_program_other_site = ProgramFactory.create(
         type='Masters',
         type_attrs=ProgramTypeAttrsFactory.create(slug="masters")
     )
     cls.bachelors_program = ProgramFactory.create(
         type='Bachelors',
         type_attrs=ProgramTypeAttrsFactory.create(slug="bachelors")
     )
     cls.no_type_program = ProgramFactory.create(
         type=None,
         type_attrs=None
     )
Example #2
0
    def setUp(self):
        super(TestCachePrograms, self).setUp()

        httpretty.httpretty.reset()

        self.catalog_integration = self.create_catalog_integration()
        self.site_domain = 'testsite.com'
        self.site = self.set_up_site(
            self.site_domain,
            {
                'COURSE_CATALOG_API_URL': self.catalog_integration.get_internal_api_url().rstrip('/')
            }
        )

        self.list_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/programs/'
        self.detail_tpl = self.list_url.rstrip('/') + '/{uuid}/'
        self.pathway_url = self.catalog_integration.get_internal_api_url().rstrip('/') + '/pathways/'

        self.programs = ProgramFactory.create_batch(3)
        self.pathways = PathwayFactory.create_batch(3)
        self.child_program = ProgramFactory.create()

        self.programs[0]['curricula'][0]['programs'].append(self.child_program)
        self.programs.append(self.child_program)

        self.programs[0]['authoring_organizations'] = OrganizationFactory.create_batch(2)

        for pathway in self.pathways:
            self.programs += pathway['programs']

        self.uuids = [program['uuid'] for program in self.programs]

        # add some of the previously created programs to some pathways
        self.pathways[0]['programs'].extend([self.programs[0], self.programs[1]])
        self.pathways[1]['programs'].append(self.programs[0])
Example #3
0
    def _create_cached_program(self):
        """ helper method to create a cached program """
        program = ProgramFactory.create()

        for course_key in self.course_keys:
            program['courses'].append(CourseFactory(id=course_key))

        program['type'] = 'MicroBachelors'
        program['type_attrs']['coaching_supported'] = True

        for course in program['courses']:
            cache.set(
                CATALOG_COURSE_PROGRAMS_CACHE_KEY_TPL.format(course_uuid=course['uuid']),
                [program['uuid']],
                None
            )

            course_run = course['course_runs'][0]['key']
            cache.set(
                COURSE_PROGRAMS_CACHE_KEY_TPL.format(course_run_id=course_run),
                [program['uuid']],
                None
            )
        cache.set(
            PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']),
            program,
            None
        )

        return program
Example #4
0
 def _create_catalog_program(self, catalog_org):
     """ helper method to create a cached catalog program """
     program = ProgramFactory.create(
         authoring_organizations=[catalog_org]
     )
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']), program, None)
     return program
 def _create_catalog_program(self, catalog_org):
     """ helper method to create a cached catalog program """
     program = ProgramFactory.create(
         authoring_organizations=[catalog_org]
     )
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=program['uuid']), program, None)
     return program
Example #6
0
 def setUp(self):
     super(GetUsersByExternalKeysTests, self).setUp()
     catalog_org = CatalogOrganizationFactory.create(key=self.organization_key)
     program = ProgramFactory.create(
         uuid=self.program_uuid,
         authoring_organizations=[catalog_org]
     )
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid), program, None)
 def setup_catalog_cache(self, program_uuid, organization_key):
     """
     helper function to initialize a cached program with an single authoring_organization
     """
     catalog_org = CatalogOrganizationFactory.create(key=organization_key)
     program = ProgramFactory.create(uuid=program_uuid,
                                     authoring_organizations=[catalog_org])
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=program_uuid), program,
               None)
Example #8
0
 def setup_catalog_cache(self, program_uuid, organization_key):
     """
     helper function to initialize a cached program with an single authoring_organization
     """
     catalog_org = CatalogOrganizationFactory.create(key=organization_key)
     program = ProgramFactory.create(
         uuid=program_uuid,
         authoring_organizations=[catalog_org]
     )
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=program_uuid), program, None)
Example #9
0
 def test_catalog_program_missing_org(self):
     """
     Test OrganizationDoesNotExistException is thrown if the cached program does not
     have an authoring organization.
     """
     program = ProgramFactory.create(uuid=self.program_uuid,
                                     authoring_organizations=[])
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid),
               program, None)
     with self.assertRaises(OrganizationDoesNotExistException):
         get_users_by_external_keys(self.program_uuid, [])
Example #10
0
 def setUp(self):
     """
     Set up test data
     """
     super(WritingProgramEnrollmentTest, self).setUp()
     catalog_org = CatalogOrganizationFactory.create(
         key=self.organization_key)
     program = ProgramFactory.create(uuid=self.program_uuid_x,
                                     authoring_organizations=[catalog_org])
     organization = OrganizationFactory.create(
         short_name=self.organization_key)
     SAMLProviderConfigFactory.create(organization=organization)
     cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid_x),
               program, None)
Example #11
0
    def test_catalog_program_missing_org(self):
        """
        Test OrganizationDoesNotExistException is thrown if the cached program does not
        have an authoring organization.
        """
        program = ProgramFactory.create(
            uuid=self.program_uuid,
            authoring_organizations=[]
        )
        cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid), program, None)

        organization = OrganizationFactory.create(short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        with pytest.raises(OrganizationDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Example #12
0
    def test_catalog_program_missing_org(self):
        """
        Test OrganizationDoesNotExistException is thrown if the cached program does not
        have an authoring organization.
        """
        program = ProgramFactory.create(
            uuid=self.program_uuid,
            authoring_organizations=[]
        )
        cache.set(PROGRAM_CACHE_KEY_TPL.format(uuid=self.program_uuid), program, None)

        organization = OrganizationFactory.create(short_name=self.organization_key)
        provider = SAMLProviderConfigFactory.create(organization=organization)
        self.create_social_auth_entry(self.user, provider, self.external_user_id)

        with pytest.raises(OrganizationDoesNotExistException):
            get_user_by_program_id(self.external_user_id, self.program_uuid)
Example #13
0
    def setUpClass(cls):
        """
        Set up test data
        """
        super().setUpClass()
        catalog_org = CatalogOrganizationFactory.create(
            key=cls.organization_key)
        cls.program = ProgramFactory.create(
            uuid=cls.program_uuid, authoring_organizations=[catalog_org])
        organization = OrganizationFactory.create(
            short_name=cls.organization_key)
        SAMLProviderConfigFactory.create(organization=organization)

        catalog_course_id_str = 'course-v1:edX+ToyX'
        course_run_id_str = f'{catalog_course_id_str}+Toy_Course'
        cls.course_id = CourseKey.from_string(course_run_id_str)
        CourseOverviewFactory(id=cls.course_id)
        course_run = CourseRunFactory(key=course_run_id_str)
        cls.course = CourseFactory(key=catalog_course_id_str,
                                   course_runs=[course_run])
        cls.student_1 = UserFactory(username='******')
        cls.student_2 = UserFactory(username='******')