From c61cdd2d18e1febd27430e2cba9f52fac9b181c9 Mon Sep 17 00:00:00 2001 From: kovalch Date: Mon, 29 Jul 2024 20:08:33 +0200 Subject: [PATCH] fix: Update tests tu use uri and not str as a value for license and rights --- ckanext/dcatapchharvest/dcat_helpers.py | 2 +- ckanext/dcatapchharvest/profiles.py | 8 ++++++-- .../dcatapchharvest/tests/test_dcatap_ch_parse.py | 10 +++++----- .../tests/test_dcatap_ch_serialize.py | 12 ++++++------ 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/ckanext/dcatapchharvest/dcat_helpers.py b/ckanext/dcatapchharvest/dcat_helpers.py index bc57608..62292b2 100644 --- a/ckanext/dcatapchharvest/dcat_helpers.py +++ b/ckanext/dcatapchharvest/dcat_helpers.py @@ -13,7 +13,7 @@ DCT = Namespace("http://purl.org/dc/terms/") EUTHEMES = \ Namespace("http://publications.europa.eu/resource/authority/data-theme/") -FOAF = Namespace("http://xmlns.com/foaf/0.1/") # noqa +FOAF = Namespace("http://xmlns.com/foaf/0.1/") HYDRA = Namespace('http://www.w3.org/ns/hydra/core#') SKOSXL = Namespace("http://www.w3.org/2008/05/skos-xl#") diff --git a/ckanext/dcatapchharvest/profiles.py b/ckanext/dcatapchharvest/profiles.py index 09d6813..7b1f392 100644 --- a/ckanext/dcatapchharvest/profiles.py +++ b/ckanext/dcatapchharvest/profiles.py @@ -624,8 +624,12 @@ def parse_dataset(self, dataset_dict, dataset_ref): # noqa resource_dict[key] = value # Rights & License save homepage uri - rights = self._license_rights_homepage_uri(distribution, DCT.rights) - license = self._license_rights_homepage_uri(distribution, DCT.license) + rights = self._license_rights_homepage_uri( + distribution, DCT.rights + ) + license = self._license_rights_homepage_uri( + distribution, DCT.license + ) if rights is None and license is not None: resource_dict['license'] = license diff --git a/ckanext/dcatapchharvest/tests/test_dcatap_ch_parse.py b/ckanext/dcatapchharvest/tests/test_dcatap_ch_parse.py index 26de93d..d729b38 100644 --- a/ckanext/dcatapchharvest/tests/test_dcatap_ch_parse.py +++ b/ckanext/dcatapchharvest/tests/test_dcatap_ch_parse.py @@ -32,8 +32,8 @@ def test_rights_license(self): # Resources eq_(len(dataset['resources']), 1) resource = dataset['resources'][0] - eq_(resource['rights'], u'NonCommercialAllowed-CommercialAllowed-ReferenceRequired') - eq_(resource['license'], u'NonCommercialAllowed-CommercialWithPermission-ReferenceRequired') + eq_(unicode(resource['rights']), u'https://opendata.swiss/en/terms-of-use/#terms_by') + eq_(unicode(resource['license']), u'https://opendata.swiss/en/terms-of-use/#terms_by_ask') def test_dataset_all_fields(self): @@ -146,8 +146,8 @@ def test_dataset_all_fields(self): eq_(resource['format'], u'html') eq_(resource['media_type'], u'text/html') eq_(resource['identifier'], u'346265-fr@bundesamt-fur-statistik-bfs') - eq_(resource['rights'], u'NonCommercialAllowed-CommercialAllowed-ReferenceRequired') - eq_(resource['license'], u'Creative Commons Zero 1.0 Universal (CC0 1.0)') + eq_(resource['license'], u'https://opendata.swiss/en/terms-of-use/#terms_by') + eq_(resource['rights'], u'http://www.opendefinition.org/licenses/cc-zero') eq_(resource['language'], [u'fr']) eq_(resource['issued'], u'1900-12-31T00:00:00') eq_(resource['temporal_resolution'], u'P1D') @@ -402,7 +402,7 @@ def test_multiple_rights_statements(self): dataset = [d for d in p.datasets()][0] resource = dataset["resources"][0] - eq_(resource['rights'], u"NonCommercialAllowed-CommercialWithPermission-ReferenceRequired") + eq_(unicode(resource['rights']), u"https://opendata.swiss/en/terms-of-use/#terms_by_ask") def test_eu_themes_mapping(self): contents = self._get_file_contents('catalog-themes.xml') diff --git a/ckanext/dcatapchharvest/tests/test_dcatap_ch_serialize.py b/ckanext/dcatapchharvest/tests/test_dcatap_ch_serialize.py index 333ea47..8e3e77b 100644 --- a/ckanext/dcatapchharvest/tests/test_dcatap_ch_serialize.py +++ b/ckanext/dcatapchharvest/tests/test_dcatap_ch_serialize.py @@ -113,22 +113,22 @@ def test_graph_from_dataset(self): if resource_dict.get('rights') == 'Creative Commons Zero 1.0 Universal (CC0 1.0)': assert self._triple(g, distribution, DCT.rights, URIRef("https://creativecommons.org/publicdomain/zero/1.0/")) - if resource_dict.get('license') == 'NonCommercialAllowed-CommercialAllowed-ReferenceNotRequired': + if resource_dict.get('license') == 'https://opendata.swiss/terms-of-use/#terms_open': assert self._triple(g, distribution, DCT.license, URIRef("http://dcat-ap.ch/vocabulary/licenses/terms_open")) # 28e75e40-e1a1-497b-a1b9-8c1834d60201 - if resource_dict.get('rights') == "http://dcat-ap.ch/vocabulary/licenses/terms_by": + if resource_dict.get('rights') == "https://opendata.swiss/terms-of-use#terms_by": assert self._triple(g, distribution, DCT.rights, URIRef("http://dcat-ap.ch/vocabulary/licenses/terms_by")) - if resource_dict.get('license') == "NonCommercialAllowed-CommercialAllowed-ReferenceRequired": + if resource_dict.get('license') == "https://opendata.swiss/terms-of-use#terms_by": assert self._triple(g, distribution, DCT.license, URIRef("http://dcat-ap.ch/vocabulary/licenses/terms_by")) # 0cfce6ba-28f4-4229-b733-f6492c650395 - if resource_dict.get('rights') == "http://dcat-ap.ch/vocabulary/licenses/terms_by_ask": + if resource_dict.get('rights') == "https://opendata.swiss/terms-of-use#terms_by_ask": assert self._triple(g, distribution, DCT.rights, URIRef("http://dcat-ap.ch/vocabulary/licenses/terms_by_ask")) - if resource_dict.get('license') == "https://creativecommons.org/licenses/by/4.0/": - assert self._triple(g, distribution, DCT.license, URIRef("https://creativecommons.org/licenses/by/4.0/")) + if resource_dict.get('rights') == " http://www.opendefinition.org/licenses/cc-by/": + assert self._triple(g, distribution, DCT.rights, URIRef("https://creativecommons.org/licenses/by/4.0/")) if resource_dict.get('format') == "CSV": assert self._triple(g, distribution, DCT['format'], URIRef("http://publications.europa.eu/resource/authority/file-type/CSV"))