def test_resource_handling_2(self): data_dict = copy.deepcopy(self.test_data3) utils.resource_to_dataset(data_dict) assert 'direct_download_URL' in data_dict assert 'resources' in data_dict data_dict['availability'] = 'direct_download' utils.dataset_to_resource(data_dict) assert 'resources' in data_dict utils.resource_to_dataset(data_dict) assert 'resources' in data_dict assert data_dict.get('algorithm') == self.test_data3['resources'][0]['algorithm'] assert data_dict.get('checksum') == self.test_data3['resources'][0]['hash'] assert data_dict.get('mimetype') == self.test_data3['resources'][0]['mimetype'] assert data_dict.get('direct_download_URL') == self.test_data3['resources'][0]['url']
def package_show(context, data_dict): ''' Return the metadata of a dataset (package) and its resources. Called before showing the dataset in some interface (browser, API), or when adding package to Solr index (no validation / conversions then). :param id: the id or name of the dataset :type id: string :rtype: dictionary ''' if data_dict.get('type') == 'harvest': context['schema'] = Schemas.harvest_source_show_package_schema() if not data_dict.get('id') and not data_dict.get('name'): # Get package by data PIDs data_dict['id'] = utils.get_package_id_by_data_pids(data_dict) pkg_dict1 = ckan.logic.action.get.package_show(context, data_dict) pkg_dict1 = utils.resource_to_dataset(pkg_dict1) # Remove empty agents that come from padding the agent list in converters if 'agent' in pkg_dict1: agents = filter(None, pkg_dict1.get('agent', [])) pkg_dict1['agent'] = agents or [] # Normally logic function should not catch the raised errors # but here it is needed so action package_show won't catch it instead # Hiding information from API calls try: check_access('package_update', context) except NotAuthorized: pkg_dict1 = utils.hide_sensitive_fields(pkg_dict1) pkg = Package.get(pkg_dict1['id']) if 'erelated' in pkg.extras: erelated = pkg.extras['erelated'] if len(erelated): for value in erelated.split(';'): if len(Session.query(Related).filter(Related.title == value).all()) == 0: data_dict = {'title': value, 'type': _("Paper"), 'dataset_id': pkg.id} related_create(context, data_dict) # Update package.title to match package.extras.title_0 extras_title = pkg.extras.get(u'title_0') if extras_title and extras_title != pkg.title: repo.new_revision() pkg.title = pkg.extras[u'title_0'] pkg.save() rebuild(pkg.id) # Rebuild solr-index for this dataset return pkg_dict1
def package_show(context, data_dict): ''' Return the metadata of a dataset (package) and its resources. Called before showing the dataset in some interface (browser, API), or when adding package to Solr index (no validation / conversions then). :param id: the id or name of the dataset :type id: string :rtype: dictionary ''' if data_dict.get('type') == 'harvest': context['schema'] = Schemas.harvest_source_show_package_schema() context['use_cache'] = False # Disable package retrieval directly from Solr as contact.email is not there. if not data_dict.get('id') and not data_dict.get('name'): # Get package by data PIDs data_dict['id'] = utils.get_package_id_by_primary_pid(data_dict) pkg_dict1 = ckan.logic.action.get.package_show(context, data_dict) pkg_dict1 = utils.resource_to_dataset(pkg_dict1) # Remove empty agents that come from padding the agent list in converters if 'agent' in pkg_dict1: agents = filter(None, pkg_dict1.get('agent', [])) pkg_dict1['agent'] = agents or [] # Normally logic function should not catch the raised errors # but here it is needed so action package_show won't catch it instead # Hiding information from API calls try: check_access('package_update', context) except NotAuthorized: pkg_dict1 = utils.hide_sensitive_fields(pkg_dict1) pkg = Package.get(pkg_dict1['id']) if 'erelated' in pkg.extras: erelated = pkg.extras['erelated'] if len(erelated): for value in erelated.split(';'): if len(Session.query(Related).filter(Related.title == value).all()) == 0: data_dict = {'title': value, 'type': _("Paper"), 'dataset_id': pkg.id} related_create(context, data_dict) return pkg_dict1
def test_resource_to_dataset_invalid(self): data_dict = copy.deepcopy(self.test_data2) data_dict['resources'][0].pop('resource_type') utils.resource_to_dataset(data_dict) assert 'direct_download_URL' not in data_dict
def test_resource_to_dataset(self): data_dict = copy.deepcopy(self.test_data2) utils.resource_to_dataset(data_dict) assert 'direct_download_URL' in data_dict