Skip to content

Commit

Permalink
Merge pull request #76 from opendata-swiss/tests/add-dcat-ap-ch-seria…
Browse files Browse the repository at this point in the history
…lization-tests

Tests/add dcat ap ch serialization tests
  • Loading branch information
bellisk authored Sep 14, 2023
2 parents 5e77045 + 27e7a77 commit be003c4
Show file tree
Hide file tree
Showing 10 changed files with 404 additions and 265 deletions.
2 changes: 1 addition & 1 deletion ckanext/dcatapchharvest/profiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -726,7 +726,7 @@ def graph_from_dataset(self, dataset_dict, dataset_ref): # noqa
g.add((dataset_ref, DCT.temporal, temporal_extent))

# Themes
groups = self._get_dataset_value(dataset_dict, 'groups')
groups = self._get_dataset_value(dataset_dict, 'groups', [])
for group_name in groups:
ogdch_theme_ref = URIRef(CHTHEMES_URI + group_name.get('name'))
eu_theme_ref_list = eu_theme_mapping.get(ogdch_theme_ref)
Expand Down
35 changes: 35 additions & 0 deletions ckanext/dcatapchharvest/tests/base_test_classes.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import os

from rdflib import URIRef, BNode, Literal


class BaseParseTest(object):
def _extras(self, dataset):
extras = {}
for extra in dataset.get('extras'):
extras[extra['key']] = extra['value']
return extras

def _get_file_contents(self, file_name):
path = os.path.join(os.path.dirname(__file__),
'fixtures',
file_name)
with open(path, 'r') as f:
return f.read()


class BaseSerializeTest(BaseParseTest):

def _triples(self, graph, subject, predicate, _object, data_type=None):

if not (isinstance(_object, URIRef) or isinstance(_object, BNode) or _object is None):
if data_type:
_object = Literal(_object, datatype=data_type)
else:
_object = Literal(_object)
triples = [t for t in graph.triples((subject, predicate, _object))]
return triples

