Example #1
0
    def test_contains_catalog_list_parent_key(self):
        """
        Verify the contains_content_items endpoint returns a list of catalogs the course is in
        """
        content_metadata = ContentMetadataFactory()
        self.add_metadata_to_catalog(self.enterprise_catalog,
                                     [content_metadata])

        # Create a two catalogs that have the content we're looking for
        parent_content_key = 'fake-parent-key+105x'
        content_key = 'fake-key+101x'
        second_catalog = EnterpriseCatalogFactory(
            enterprise_uuid=self.enterprise_uuid)
        relevant_content = ContentMetadataFactory(
            content_key=content_key, parent_content_key=parent_content_key)
        self.add_metadata_to_catalog(second_catalog, [relevant_content])
        content_key_2 = 'fake-key+102x'
        third_catalog = EnterpriseCatalogFactory(
            enterprise_uuid=self.enterprise_uuid)
        relevant_content = ContentMetadataFactory(
            content_key=content_key_2, parent_content_key=parent_content_key)
        self.add_metadata_to_catalog(third_catalog, [relevant_content])

        url = self._get_contains_content_base_url(
        ) + '?course_run_ids=' + parent_content_key + '&get_catalog_list=True'
        response = self.client.get(url).json()
        assert response['contains_content_items'] is True
        catalog_list = response['catalog_list']
        assert set(catalog_list) == {
            str(second_catalog.uuid),
            str(third_catalog.uuid)
        }
Example #2
0
    def setUpTestData(cls):
        super().setUpTestData()
        cls.catalog_query_a = CatalogQueryFactory()
        cls.catalog_query_b = CatalogQueryFactory()
        cls.enterprise_catalog_a = EnterpriseCatalogFactory(
            catalog_query=cls.catalog_query_a)
        cls.enterprise_catalog_b = EnterpriseCatalogFactory(
            catalog_query=cls.catalog_query_b)

        ContentMetadataFactory.create_batch(3)
