Skip to content

Commit

Permalink
Merge pull request #1 from mpolidori/master
Browse files Browse the repository at this point in the history
Fixes group relationship loss on re-harvest
  • Loading branch information
zelima authored Jan 7, 2020
2 parents 8c55890 + 015422d commit 29879de
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
10 changes: 10 additions & 0 deletions ckanext/dcat/harvesters/_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def import_stage(self, harvest_object):
existing_dataset = self._get_existing_dataset(harvest_object.guid)
if existing_dataset:
copy_across_resource_ids(existing_dataset, package_dict)
copy_across_dataset_groups(existing_dataset, package_dict)

# Allow custom harvesters to modify the package dict before creating
# or updating the package
Expand Down Expand Up @@ -343,3 +344,12 @@ def copy_across_resource_ids(existing_dataset, harvested_dataset):
matching_existing_resource)
if not existing_resources_still_to_match:
break


def copy_across_dataset_groups(existing_dataset, harvested_dataset):
'''Copies the groups any existing datasets
are in to the newly harvested datasets'''
existing_groups = existing_dataset.get('groups')

if existing_groups:
harvested_dataset['groups'] = existing_groups
32 changes: 31 additions & 1 deletion ckanext/dcat/tests/test_json_harvester.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@

import ckan.tests.factories as factories

from ckanext.dcat.harvesters._json import copy_across_resource_ids, DCATJSONHarvester
from ckanext.dcat.harvesters._json import (copy_across_resource_ids,
DCATJSONHarvester,
copy_across_dataset_groups)
from test_harvester import FunctionalHarvestTest

eq_ = nose.tools.eq_
Expand Down Expand Up @@ -323,3 +325,31 @@ def test_import_invalid_tags(

assert 'Error importing dataset Invalid tags: ValidationError(None,)' in args[0]
assert '{\'tags\': [{}, u\'Tag "test\\\'s" must be alphanumeric characters or symbols: -_.\', u\'Tag "invalid & wrong" must be alphanumeric characters or symbols: -_.\']}' in args[0]


class TestCopyAcrossDatasetGroups:
def test_groups_copied(self):
harvested_dataset = {}
existing_dataset = {'groups': [{
'display_name': u'education',
u'description': u'',
u'title': u'education',
'image_display_url': u'',
u'id': u'ed944b74-6338-4cbd-83df-0927ff8ae8ab',
u'name': u'education'
}, {
'display_name': u'other',
u'description': u'',
u'title': u'other',
'image_display_url': u'',
u'id': u'95291d78-7c33-48e6-bd06-5751254e5bf7',
u'name': u'other'}]
}

copy_across_dataset_groups(
existing_dataset,
harvested_dataset,
)

eq_(harvested_dataset['groups'][0].get('name'),
existing_dataset['groups'][0].get('name'))

0 comments on commit 29879de

Please sign in to comment.