Skip to content

Commit

Permalink
Consolidate input datasets in tests
Browse files Browse the repository at this point in the history
Use the same files in examples used in the shacl tests, don't use
separate dataset dicts on each test.
  • Loading branch information
amercader committed Oct 7, 2024
1 parent 0c5b294 commit effa3f6
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 244 deletions.
130 changes: 3 additions & 127 deletions ckanext/dcat/tests/profiles/dcat_ap_2/test_scheming_support.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,133 +48,9 @@ def test_e2e_ckan_to_dcat(self):
are exposed in the DCAT RDF graph
"""

dataset_dict = {
# Core fields
"name": "test-dataset",
"title": "Test DCAT dataset",
"notes": "Lorem ipsum",
"url": "http://example.org/ds1",
"version": "1.0b",
"tags": [{"name": "Tag 1"}, {"name": "Tag 2"}],
# Standard fields
"issued": "2024-05-01",
"modified": "2024-05-05",
"identifier": "xx-some-dataset-id-yy",
"frequency": "monthly",
"provenance": "Statement about provenance",
"dcat_type": "test-type",
"version_notes": "Some version notes",
"access_rights": "Statement about access rights",
# List fields (lists)
"alternate_identifier": ["alt-id-1", "alt-id-2"],
"theme": [
"https://example.org/uri/theme1",
"https://example.org/uri/theme2",
"https://example.org/uri/theme3",
],
"language": ["en", "ca", "es"],
"documentation": ["https://example.org/some-doc.html"],
"conforms_to": ["Standard 1", "Standard 2"],
"is_referenced_by": [
"https://doi.org/10.1038/sdata.2018.22",
"test_isreferencedby",
],
"applicable_legislation": [
"http://data.europa.eu/eli/reg_impl/2023/138/oj",
"http://data.europa.eu/eli/reg_impl/2023/138/oj_alt",
],
# Repeating subfields
"contact": [
{"name": "Contact 1", "email": "[email protected]"},
{"name": "Contact 2", "email": "[email protected]"},
],
"publisher": [
{
"name": "Test Publisher",
"email": "[email protected]",
"url": "https://example.org",
"type": "public_body",
"identifier": "http://example.org/publisher-id",
},
],
"creator": [
{
"name": "Test Creator",
"email": "[email protected]",
"url": "https://example.org/creator",
"type": "person",
"identifier": "http://example.org/creator-id",
}
],
"temporal_coverage": [
{"start": "1905-03-01", "end": "2013-01-05"},
{"start": "2024-04-10", "end": "2024-05-29"},
],
"temporal_resolution": "PT15M",
"spatial_coverage": [
{
"geom": {
"type": "Polygon",
"coordinates": [
[
[11.9936, 54.0486],
[11.9936, 54.2466],
[12.3045, 54.2466],
[12.3045, 54.0486],
[11.9936, 54.0486],
]
],
},
"text": "Tarragona",
"uri": "https://sws.geonames.org/6361390/",
"bbox": {
"type": "Polygon",
"coordinates": [
[
[-2.1604, 42.7611],
[-2.0938, 42.7611],
[-2.0938, 42.7931],
[-2.1604, 42.7931],
[-2.1604, 42.7611],
]
],
},
"centroid": {"type": "Point", "coordinates": [1.26639, 41.12386]},
}
],
"spatial_resolution_in_meters": 1.5,
"resources": [
{
"name": "Resource 1",
"description": "Some description",
"url": "https://example.com/data.csv",
"format": "CSV",
"availability": "http://publications.europa.eu/resource/authority/planned-availability/EXPERIMENTAL",
"compress_format": "http://www.iana.org/assignments/media-types/application/gzip",
"package_format": "http://publications.europa.eu/resource/authority/file-type/TAR",
"size": 12323,
"hash": "4304cf2e751e6053c90b1804c89c0ebb758f395a",
"hash_algorithm": "http://spdx.org/rdf/terms#checksumAlgorithm_sha1",
"status": "http://purl.org/adms/status/Completed",
"access_url": "https://example.com/data.csv",
"download_url": "https://example.com/data.csv",
"issued": "2024-05-01T01:20:33",
"modified": "2024-05-05T09:33:20",
"license": "http://creativecommons.org/licenses/by/3.0/",
"rights": "Some stament about rights",
"language": ["en", "ca", "es"],
"access_services": [
{
"title": "Access Service 1",
"endpoint_url": [
"https://example.org/access_service/1",
"https://example.org/access_service/2",
],
}
],
}
],
}
dataset_dict = json.loads(
self._get_file_contents("ckan/ckan_full_dataset_dcat_ap.json")
)

dataset = call_action("package_create", **dataset_dict)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import json
import pytest

from rdflib.namespace import RDF
Expand Down Expand Up @@ -45,123 +46,9 @@ def test_e2e_ckan_to_dcat(self):
are exposed in the DCAT RDF graph
"""

