Skip to content

Commit

Permalink
Add stub for croissant validation tests
Browse files Browse the repository at this point in the history
  • Loading branch information
amercader committed Jan 17, 2025
1 parent 675c484 commit 7fd67fe
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ckanext/dcat/tests/profiles/croissant/test_validate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json

import mlcroissant as mlc

from ckan.tests.helpers import call_action
from ckanext.dcat.processors import RDFSerializer
from ckanext.dcat.tests.utils import get_file_contents


def test_valid_output():

dataset_dict = json.loads(get_file_contents("ckan/ckan_full_dataset_croissant.json"))

s = RDFSerializer(profiles=["croissant"])

s.graph_from_dataset(dataset_dict)

croissant_dict = s.g.serialize(format="json-ld")

try:
mlc.Dataset(croissant_dict)
except mlc.ValidationError as exception:
raise
76 changes: 76 additions & 0 deletions examples/ckan/ckan_full_dataset_croissant.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"id": "05469327-3d64-4e54-a23b-e97e0a0b9c81",
"name": "test-dataset-croissant",
"title": "Test Croissant dataset",
"notes": "Lorem ipsum",
"id_given": "my-custom-id",
"is_live_dataset": true,
"url": "http://example.org/ds1",
"version": "1.0b",
"tags": [
{
"name": "Tag 1"
},
{
"name": "Tag 2"
}
],
"created": "2024-05-01",
"issued": "2024-05-02",
"modified": "2024-05-05",
"license": "http://creativecommons.org/licenses/by/3.0/",
"structured_data_license": "http://creativecommons.org/licenses/by/3.0/",
"language": [
"en",
"ca",
"es"
],
"creator": [
{
"name": "Test Creator",
"email": "creator@example.org",
"url": "https://example.org",
"identifier": "http://example.org/creator-id",
"type": "person",
"id_given": "custom-creator-id"
}
],
"publisher": [
{
"name": "Test Publisher",
"email": "publisher@example.org",
"url": "https://example.org",
"identifier": "http://example.org/publisher-id",
"type": "person",
"id_given": "custom-publisher-id"
}
],
"same_as": [
"https://some.other.catalog/dataset/123",
"https://yet.another.catalog/dataset/xyz"
],
"cite_as": "@Article{bloggs24data, author=\"Joe Bloggs and Sally Biggs\"}",
"resources": [
{
"id": "568b8ac9-8c69-4475-b35e-d7f812a63c32",
"name": "Resource 1",
"description": "Some description",
"url": "https://example.com/data.csv",
"format": "CSV",
"type": "fileSet",
"id_given": "my-custom-resource-id",
"size": 12323,
"hash": "4304cf2e751e6053c90b1804c89c0ebb758f395a",
"subresources": [
{
"type": "fileObject",
"id_given": "my-custom-subresource-id",
"description": "Test subresource 1",
"format": "CSV",
"includes": "**.csv",
"excludes": "**.txt"
}
]
}
]
}

0 comments on commit 7fd67fe

Please sign in to comment.