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

Support dct:license on DCAT harvester #2589

Merged
merged 2 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Current (in progress)

- Nothing yet
- Support dct:license on DCAT harvester [#2589](https://github.com/opendatateam/udata/pull/2589)

## 2.6.1 (2021-01-26)

Expand Down
3 changes: 2 additions & 1 deletion udata/core/dataset/rdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ def dataset_from_rdf(graph, dataset=None, node=None):
licenses.add(value.identifier.toPython())

default_license = dataset.license or License.default()
dataset.license = License.guess(*licenses, default=default_license)
dataset_license = rdf_value(d, DCT.license)
dataset.license = License.guess(dataset_license, *licenses, default=default_license)

return dataset
2 changes: 2 additions & 0 deletions udata/harvest/tests/dcat/catalog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
xmlns:owl="http://www.w3.org/2002/07/owl#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:dcat="http://www.w3.org/ns/dcat#"
xmlns:dct="http://purl.org/dc/terms/"
xmlns:dcterms="http://purl.org/dc/terms/"
xmlns:vcard="http://www.w3.org/2006/vcard/ns#"
xmlns:schema="http://schema.org/"
Expand All @@ -22,6 +23,7 @@
<dcterms:description>Dataset 3 description</dcterms:description>
<dcat:keyword>Tag 1</dcat:keyword>
<dcat:distribution rdf:resource="http://data.test.org/datasets/3/resources/1"/>
<dct:license>Licence Ouverte Version 2.0</dct:license>
</dcat:Dataset>
</dcat:dataset>
<dcterms:title>Sample DCAT Catalog</dcterms:title>
Expand Down
23 changes: 18 additions & 5 deletions udata/harvest/tests/test_dcat_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from udata.models import Dataset, License
from udata.core.organization.factories import OrganizationFactory
from udata.core.dataset.factories import LicenseFactory

from .factories import HarvestSourceFactory
from .. import actions
Expand Down Expand Up @@ -44,11 +45,6 @@ def callback(request, context):
@pytest.mark.usefixtures('clean_db')
@pytest.mark.options(PLUGINS=['dcat'])
class DcatBackendTest:
@pytest.fixture(autouse=True)
def inject_licenses(self):
# Create fake licenses
for license_id in 'lool', 'fr-lo':
License.objects.create(id=license_id, title=license_id)

def test_simple_flat(self, rmock):
filename = 'flat.jsonld'
Expand Down Expand Up @@ -218,6 +214,23 @@ def test_supported_mime_type(self, rmock):
assert job.errors == []
assert len(job.items) == 3

def test_xml_catalog(self, rmock):
LicenseFactory(id='lov2', title='Licence Ouverte Version 2.0')

url = mock_dcat(rmock, 'catalog.xml', path='catalog.xml')
org = OrganizationFactory()
source = HarvestSourceFactory(backend='dcat',
url=url,
organization=org)

actions.run(source.slug)

# test dct:license support
extras = {'extras__dct:identifier': '3'}
dataset = Dataset.objects.get(**extras)
assert dataset.license.id == 'lov2'


def test_unsupported_mime_type(self, rmock):
url = DCAT_URL_PATTERN.format(path='', domain=TEST_DOMAIN)
rmock.head(url, headers={'Content-Type': 'text/html; charset=utf-8'})
Expand Down