dataset_dict = {
# Core fields
"name": "test-dataset",
"title": "Test DCAT dataset",
"notes": "Lorem ipsum",
"url": "http://example.org/ds1",
"version": "1.0b",
"tags": [{"name": "Tag 1"}, {"name": "Tag 2"}],
# Standard fields
"issued": "2024-05-01",
"modified": "2024-05-05",
"identifier": "xx-some-dataset-id-yy",
"frequency": "monthly",
"provenance": "Statement about provenance",
"dcat_type": "test-type",
"version_notes": "Some version notes",
"access_rights": "Statement about access rights",
# List fields (lists)
"alternate_identifier": ["alt-id-1", "alt-id-2"],
"theme": [
"https://example.org/uri/theme1",
"https://example.org/uri/theme2",
"https://example.org/uri/theme3",
],
"language": ["en", "ca", "es"],
"documentation": ["https://example.org/some-doc.html"],
"conforms_to": ["Standard 1", "Standard 2"],
"is_referenced_by": [
"https://doi.org/10.1038/sdata.2018.22",
"test_isreferencedby",
],
"applicable_legislation": [
"http://data.europa.eu/eli/reg_impl/2023/138/oj",
"http://data.europa.eu/eli/reg_impl/2023/138/oj_alt",
],
# Repeating subfields
"contact": [
{"name": "Contact 1", "email": "[email protected]"},
{"name": "Contact 2", "email": "[email protected]"},
],
"publisher": [
{
"name": "Test Publisher",
"email": "[email protected]",
"url": "https://example.org",
"type": "public_body",
},
],
"temporal_coverage": [
{"start": "1905-03-01", "end": "2013-01-05"},
{"start": "2024-04-10", "end": "2024-05-29"},
],
"temporal_resolution": "PT15M",
"spatial_coverage": [
{
"geom": {
"type": "Polygon",
"coordinates": [
[
[11.9936, 54.0486],
[11.9936, 54.2466],
[12.3045, 54.2466],
[12.3045, 54.0486],
[11.9936, 54.0486],
]
],
},
"text": "Tarragona",
"uri": "https://sws.geonames.org/6361390/",
"bbox": {
"type": "Polygon",
"coordinates": [
[
[-2.1604, 42.7611],
[-2.0938, 42.7611],
[-2.0938, 42.7931],
[-2.1604, 42.7931],
[-2.1604, 42.7611],
]
],
},
"centroid": {"type": "Point", "coordinates": [1.26639, 41.12386]},
}
],
"spatial_resolution_in_meters": 1.5,
"resources": [
{
"name": "Resource 1",
"description": "Some description",
"url": "https://example.com/data.csv",
"format": "CSV",
"availability": "http://publications.europa.eu/resource/authority/planned-availability/EXPERIMENTAL",
"compress_format": "http://www.iana.org/assignments/media-types/application/gzip",
"package_format": "http://publications.europa.eu/resource/authority/file-type/TAR",
"size": 12323,
"hash": "4304cf2e751e6053c90b1804c89c0ebb758f395a",
"hash_algorithm": "http://spdx.org/rdf/terms#checksumAlgorithm_sha1",
"status": "http://purl.org/adms/status/Completed",
"access_url": "https://example.com/data.csv",
"download_url": "https://example.com/data.csv",
"issued": "2024-05-01T01:20:33",
"modified": "2024-05-05T09:33:20",
"license": "http://creativecommons.org/licenses/by/3.0/",
"rights": "Some stament about rights",
"language": ["en", "ca", "es"],
"access_services": [
{
"title": "Access Service 1",
"endpoint_url": [
"https://example.org/access_service/1",
"https://example.org/access_service/2",
],
}
],
}
],
}
dataset_dict = json.loads(
self._get_file_contents("ckan/ckan_full_dataset_dcat_ap.json")
)

dataset = call_action("package_create", **dataset_dict)

Expand Down
3 changes: 3 additions & 0 deletions ckanext/dcat/tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,6 @@ def _get_dict_from_list(self, dict_list, key, value):
if dict.get(key) == value:
return dict
return None

def _get_file_contents(self, file_name):
return get_file_contents(file_name)
15 changes: 15 additions & 0 deletions examples/ckan/ckan_full_dataset_dcat_ap_2.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,33 @@
"email": "[email protected]"
}
],
"creator": [
{
"name": "Test Creator",
"email": "[email protected]",
"url": "https://example.org",
"identifier": "http://example.org/creator-id",
"type": "public_body"
}
],
"publisher": [
{
"name": "Test Publisher",
"email": "[email protected]",
"url": "https://example.org",
"identifier": "http://example.org/publisher-id",
"type": "public_body"
}
],
"temporal_coverage": [
{

"start": "1905-03-01",
"end": "2013-01-05"
},
{
"start": "2024-04-10",
"end": "2024-05-29"
}
],
"temporal_resolution": "PT15M",
Expand Down

0 comments on commit effa3f6

Please sign in to comment.