Example #3
0
    def test_multiple_catalogs_for_catalog_admins(self,
                                                  is_role_assigned_via_jwt):
        """
        Verify the viewset returns multiple catalogs for catalog admins of two different enterprises.
        """
        second_enterprise_catalog = EnterpriseCatalogFactory(
            enterprise_uuid=uuid.uuid4())

        if is_role_assigned_via_jwt:
            self.assign_catalog_admin_jwt_role(
                self.enterprise_uuid,
                second_enterprise_catalog.enterprise_uuid,
            )
        else:
            self.assign_catalog_admin_feature_role(enterprise_uuids=[
                self.enterprise_uuid,
                second_enterprise_catalog.enterprise_uuid,
            ])

        url = reverse('api:v1:enterprise-catalog-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 2)
        results = response.data['results']
        self.assertEqual(uuid.UUID(results[0]['uuid']),
                         self.enterprise_catalog.uuid)
        self.assertEqual(uuid.UUID(results[1]['uuid']),
                         second_enterprise_catalog.uuid)
Example #4
0
 def setUp(self):
     super().setUp()
     # Set up catalog.has_learner_access permissions
     self.set_up_catalog_learner()
     self.enterprise_catalog = EnterpriseCatalogFactory(
         enterprise_uuid=self.enterprise_uuid)
     # Delete any existing ContentMetadata records.
     ContentMetadata.objects.all().delete()
Example #5
0
 def setUp(self):
     super().setUp()
     self.set_up_staff()
     self.catalog_query = CatalogQueryFactory()
     self.enterprise_catalog = EnterpriseCatalogFactory(
         enterprise_uuid=self.enterprise_uuid,
         catalog_query=self.catalog_query,
     )
Example #6
0
 def test_get_content_metadata_unauthorized_incorrect_jwt_context(self):
     """
     Verify the get_content_metadata endpoint rejects catalog learners
     with an incorrect JWT context (i.e., enterprise uuid)
     """
     enterprise_catalog = EnterpriseCatalogFactory()
     self.remove_role_assignments()
     url = self._get_content_metadata_url(enterprise_catalog)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Example #7
0
 def test_contains_content_items_unauthorized_incorrect_jwt_context(self):
     """
     Verify the contains_content_items endpoint rejects users with an invalid JWT context (i.e., enterprise uuid)
     """
     enterprise_catalog = EnterpriseCatalogFactory()
     self.remove_role_assignments()
     url = self._get_contains_content_base_url(
         enterprise_catalog) + '?course_run_ids=fakeX'
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Example #8
0
 def test_put_unauthorized_incorrect_jwt_context(self):
     """
     Verify the viewset rejects put for users that are catalog admins with an invalid
     context (i.e., enterprise uuid)
     """
     enterprise_catalog = EnterpriseCatalogFactory()
     self.remove_role_assignments()
     url = reverse('api:v1:enterprise-catalog-detail',
                   kwargs={'uuid': enterprise_catalog.uuid})
     response = self.client.put(url, self.new_catalog_data)
     self.assertEqual(response.status_code, status.HTTP_403_FORBIDDEN)
Example #9
0
 def test_contains_content_items_no_catalog_query(self):
     """
     Verify the contains_content_items endpoint returns False if there is no associated catalog query
     """
     no_catalog_query_catalog = EnterpriseCatalogFactory(
         catalog_query=None,
         enterprise_uuid=self.enterprise_uuid,
     )
     url = self._get_contains_content_base_url(
         no_catalog_query_catalog) + '?program_uuids=test-uuid'
     self.assert_correct_contains_response(url, False)
Example #10
0
    def setUpTestData(cls):
        super().setUpTestData()
        cls.ALGOLIA_FIELDS = [
            'key', 'objectID', 'enterprise_customer_uuids',
            'enterprise_catalog_uuids'
        ]

        # Set up a catalog, query, and metadata for a course
        cls.enterprise_catalog_courses = EnterpriseCatalogFactory()
        courses_catalog_query = cls.enterprise_catalog_courses.catalog_query
        cls.course_metadata = ContentMetadataFactory(content_type=COURSE,
                                                     content_key='fakeX')
        cls.course_metadata.catalog_queries.set([courses_catalog_query])

        # Set up new catalog, query, and metadata for a course run
        cls.enterprise_catalog_course_runs = EnterpriseCatalogFactory()
        course_runs_catalog_query = cls.enterprise_catalog_course_runs.catalog_query
        course_run_metadata = ContentMetadataFactory(
            content_type=COURSE_RUN, parent_content_key='fakeX')
        course_run_metadata.catalog_queries.set([course_runs_catalog_query])
Example #11
0
    def setUp(self):
        super().setUp()
        # clean up any stale test objects
        CatalogQuery.objects.all().delete()
        ContentMetadata.objects.all().delete()
        EnterpriseCatalog.objects.all().delete()

        self.enterprise_catalog = EnterpriseCatalogFactory(
            enterprise_uuid=self.enterprise_uuid)

        # Set up catalog.has_learner_access permissions
        self.set_up_catalog_learner()
Example #12
0
 def test_get_content_metadata_no_catalog_query(self):
     """
     Verify the get_content_metadata endpoint returns no results if the catalog has no catalog query
     """
     no_catalog_query_catalog = EnterpriseCatalogFactory(
         catalog_query=None,
         enterprise_uuid=self.enterprise_uuid,
     )
     url = self._get_content_metadata_url(no_catalog_query_catalog)
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.json()['results'], [])
Example #13
0
    def setUpTestData(cls):
        super().setUpTestData()
        cls.ALGOLIA_FIELDS = [
            'key', 'objectID', 'enterprise_customer_uuids',
            'enterprise_catalog_uuids', 'enterprise_catalog_query_uuids'
        ]

        # Set up a catalog, query, and metadata for a course
        cls.enterprise_catalog_courses = EnterpriseCatalogFactory()
        courses_catalog_query = cls.enterprise_catalog_courses.catalog_query
        cls.course_metadata_published = ContentMetadataFactory(
            content_type=COURSE, content_key='fakeX')
        cls.course_metadata_published.catalog_queries.set(
            [courses_catalog_query])
        cls.course_metadata_unpublished = ContentMetadataFactory(
            content_type=COURSE, content_key='testX')
        cls.course_metadata_unpublished.json_metadata.get(
            'course_runs')[0].update({
                'status': 'unpublished',
            })
        cls.course_metadata_unpublished.catalog_queries.set(
            [courses_catalog_query])
        cls.course_metadata_unpublished.save()

        # Set up new catalog, query, and metadata for a course run
        cls.enterprise_catalog_course_runs = EnterpriseCatalogFactory()
        course_runs_catalog_query = cls.enterprise_catalog_course_runs.catalog_query
        course_run_metadata_published = ContentMetadataFactory(
            content_type=COURSE_RUN, parent_content_key='fakeX')
        course_run_metadata_published.catalog_queries.set(
            [course_runs_catalog_query])
        course_run_metadata_unpublished = ContentMetadataFactory(
            content_type=COURSE_RUN, parent_content_key='testX')
        course_run_metadata_unpublished.json_metadata.update({
            'status':
            'unpublished',
        })
        course_run_metadata_unpublished.catalog_queries.set(
            [course_runs_catalog_query])
        course_run_metadata_unpublished.save()
