Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AV-2418: Add validate packages feature to syke harvester #2586

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from ckan.lib.munge import munge_tag
from ckanext.harvest.model import HarvestObject
from ckanext.harvest.harvesters.ckanharvester import CKANHarvester
import ckan.lib.plugins as lib_plugins

Check warning on line 12 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L12

Added line #L12 was not covered by tests

import logging
log = logging.getLogger(__name__)
Expand Down Expand Up @@ -436,6 +437,42 @@

package_dict = self.modify_package_dict(package_dict, harvest_object)

# validate packages if needed
validate_packages = self.config.get('validate_packages', {})
if validate_packages:
if 'type' not in package_dict:
package_plugin = lib_plugins.lookup_package_plugin()
try:

Check warning on line 445 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L441-L445

Added lines #L441 - L445 were not covered by tests
# use first type as default if user didn't provide type
package_type = package_plugin.package_types()[0]
except (AttributeError, IndexError):
package_type = 'dataset'

Check warning on line 449 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L447-L449

Added lines #L447 - L449 were not covered by tests
# in case a 'dataset' plugin was registered w/o fallback
package_plugin = lib_plugins.lookup_package_plugin(package_type)
package_dict['type'] = package_type

Check warning on line 452 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L451-L452

Added lines #L451 - L452 were not covered by tests
else:
package_plugin = lib_plugins.lookup_package_plugin(package_dict['type'])

Check warning on line 454 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L454

Added line #L454 was not covered by tests

errors = {}

Check warning on line 456 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L456

Added line #L456 was not covered by tests
# if package has been previously imported
try:
existing_package_dict = self._find_existing_package(package_dict)

Check warning on line 459 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L458-L459

Added lines #L458 - L459 were not covered by tests

if 'metadata_modified' not in package_dict or \

Check warning on line 461 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L461

Added line #L461 was not covered by tests
package_dict['metadata_modified'] > existing_package_dict.get('metadata_modified'):
schema = package_plugin.update_package_schema()
data, errors = lib_plugins.plugin_validate(

Check warning on line 464 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L463-L464

Added lines #L463 - L464 were not covered by tests
package_plugin, base_context, package_dict, schema, 'package_update')

except NotFound:

Check warning on line 467 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L467

Added line #L467 was not covered by tests

schema = package_plugin.create_package_schema()
data, errors = lib_plugins.plugin_validate(

Check warning on line 470 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L469-L470

Added lines #L469 - L470 were not covered by tests
package_plugin, base_context, package_dict, schema, 'package_create')

if errors:
raise ValidationError(errors)

Check warning on line 474 in ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py

View check run for this annotation

Codecov / codecov/patch

ckan/ckanext/ckanext-ytp_main/ckanext/ytp/harvesters/syke_harvester.py#L473-L474

Added lines #L473 - L474 were not covered by tests

result = self._create_or_update_package(
package_dict, harvest_object, package_dict_form='package_show')

Expand Down
Loading