def get_content_metadata(self, enterprise_customer, enterprise_catalogs=None): """ Return all content metadata contained in the catalogs associated with the EnterpriseCustomer. Arguments: enterprise_customer (EnterpriseCustomer): The EnterpriseCustomer to return content metadata for. enterprise_catalogs (EnterpriseCustomerCatalog): Optional list of EnterpriseCustomerCatalog objects. Returns: list: List of dicts containing content metadata. """ content_metadata = OrderedDict() enterprise_customer_catalogs = enterprise_catalogs or enterprise_customer.enterprise_customer_catalogs.all( ) for enterprise_customer_catalog in enterprise_customer_catalogs: response = self._load_data( self.ENTERPRISE_CUSTOMER_CATALOGS_ENDPOINT, resource_id=str(enterprise_customer_catalog.uuid), traverse_pagination=True, querystring={'page_size': 1000}, ) for item in response['results']: content_id = utils.get_content_metadata_item_id(item) content_metadata[content_id] = item return list(content_metadata.values())
def get_content_metadata(self, enterprise_customer, enterprise_catalogs=None): """ Return all content metadata contained in the catalogs associated with the EnterpriseCustomer. Arguments: enterprise_customer (EnterpriseCustomer): The EnterpriseCustomer to return content metadata for. enterprise_catalogs (EnterpriseCustomerCatalog): Optional list of EnterpriseCustomerCatalog objects. Returns: list: List of dicts containing content metadata. """ content_metadata = OrderedDict() enterprise_customer_catalogs = enterprise_catalogs or enterprise_customer.enterprise_customer_catalogs.all() for enterprise_customer_catalog in enterprise_customer_catalogs: catalog_uuid = enterprise_customer_catalog.uuid endpoint = getattr(self.client, self.GET_CONTENT_METADATA_ENDPOINT.format(catalog_uuid)) try: response = endpoint.get() for item in utils.traverse_pagination(response, endpoint): content_id = utils.get_content_metadata_item_id(item) content_metadata[content_id] = item except (SlumberBaseException, ConnectionError, Timeout) as exc: LOGGER.exception( 'Failed to get content metadata for Catalog [%s] in enterprise-catalog due to: [%s]', catalog_uuid, str(exc) ) raise return list(content_metadata.values())
def _assert_enterprise_courses_api_response(self, content_ids, content_metadata, expected_count): """ DRY method to verify the enterprise courses api response. """ assert len(content_ids) == len(content_metadata) assert expected_count == len(content_metadata) for item in content_metadata: assert get_content_metadata_item_id(item) in content_ids
def get_content_metadata(self, enterprise_customer): """ Return all content metadata contained in the catalogs associated with the EnterpriseCustomer. Arguments: enterprise_customer (EnterpriseCustomer): The EnterpriseCustomer to return content metadata for. Returns: list: List of dicts containing content metadata. """ content_metadata = OrderedDict() # TODO: This if block can be removed when we get rid of discovery service-based catalogs. if enterprise_customer.catalog: response = self._load_data( self.ENTERPRISE_CUSTOMER_ENDPOINT, detail_resource='courses', resource_id=str(enterprise_customer.uuid), traverse_pagination=True, ) for course in response['results']: for course_run in course['course_runs']: course_run[ 'content_type'] = 'courserun' # Make this look like a search endpoint result. content_metadata[course_run['key']] = course_run for enterprise_customer_catalog in enterprise_customer.enterprise_customer_catalogs.all( ): response = self._load_data( self.ENTERPRISE_CUSTOMER_CATALOGS_ENDPOINT, resource_id=str(enterprise_customer_catalog.uuid), traverse_pagination=True, querystring={'page_size': 1000}, ) for item in response['results']: content_id = utils.get_content_metadata_item_id(item) content_metadata[content_id] = item return content_metadata.values()
def __init__(self, content_metadata_item, channel_content_metadata_item): self.content_id = get_content_metadata_item_id(content_metadata_item) self.metadata = content_metadata_item self.channel_metadata = channel_content_metadata_item