Example #14
0
    def test_every_catalog_for_catalog_admins(self, is_role_assigned_via_jwt):
        """
        Verify the viewset returns catalogs of all enterprises for admins with wildcard permission.
        """
        if is_role_assigned_via_jwt:
            self.assign_catalog_admin_jwt_role('*')
        else:
            # This will cause a feature role assignment to be created with a null enterprise UUID,
            # which is interpretted as having access to catalogs of ANY enterprise.
            self.assign_catalog_admin_feature_role(enterprise_uuids=[None])

        catalog_b = EnterpriseCatalogFactory(enterprise_uuid=uuid.uuid4())
        catalog_c = EnterpriseCatalogFactory(enterprise_uuid=uuid.uuid4())

        url = reverse('api:v1:enterprise-catalog-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 3)
        results = response.data['results']
        self.assertEqual(uuid.UUID(results[0]['uuid']),
                         self.enterprise_catalog.uuid)
        self.assertEqual(uuid.UUID(results[1]['uuid']), catalog_b.uuid)
        self.assertEqual(uuid.UUID(results[2]['uuid']), catalog_c.uuid)
Example #15
0
 def test_list_for_superusers(self):
     """
     Verify the viewset returns a list of all enterprise catalogs for superusers
     """
     self.set_up_superuser()
     url = reverse('api:v1:enterprise-catalog-list')
     second_enterprise_catalog = EnterpriseCatalogFactory()
     response = self.client.get(url)
     self.assertEqual(response.status_code, status.HTTP_200_OK)
     self.assertEqual(response.data['count'], 2)
     results = response.data['results']
     self.assertEqual(uuid.UUID(results[0]['uuid']),
                      self.enterprise_catalog.uuid)
     self.assertEqual(uuid.UUID(results[1]['uuid']),
                      second_enterprise_catalog.uuid)
Example #16
0
 def setUp(self):
     super().setUp()
     self.set_up_staff()
     self.enterprise_catalog = EnterpriseCatalogFactory(
         enterprise_uuid=self.enterprise_uuid,
         enterprise_name=self.enterprise_name,
     )
     self.new_catalog_uuid = uuid.uuid4()
     self.new_catalog_data = {
         'uuid': self.new_catalog_uuid,
         'title': 'Test Title',
         'enterprise_customer': self.enterprise_uuid,
         'enterprise_customer_name': self.enterprise_name,
         'enabled_course_modes': '["verified"]',
         'publish_audit_enrollment_urls': True,
         'content_filter': '{"content_type":"course"}',
     }
Example #17
0
    def test_no_catalog_list_given_without_get_catalog_list_query(self):
        """
        Verify that the contains_content_items endpoint does not return a list of catalogs without a querystring
        """
        content_metadata = ContentMetadataFactory()
        self.add_metadata_to_catalog(self.enterprise_catalog,
                                     [content_metadata])

        # Create a second catalog that has the content we're looking for
        content_key = 'fake-key+101x'
        second_catalog = EnterpriseCatalogFactory(
            enterprise_uuid=self.enterprise_uuid)
        relevant_content = ContentMetadataFactory(content_key=content_key)
        self.add_metadata_to_catalog(second_catalog, [relevant_content])
        url = self._get_contains_content_base_url(
        ) + '?course_run_ids=' + content_key
        response = self.client.get(url)
        assert 'catalog_list' not in response.json().keys()
Example #18
0
    def test_contains_content_items_in_catalogs(self):
        """
        Verify the contains_content_items endpoint returns True if the content is in any associated catalog
        """
        content_metadata = ContentMetadataFactory()
        self.add_metadata_to_catalog(self.enterprise_catalog,
                                     [content_metadata])

        # Create a second catalog that has the content we're looking for
        content_key = 'fake-key+101x'
        second_catalog = EnterpriseCatalogFactory(
            enterprise_uuid=self.enterprise_uuid)
        relevant_content = ContentMetadataFactory(content_key=content_key)
        self.add_metadata_to_catalog(second_catalog, [relevant_content])

        url = self._get_contains_content_base_url(
        ) + '?course_run_ids=' + content_key
        self.assert_correct_contains_response(url, True)
Example #19
0
    def test_one_catalog_for_catalog_admins(self, is_role_assigned_via_jwt):
        """
        Verify the viewset returns a single catalog (when multiple exist) for catalog admins of a certain enterprise.
        """
        if is_role_assigned_via_jwt:
            self.assign_catalog_admin_jwt_role()
        else:
            self.assign_catalog_admin_feature_role()

        # create an additional catalog from a different enterprise,
        # and make sure we don't see it in the response results.
        EnterpriseCatalogFactory(enterprise_uuid=uuid.uuid4())

        url = reverse('api:v1:enterprise-catalog-list')
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        self.assertEqual(response.data['count'], 1)
        results = response.data['results']
        self.assertEqual(uuid.UUID(results[0]['uuid']),
                         self.enterprise_catalog.uuid)
Example #20
0
    def test_contains_catalog_list(self):
        """
        Verify the contains_content_items endpoint returns a list of catalogs the course is in if the correct
        parameter is passed
        """
        content_metadata = ContentMetadataFactory()
        self.add_metadata_to_catalog(self.enterprise_catalog,
                                     [content_metadata])

        # Create a two catalogs that have the content we're looking for
        content_key = 'fake-key+101x'
        second_catalog = EnterpriseCatalogFactory(
            enterprise_uuid=self.enterprise_uuid)
        relevant_content = ContentMetadataFactory(content_key=content_key)
        self.add_metadata_to_catalog(second_catalog, [relevant_content])
        url = self._get_contains_content_base_url(
        ) + '?course_run_ids=' + content_key + '&get_catalog_list=True'
        self.assert_correct_contains_response(url, True)

        response = self.client.get(url)
        catalog_list = response.json()['catalog_list']
        assert set(catalog_list) == {str(second_catalog.uuid)}
Example #21
0
 def setUpTestData(cls):
     super().setUpTestData()
     cls.enterprise_catalog = EnterpriseCatalogFactory()
     cls.catalog_query = cls.enterprise_catalog.catalog_query
Example #22
0
 def setUp(self):
     super().setUp()
     self.set_up_staff_user()
     self.enterprise_catalog = EnterpriseCatalogFactory(
         enterprise_uuid=self.enterprise_uuid)
Example #23
0
 def setUp(self):
     super().setUp()
     # Set up catalog.has_learner_access permissions
     self.set_up_catalog_learner()
     self.enterprise_catalog = EnterpriseCatalogFactory(
         enterprise_uuid=self.enterprise_uuid)