Skip to content

Commit

Permalink
Add json test & test datafile
Browse files Browse the repository at this point in the history
  • Loading branch information
dalito committed Jan 16, 2025
1 parent aa9507f commit 28460b3
Show file tree
Hide file tree
Showing 3 changed files with 256 additions and 30 deletions.
110 changes: 85 additions & 25 deletions examples/PID4CatRecord-001.yaml
Original file line number Diff line number Diff line change
@@ -1,26 +1,86 @@
# Example data object
---
contains_pids:
- id: lik-123
landing_page_url: https://pid4cat.example.org/lik-123
status: REGISTERED
pid_schema_version: 0.1.0
record_version: 20240219v-0
resource_info:
label: Resource label
description: Resource description
resource_category: SAMPLE
rdf_url: https://example.org/resource
rdf_type: TURTLE
schema_url: https://example.org/schema
schema_type: XSD
dc_rights: CC0-1.0
curation_contact: [email protected]
change_log:
- datetime_log: '2024-02-19T00:00:00Z'
has_agent:
name: Data Fuzzi
person_orcid: 0000-0000-0000-0000
role: TRUSTEE
changed_field: STATUS
description: 'as requested in issue #123'
- responseCode: 1
handle: 21.T12995/lik-1
values:
- index: 1
type: URL
data:
format: string
value: https://pid4cat.example.org/lik-1
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
- index: 2
type: STATUS
data:
format: string
value: REGISTERED
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
- index: 3
type: SCHEMA_VER
data:
format: string
value: v0.1.0
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
- index: 4
type: LICENSE
data:
format: string
value: CC0-1.0
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
- index: 5
type: EMAIL
data:
format: string
value: [email protected]
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
- index: 6
type: RESOURCE_INFO
data:
format: string
value:
- resource_info:
label: Resource label
description: Resource description
resource_category: SAMPLE
representation_variants:
- url: https://example.org/resource
media_type: text/turtle
encoding_format: UTF-8
size: 12345
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
- index: 7
type: RELATED
data:
format: string
value:
- related_identifiers:
- relation_type: IS_PART_OF
related_identifier: https://example.org/collection
datetime_log: '2024-02-19T00:00:00Z'
- relation_type: IS_REFERENCED_BY
related_identifier: https://example.org/referenced
datetime_log: '2024-02-19T00:00:00Z'
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
- index: 8
type: LOG
data:
format: string
value:
- change_log:
- datetime_log: '2024-02-19T00:00:00Z'
has_agent:
name: Data Fuzzi
email: [email protected]
orcid: 0000-0000-0000-0000
affiliation_ror: https://ror.org/029hg0311
role: TRUSTEE
changed_field: STATUS
description: 'as requested in issue #123'
ttl: 86400
timestamp: '2024-05-15T15:51:15Z'
159 changes: 159 additions & 0 deletions src/data/examples/PID4CatRecord-001.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
{
"contains_pids": [
{
"responseCode": 1,
"handle": "21.T12995/lik-1",
"values": [
{
"index": 1,
"type": "URL",
"data": {
"format": "string",
"value": "https://pid4cat.example.org/lik-1"
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
},
{
"index": 2,
"type": "STATUS",
"data": {
"format": "string",
"value": "REGISTERED"
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
},
{
"index": 3,
"type": "SCHEMA_VER",
"data": {
"format": "string",
"value": "v0.1.0"
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
},
{
"index": 4,
"type": "LICENSE",
"data": {
"format": "string",
"value": "CC0-1.0"
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
},
{
"index": 5,
"type": "EMAIL",
"data": {
"format": "string",
"value": "[email protected]"
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
},
{
"index": 6,
"type": "RESOURCE_INFO",
"data": {
"format": "string",
"value": {
"resource_info": {
"label": "Resource label",
"description": "Resource description",
"resource_category": "SAMPLE",
"representation_variants": [
{
"url": "https://example.org/resource",
"media_type": "text/turtle",
"encoding_format": "UTF-8",
"size": 12345
}
]
}
}
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
},
{
"index": 7,
"type": "RELATED",
"data": {
"format": "string",
"value": {
"related_identifiers": [
{
"relation_type": "IS_PART_OF",
"related_identifier": "https://example.org/related",
"datetime_log": "2024-02-19T00:00:00Z",
"has_agent": {
"name": "Data Fuzzi",
"email": "[email protected]",
"orcid": "0000-0000-0000-0000",
"affiliation_ror": "https://ror.org/01abcde",
"role": "TRUSTEE"
}
},
{
"relation_type": "IS_REFERENCED_BY",
"related_identifier": "https://example.org/referenced",
"datetime_log": "2024-02-19T00:00:00Z",
"has_agent": {
"name": "Data Fuzzi",
"email": "[email protected]",
"orcid": "0000-0000-0000-0000",
"affiliation_ror": "https://ror.org/01abcde",
"role": "TRUSTEE"
}
}
]
}
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
},
{
"index": 8,
"type": "LOG",
"data": {
"format": "string",
"value": {
"change_log": [
{
"datetime_log": "2024-02-19T00:00:00Z",
"has_agent": {
"name": "Data Fuzzi",
"email": "[email protected]",
"orcid": "0000-0000-0000-0000",
"affiliation_ror": "https://ror.org/01abcde",
"role": "TRUSTEE"
},
"changed_field": "STATUS",
"description": "Registration completed."
},
{
"datetime_log": "2024-05-15T15:51:15Z",
"has_agent": {
"name": "Data Fuzzi",
"email": "[email protected]",
"orcid": "0000-0000-0000-0000",
"affiliation_ror": "https://ror.org/01abcde",
"role": "TRUSTEE"
},
"changed_field": "RESOURCE_INFO",
"description": "as requested in issue #234"
}
]
}
},
"ttl": 86400,
"timestamp": "2024-05-15T15:51:15Z"
}
]
}
],
"@type": "HandleRecordContainer"
}
17 changes: 12 additions & 5 deletions tests/test_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,27 @@
import glob
import unittest

from linkml_runtime.loaders import yaml_loader
from linkml_runtime.loaders import yaml_loader, json_loader
from pid4cat_model.datamodel.pid4cat_model import HandleRecordContainer

ROOT = os.path.join(os.path.dirname(__file__), "..")
DATA_DIR = os.path.join(ROOT, "src", "data", "examples")

EXAMPLE_FILES = glob.glob(os.path.join(DATA_DIR, "*.yaml"))
EXAMPLE_FILES_YAML = glob.glob(os.path.join(DATA_DIR, "*.yaml"))
EXAMPLE_FILES_JSON = glob.glob(os.path.join(DATA_DIR, "*.json"))


class TestData(unittest.TestCase):
"""Test data and datamodel."""

def test_data(self):
"""Data test."""
for path in EXAMPLE_FILES:
def test_yaml_data(self):
"""Yaml data test."""
for path in EXAMPLE_FILES_YAML:
obj = yaml_loader.load(path, target_class=HandleRecordContainer)
assert obj

def test_json_data(self):
"""Json data test."""
for path in EXAMPLE_FILES_JSON:
obj = json_loader.load(path, target_class=HandleRecordContainer)
assert obj

0 comments on commit 28460b3

Please sign in to comment.