def _triple(self, graph, subject, predicate, _object, data_type=None):
triples = self._triples(graph, subject, predicate, _object, data_type)
return triples[0] if triples else None
16 changes: 16 additions & 0 deletions ckanext/dcatapchharvest/tests/fixtures/dataset-test-uri.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"id": "4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6",
"name": "test-dataset",
"title": "Test DCAT dataset",
"uri": "https://test.example.com/dataset/foo",
"version": "1.0b",
"metadata_created": "2015-06-26T15:21:09.034694",
"metadata_modified": "2015-06-26T15:21:09.075774",
"resources": [
{
"uri": "https://test.example.com/dataset/foo/resource/fxx",
"id": "5f2be71f-636c-4d3f-aac1-50830b97f853",
"package_id": "4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6"
}
]
}
162 changes: 162 additions & 0 deletions ckanext/dcatapchharvest/tests/fixtures/dataset.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
{
"id": "4b6fe9ca-dc77-4cec-92a4-55c6624a5bd6",
"name": "test-dataset",
"title": "Test DCAT dataset",
"url": "http://example.com/ds1",
"version": "1.0b",
"issued": "2015-06-26T15:21:09.034694",
"keywords": {
"fr": [],
"de": [
"alter",
"sozialhilfe"
],
"en": [
"age"
],
"it": []
},
"groups": [
{
"display_name": {
"fr": "Economie nationale",
"de": "Volkswirtschaft",
"en": "National economy",
"it": "Economia"
},
"description": {
"fr": "",
"de": "",
"en": "some descriptiom",
"it": ""
},
"image_display_url": "",
"title": {
"fr": "Economie nationale",
"de": "Volkswirtschaft",
"en": "National economy",
"it": "Economia"
},
"id": "5389c3f2-2f64-436b-9fac-2d1fc342f7b5",
"name": "national-economy"
},
{
"display_name": {
"fr": "Education, science",
"de": "Bildung, Wissenschaft",
"en": "Education and science",
"it": "Formazione e scienza"
},
"description": {
"fr": "",
"de": "",
"en": "",
"it": ""
},
"image_display_url": "",
"title": {
"fr": "Education, science",
"de": "Bildung, Wissenschaft",
"en": "Education and science",
"it": "Formazione e scienza"
},
"id": "afcb4a2a-b4b0-4d7c-984a-9078e964be49",
"name": "education"
},
{
"display_name": {
"fr": "Finances",
"de": "Finanzen",
"en": "Finances",
"it": "Finanze"
},
"description": {
"fr": "",
"de": "",
"en": "",
"it": ""
},
"image_display_url": "",
"title": {
"fr": "Finances",
"de": "Finanzen",
"en": "Finances",
"it": "Finanze"
},
"id": "79cbe120-e9c6-4249-b934-58ca980606d7",
"name": "finances"
}
],
"description": {
"fr": "",
"de": "Deutsche Beschreibung",
"en": "English Description",
"it": ""
},
"extras": [
{
"key": "alternate_identifier",
"value": "[\"xyz\", \"abc\"]"
},
{
"key": "identifier",
"value": "26be5452-fc5c-11e7-8450-fea9aa178066"
},
{
"key": "version_notes",
"value": "This is a beta version"
},
{
"key": "frequency",
"value": "monthly"
},
{
"key": "language",
"value": "[\"en\"]"
},
{
"key": "theme",
"value": "[\"http://eurovoc.europa.eu/100142\", \"http://eurovoc.europa.eu/100152\"]"
},
{
"key": "conforms_to",
"value": "[\"Standard 1\", \"Standard 2\"]"
},
{
"key": "access_rights",
"value": "public"
},
{
"key": "documentation",
"value": "[\"http://dataset.info.org/doc1\", \"http://dataset.info.org/doc2\"]"
},
{
"key": "provenance",
"value": "Some statement about provenance"
},
{
"key": "dcat_type",
"value": "test-type"
},
{
"key": "related_resource",
"value": "[\"http://dataset.info.org/related1\", \"http://dataset.info.org/related2\"]"
},
{
"key": "has_version",
"value": "[\"https://data.some.org/catalog/datasets/derived-dataset-1\", \"https://data.some.org/catalog/datasets/derived-dataset-2\"]"
},
{
"key": "is_version_of",
"value": "[\"https://data.some.org/catalog/datasets/original-dataset\"]"
},
{
"key": "source",
"value": "[\"https://data.some.org/catalog/datasets/source-dataset-1\", \"https://data.some.org/catalog/datasets/source-dataset-2\"]"
},
{
"key": "sample",
"value": "[\"https://data.some.org/catalog/datasets/9df8df51-63db-37a8-e044-0003ba9b0d98/sample\"]"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# -*- coding: utf-8 -*-

import os
import json
from datetime import datetime

import nose

Expand All @@ -11,27 +9,12 @@

from ckanext.dcat.processors import RDFParser
from ckanext.dcatapchharvest.profiles import (DCAT, DCT)
from ckanext.dcatapchharvest.tests.base_test_classes import BaseParseTest

eq_ = nose.tools.eq_
assert_true = nose.tools.assert_true


class BaseParseTest(object):

def _extras(self, dataset):
extras = {}
for extra in dataset.get('extras'):
extras[extra['key']] = extra['value']
return extras

def _get_file_contents(self, file_name):
path = os.path.join(os.path.dirname(__file__),
'fixtures',
file_name)
with open(path, 'r') as f:
return f.read()


class TestSwissDCATAPProfileParsing(BaseParseTest):

def test_dataset_all_fields(self):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# -*- coding: utf-8 -*-

import os
import nose
import json
from ckanext.dcat.processors import RDFParser
from ckanext.dcatapchharvest.tests.base_test_classes import BaseParseTest

eq_ = nose.tools.eq_
assert_true = nose.tools.assert_true


class BaseParseTest(object):
def _get_file_contents(self, file_name):
path = os.path.join(os.path.dirname(__file__),
'fixtures',
file_name)
with open(path, 'r') as f:
return f.read()


class ConformantProfileParseTest(BaseParseTest):
def test_dcatap_conformant_landing_page_import(self):
contents = self._get_file_contents('conformant/dataset-landing-page.xml')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,23 +1,14 @@
# -*- coding: utf-8 -*-

import os
import nose
import json
from ckanext.dcat.processors import RDFParser
from ckanext.dcatapchharvest.tests.base_test_classes import BaseParseTest

eq_ = nose.tools.eq_
assert_true = nose.tools.assert_true


class BaseParseTest(object):
def _get_file_contents(self, file_name):
path = os.path.join(os.path.dirname(__file__),
'fixtures',
file_name)
with open(path, 'r') as f:
return f.read()


class DeprecatedProfileParseTest(BaseParseTest):
def test_deprecated_landing_page_import(self):
contents = self._get_file_contents('deprecated/dataset-landing-page.xml')
Expand Down
Loading

0 comments on commit be003c4

Please sign in to comment.