2
2
#
3
3
# SPDX-License-Identifier: AGPL-3.0-only
4
4
5
- import pytest
6
- from datetime import datetime
7
- from dateutil .tz import tzutc
5
+ import json
8
6
from pathlib import Path
9
7
from unittest .mock import patch
10
8
11
- from docopt import extras
9
+ import pytest
12
10
from rdflib import Graph
13
11
from ckanext .fairdatapoint .harvesters .domain .fair_data_point_record_to_package_converter import (
14
12
FairDataPointRecordToPackageConverter )
@@ -39,6 +37,10 @@ def test_fdp_record_converter_catalog(self, parser_catalogs):
39
37
record = data , series_mapping = None )
40
38
assert parser_catalogs .called
41
39
40
+ @staticmethod
41
+ def _extras_to_dict (extras_list ):
42
+ return {item ["key" ]: item ["value" ] for item in extras_list }
43
+
42
44
def test_fdp_record_converter_dataset_dict (self ):
43
45
fdp_record_to_package = FairDataPointRecordToPackageConverter (profile = "fairdatapoint_dcat_ap" )
44
46
data = Graph ().parse (Path (TEST_DATA_DIRECTORY , "Project_27866022694497978_out.ttl" )).serialize ()
@@ -47,17 +49,64 @@ def test_fdp_record_converter_dataset_dict(self):
47
49
"http://purl.org/zonmw/generic/10006;"
48
50
"dataset=https://covid19initiatives.health-ri.nl/p/Project/27866022694497978" ,
49
51
record = data , series_mapping = None )
50
- expected_dataset = dict (extras = [], uri = "https://covid19initiatives.health-ri.nl/p/Project/27866022694497978" ,
51
- resources = [], title = "COVID-NL cohort MUMC+" ,
52
- notes = "Clinical data of MUMC COVID-NL cohort" , tags = [],
53
- license_id = "" , identifier = "27866022694497978" ,
54
- has_version = [
55
- "https://repo.metadatacenter.org/template-instances/2836bf1c-76e9-44e7-a65e-80e9ca63025a" ],
56
- contact = [{'email' : '' , 'identifier' : 'https://orcid.org/0000-0002-4348-707X' , 'name' : 'N.K. De Vries' ,'uri' : '' , 'url' : '' }
57
- ], creator = [{'email' : '' , 'identifier' : '' , 'name' : '' , 'type' : '' , 'uri' : 'https://orcid.org/0000-0002-0180-3636' , 'url' : '' }],
58
- publisher = [{'email' : '' ,'identifier' : '' ,'name' : '' ,'type' : '' ,'uri' : 'https://opal.health-ri.nl/pub' , 'url' : '' }],
59
- temporal_start = '2020-01-01' , temporal_end = '2025-12-31' )
60
- assert actual_dataset == expected_dataset
52
+ extras_dict = self ._extras_to_dict (actual_dataset ["extras" ])
53
+
54
+ assert actual_dataset ["resources" ] == []
55
+ assert actual_dataset ["title" ] == "COVID-NL cohort MUMC+"
56
+ assert actual_dataset ["notes" ] == "Clinical data of MUMC COVID-NL cohort"
57
+ assert actual_dataset ["tags" ] == []
58
+ assert actual_dataset ["license_id" ] == ""
59
+ assert actual_dataset ["has_version" ] == [
60
+ "https://repo.metadatacenter.org/template-instances/2836bf1c-76e9-44e7-a65e-80e9ca63025a"
61
+ ]
62
+ assert actual_dataset ["contact" ] == [
63
+ {
64
+ "email" : "" ,
65
+ "identifier" : "https://orcid.org/0000-0002-4348-707X" ,
66
+ "name" : "N.K. De Vries" ,
67
+ "uri" : "" ,
68
+ "url" : "" ,
69
+ }
70
+ ]
71
+ assert actual_dataset ["creator" ] == [
72
+ {
73
+ "email" : "" ,
74
+ "identifier" : "" ,
75
+ "name" : "" ,
76
+ "type" : "" ,
77
+ "uri" : "https://orcid.org/0000-0002-0180-3636" ,
78
+ "url" : "" ,
79
+ }
80
+ ]
81
+ assert actual_dataset ["publisher" ] == [
82
+ {
83
+ "email" : "" ,
84
+ "identifier" : "" ,
85
+ "name" : "" ,
86
+ "type" : "" ,
87
+ "uri" : "https://opal.health-ri.nl/pub" ,
88
+ "url" : "" ,
89
+ }
90
+ ]
91
+ assert actual_dataset ["temporal_start" ] == "2020-01-01"
92
+ assert actual_dataset ["temporal_end" ] == "2025-12-31"
93
+ assert actual_dataset ["retention_period" ] == []
94
+
95
+ assert extras_dict ["identifier" ] == "27866022694497978"
96
+ assert (
97
+ extras_dict ["uri" ]
98
+ == "https://covid19initiatives.health-ri.nl/p/Project/27866022694497978"
99
+ )
100
+ assert extras_dict ["contact_name" ] == "N.K. De Vries"
101
+ assert (
102
+ extras_dict ["contact_identifier" ]
103
+ == "https://orcid.org/0000-0002-4348-707X"
104
+ )
105
+ assert (
106
+ extras_dict ["publisher_uri" ] == "https://opal.health-ri.nl/pub"
107
+ )
108
+ assert extras_dict ["creator_uri" ] == "https://orcid.org/0000-0002-0180-3636"
109
+ assert extras_dict ["homepage" ] == "http://localhost:5000"
61
110
62
111
def test_fdp_record_converter_catalog_dict (self ):
63
112
fdp_record_to_package = FairDataPointRecordToPackageConverter (profile = "fairdatapoint_dcat_ap" )
@@ -66,33 +115,40 @@ def test_fdp_record_converter_catalog_dict(self):
66
115
guid = "catalog=https://fair.healthinformationportal.eu/catalog/1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d" ,
67
116
record = data , series_mapping = None )
68
117
118
+ extras_dict = self ._extras_to_dict (actual ["extras" ])
69
119
70
- expected = {
71
- "uri" : "https://fair.healthinformationportal.eu/catalog/1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d" ,
72
- "access_rights" : "https://fair.healthinformationportal.eu/catalog/"
73
- "1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d#accessRights" ,
74
- "conforms_to" : ["https://fair.healthinformationportal.eu/profile/"
75
- "a0949e72-4466-4d53-8900-9436d1049a4b" ],
76
- "extras" : [],
77
- "has_version" : ["1.0" ],
78
- "issued" : '2023-10-06T10:12:55.614000+00:00' ,
79
- "language" : ["http://id.loc.gov/vocabulary/iso639-1/en" ],
80
- "license_id" : "" ,
81
- "modified" : '2023-10-06T10:12:55.614000+00:00' ,
82
- 'publisher' : [
83
- {
84
- 'email' : '' ,
85
- 'identifier' : '' ,
86
- "name" : "Automatic" ,
87
- 'type' : '' ,
88
- 'uri' : '' ,
89
- 'url' : '' ,
90
- },
91
- ],
92
-
93
- "resources" : [],
94
- "tags" : [],
95
- "title" : "Slovenia National Node"
96
- }
120
+ assert actual ["has_version" ] == ["1.0" ]
121
+ assert actual ["issued" ] == "2023-10-06T10:12:55.614000+00:00"
122
+ assert actual ["modified" ] == "2023-10-06T10:12:55.614000+00:00"
123
+ assert actual ["license_id" ] == ""
124
+ assert actual ["publisher" ] == [
125
+ {
126
+ "email" : "" ,
127
+ "identifier" : "" ,
128
+ "name" : "Automatic" ,
129
+ "type" : "" ,
130
+ "uri" : "" ,
131
+ "url" : "" ,
132
+ }
133
+ ]
134
+ assert actual ["resources" ] == []
135
+ assert actual ["tags" ] == []
136
+ assert actual ["title" ] == "Slovenia National Node"
137
+ assert actual ["retention_period" ] == []
97
138
98
- assert actual == expected
139
+ assert (
140
+ extras_dict ["uri" ]
141
+ == "https://fair.healthinformationportal.eu/catalog/1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d"
142
+ )
143
+ assert (
144
+ extras_dict ["access_rights" ]
145
+ == "https://fair.healthinformationportal.eu/catalog/1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d#accessRights"
146
+ )
147
+ assert json .loads (extras_dict ["conforms_to" ]) == [
148
+ "https://fair.healthinformationportal.eu/profile/a0949e72-4466-4d53-8900-9436d1049a4b"
149
+ ]
150
+ assert json .loads (extras_dict ["language" ]) == [
151
+ "http://id.loc.gov/vocabulary/iso639-1/en"
152
+ ]
153
+ assert extras_dict ["publisher_name" ] == "Automatic"
154
+ assert extras_dict ["homepage" ] == "http://localhost:5000"
0 commit comments