1
1
# -*- coding: utf-8 -*-
2
2
#
3
3
# Copyright (C) 2023 Northwestern University.
4
+ # Copyright (C) 2024 CERN.
4
5
#
5
6
# Invenio-RDM-Records is free software; you can redistribute it and/or modify
6
7
# it under the terms of the MIT License; see LICENSE file for more details.
7
8
8
9
"""Resources serializers tests."""
9
10
10
11
from invenio_rdm_records .resources .serializers import (
12
+ FAIRSignpostingProfileLvl1Serializer ,
11
13
FAIRSignpostingProfileLvl2Serializer ,
12
14
)
13
15
@@ -33,10 +35,6 @@ def test_signposting_serializer_full(running_app, full_record_to_dict):
33
35
"href" : "https://127.0.0.1:5000/api/records/12345-abcde" ,
34
36
"type" : "application/ld+json" ,
35
37
},
36
- # {
37
- # "href": "https://127.0.0.1:5000/api/records/12345-abcde",
38
- # "type": "application/linkset+json",
39
- # },
40
38
{
41
39
"href" : "https://127.0.0.1:5000/api/records/12345-abcde" ,
42
40
"type" : "application/marcxml+xml" ,
@@ -125,6 +123,43 @@ def test_signposting_serializer_full(running_app, full_record_to_dict):
125
123
assert expected == serialized
126
124
127
125
126
+ def test_signposting_lvl1_serializer_full (running_app , full_record_to_dict ):
127
+ ui_url = "https://127.0.0.1:5000/records/12345-abcde"
128
+ api_url = "https://127.0.0.1:5000/api/records/12345-abcde"
129
+ filename = "test.txt"
130
+
131
+ expected = [
132
+ f'<https://orcid.org/0000-0001-8135-3489> ; rel="author"' ,
133
+ f'<https://doi.org/10.1234/12345-abcde> ; rel="cite-as"' ,
134
+ f'<{ api_url } > ; rel="describedby" ; type="application/dcat+xml"' ,
135
+ f'<{ api_url } > ; rel="describedby" ; type="application/json"' ,
136
+ f'<{ api_url } > ; rel="describedby" ; type="application/ld+json"' ,
137
+ f'<{ api_url } > ; rel="describedby" ; type="application/marcxml+xml"' ,
138
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.citationstyles.csl+json"' ,
139
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.datacite.datacite+json"' ,
140
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.datacite.datacite+xml"' ,
141
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.geo+json"' ,
142
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.inveniordm.v1+json"' ,
143
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.inveniordm.v1.full+csv"' ,
144
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.inveniordm.v1.simple+csv"' ,
145
+ f'<{ api_url } > ; rel="describedby" ; type="application/x-bibtex"' ,
146
+ f'<{ api_url } > ; rel="describedby" ; type="application/x-dc+xml"' ,
147
+ f'<{ api_url } > ; rel="describedby" ; type="text/x-bibliography"' ,
148
+ f'<{ ui_url } /files/{ filename } > ; rel="item" ; type="text/plain"' ,
149
+ '<https://customlicense.org/licenses/by/4.0/> ; rel="license"' ,
150
+ '<https://creativecommons.org/licenses/by/4.0/legalcode> ; rel="license"' ,
151
+ '<https://schema.org/Photograph> ; rel="type"' ,
152
+ '<https://schema.org/AboutPage> ; rel="type"' ,
153
+ f'<{ api_url } > ; rel="linkset" ; type="application/linkset+json"' ,
154
+ ]
155
+
156
+ serialized = FAIRSignpostingProfileLvl1Serializer ().serialize_object (
157
+ full_record_to_dict
158
+ )
159
+
160
+ assert expected == serialized .split (" , " )
161
+
162
+
128
163
def test_signposting_serializer_minimal (running_app , minimal_record_to_dict ):
129
164
expected = {
130
165
"linkset" : [
@@ -146,10 +181,6 @@ def test_signposting_serializer_minimal(running_app, minimal_record_to_dict):
146
181
"href" : "https://127.0.0.1:5000/api/records/67890-fghij" ,
147
182
"type" : "application/ld+json" ,
148
183
},
149
- # {
150
- # "href": "https://127.0.0.1:5000/api/records/67890-fghij",
151
- # "type": "application/linkset+json",
152
- # },
153
184
{
154
185
"href" : "https://127.0.0.1:5000/api/records/67890-fghij" ,
155
186
"type" : "application/marcxml+xml" ,
@@ -218,3 +249,37 @@ def test_signposting_serializer_minimal(running_app, minimal_record_to_dict):
218
249
serialized = FAIRSignpostingProfileLvl2Serializer ().dump_obj (minimal_record_to_dict )
219
250
220
251
assert expected == serialized
252
+
253
+
254
+ def test_signposting_lvl1_serializer_minimal (running_app , minimal_record_to_dict ):
255
+ api_url = "https://127.0.0.1:5000/api/records/67890-fghij"
256
+
257
+ expected = [
258
+ # No author since no associated PID
259
+ # No cite-as since no DOI
260
+ f'<{ api_url } > ; rel="describedby" ; type="application/dcat+xml"' ,
261
+ f'<{ api_url } > ; rel="describedby" ; type="application/json"' ,
262
+ f'<{ api_url } > ; rel="describedby" ; type="application/ld+json"' ,
263
+ f'<{ api_url } > ; rel="describedby" ; type="application/marcxml+xml"' ,
264
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.citationstyles.csl+json"' ,
265
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.datacite.datacite+json"' ,
266
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.datacite.datacite+xml"' ,
267
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.geo+json"' ,
268
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.inveniordm.v1+json"' ,
269
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.inveniordm.v1.full+csv"' ,
270
+ f'<{ api_url } > ; rel="describedby" ; type="application/vnd.inveniordm.v1.simple+csv"' ,
271
+ f'<{ api_url } > ; rel="describedby" ; type="application/x-bibtex"' ,
272
+ f'<{ api_url } > ; rel="describedby" ; type="application/x-dc+xml"' ,
273
+ f'<{ api_url } > ; rel="describedby" ; type="text/x-bibliography"' ,
274
+ # No files
275
+ # No license
276
+ '<https://schema.org/Photograph> ; rel="type"' ,
277
+ '<https://schema.org/AboutPage> ; rel="type"' ,
278
+ f'<{ api_url } > ; rel="linkset" ; type="application/linkset+json"' ,
279
+ ]
280
+
281
+ serialized = FAIRSignpostingProfileLvl1Serializer ().serialize_object (
282
+ minimal_record_to_dict
283
+ )
284
+
285
+ assert expected == serialized .split (" , " )
0 commit comments