Example #1
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 #2
0
    def test_get_content_metadata_traverse_pagination(self,
                                                      learner_portal_enabled,
                                                      mock_api_client):
        """
        Verify the get_content_metadata endpoint returns all metadata on one page if the traverse pagination query
        parameter is added.
        """
        mock_api_client.return_value.get_enterprise_customer.return_value = {
            'slug': self.enterprise_slug,
            'enable_learner_portal': learner_portal_enabled,
        }
        # Create enough metadata to force pagination (if the query parameter wasn't sent)
        metadata = ContentMetadataFactory.create_batch(api_settings.PAGE_SIZE +
                                                       1)
        self.add_metadata_to_catalog(self.enterprise_catalog, metadata)
        url = self._get_content_metadata_url(
            self.enterprise_catalog) + '?traverse_pagination=1'
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_data = response.json()
        self.assertEqual((response_data['count']), api_settings.PAGE_SIZE + 1)
        self.assertEqual(uuid.UUID(response_data['uuid']),
                         self.enterprise_catalog.uuid)
        self.assertEqual(response_data['title'], self.enterprise_catalog.title)
        self.assertEqual(uuid.UUID(response_data['enterprise_customer']),
                         self.enterprise_catalog.enterprise_uuid)

        # Check that the page contains all the metadata
        expected_metadata = [
            self._get_expected_json_metadata(item, learner_portal_enabled)
            for item in metadata
        ]
        actual_metadata = response_data['results']
        self.assertCountEqual(actual_metadata, expected_metadata)
    def setUpTestData(cls):
        super().setUpTestData()

        cls.number_of_metadata_items = 3
        cls.content_metadata = ContentMetadataFactory.create_batch(
            cls.number_of_metadata_items, content_type=COURSE)
        cls.content_keys = [
            metadata.content_key for metadata in cls.content_metadata
        ]
Example #4
0
    def test_get_content_metadata(self, learner_portal_enabled,
                                  mock_api_client):
        """
        Verify the get_content_metadata endpoint returns all the metadata associated with a particular catalog
        """
        mock_api_client.return_value.get_enterprise_customer.return_value = {
            'slug': self.enterprise_slug,
            'enable_learner_portal': learner_portal_enabled,
        }
        # The ContentMetadataFactory creates content with keys that are generated using a string builder with a
        # factory sequence (index is appended onto each content key). The results are sorted by key which creates
        # an unexpected sorting of [key0, key1, key10, key2, ...] so the test fails on
        # self.assertEqual(actual_metadata, expected_metadata[:-1]). By resetting the factory sequence to start at
        # 10 we avoid that sorting issue.
        ContentMetadataFactory.reset_sequence(10)
        # Create enough metadata to force pagination
        metadata = ContentMetadataFactory.create_batch(api_settings.PAGE_SIZE +
                                                       1)
        self.add_metadata_to_catalog(self.enterprise_catalog, metadata)
        url = self._get_content_metadata_url(self.enterprise_catalog)
        response = self.client.get(url)
        self.assertEqual(response.status_code, status.HTTP_200_OK)
        response_data = response.json()
        self.assertEqual((response_data['count']), api_settings.PAGE_SIZE + 1)
        self.assertEqual(uuid.UUID(response_data['uuid']),
                         self.enterprise_catalog.uuid)
        self.assertEqual(response_data['title'], self.enterprise_catalog.title)
        self.assertEqual(uuid.UUID(response_data['enterprise_customer']),
                         self.enterprise_catalog.enterprise_uuid)

        # Check that the first page contains all but the last metadata
        expected_metadata = sorted([
            self._get_expected_json_metadata(item, learner_portal_enabled)
            for item in metadata
        ],
                                   key=itemgetter('key'))
        actual_metadata = sorted(response_data['results'],
                                 key=itemgetter('key'))
        self.assertEqual(actual_metadata, expected_metadata[:-1])

        # Check that the second page contains the last metadata
        second_page_response = self.client.get(response_data['next'])
        self.assertEqual(second_page_response.status_code, status.HTTP_200_OK)
        self.assertEqual(second_page_response.json()['results'],
                         [expected_metadata[-1]])
 def setUpTestData(cls):
     super().setUpTestData()
     cls.content_metadata = ContentMetadataFactory.create_batch(
         3, content_type=COURSE)
 def setUpTestData(cls):
     super().setUpTestData()
     ContentMetadataFactory.create_batch(3)