Skip to content

Commit 53dc45f

Browse files
COPDS-2801: spdx_identifier in licence APIs (#118)
* feat: spdx_identifier in licence APIs * test: spdx_identifier * chore: licences.json schema update
1 parent 6f81e7b commit 53dc45f

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

cads_catalogue_api_service/models/base.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ class Licence(TypedDict):
3737
attachment_url: str
3838
scope: LicenceCategories | str | None
3939
portal: str | None
40+
spdx_identifier: str | None
4041

4142

4243
class Licences(TypedDict):

cads_catalogue_api_service/vocabularies.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ def query_licences(
6060
cads_catalogue.database.Licence.revision,
6161
cads_catalogue.database.Licence.scope,
6262
cads_catalogue.database.Licence.portal,
63+
cads_catalogue.database.Licence.spdx_identifier,
6364
)
6465
if scope and scope != LicenceScopeCriterion.all:
6566
query = query.filter(cads_catalogue.database.Licence.scope == scope)
@@ -94,6 +95,7 @@ def query_licence(
9495
cads_catalogue.database.Licence.revision,
9596
cads_catalogue.database.Licence.scope,
9697
cads_catalogue.database.Licence.portal,
98+
cads_catalogue.database.Licence.spdx_identifier,
9799
)
98100
query = query.filter(cads_catalogue.database.Licence.licence_uid == licence_uid)
99101
result = (
@@ -105,6 +107,7 @@ def query_licence(
105107
cads_catalogue.database.Licence.revision,
106108
cads_catalogue.database.Licence.scope,
107109
cads_catalogue.database.Licence.portal,
110+
cads_catalogue.database.Licence.spdx_identifier,
108111
)
109112
.order_by(sa.desc("revision"))
110113
.first()
@@ -151,6 +154,7 @@ def list_licences(
151154
),
152155
scope=licence.scope,
153156
portal=licence.portal,
157+
spdx_identifier=licence.spdx_identifier,
154158
)
155159
for licence in results
156160
]
@@ -176,6 +180,7 @@ def licence_details(
176180
),
177181
scope=licence.scope,
178182
portal=licence.portal,
183+
spdx_identifier=licence.spdx_identifier,
179184
)
180185

181186

schemas/licences.json

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,26 @@
1818
"revision": {
1919
"type": "number"
2020
},
21-
"text": {
21+
"contents_url": {
2222
"type": "string",
2323
"format": "uri"
2424
},
25-
"file": {
25+
"attachment_url": {
2626
"type": "string",
2727
"format": "uri"
28+
},
29+
"scope": {
30+
"type": "string",
31+
"enum": ["portal", "dataset"]
32+
},
33+
"portal": {
34+
"type": ["string", "null"]
35+
},
36+
"spdx_identifier": {
37+
"type": ["string", "null"]
2838
}
2939
},
30-
"required": ["id", "label", "revision", "text"]
40+
"required": ["id", "label", "revision", "contents_url", "attachment_url", "scope", "portal", "spdx_identifier"]
3141
}
3242
}
3343
},

tests/test_20_vocabularies.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
md_filename="cc-by-4.0-1.md",
3434
download_filename="cc-by-4.0-1.pdf",
3535
scope="dataset",
36+
spdx_identifier="CC-BY-4.0",
3637
),
3738
cads_catalogue.database.Licence(
3839
licence_id=3,
@@ -106,6 +107,7 @@ def test_vocabularies_license(monkeypatch) -> None:
106107
"attachment_url": "/document-storage/cc-by-4.0-1.pdf",
107108
"contents_url": "/document-storage/cc-by-4.0-1.md",
108109
"scope": "dataset",
110+
"spdx_identifier": "CC-BY-4.0",
109111
},
110112
{
111113
"id": "cc-by-sa-4.0",
@@ -115,6 +117,7 @@ def test_vocabularies_license(monkeypatch) -> None:
115117
"attachment_url": "/document-storage/cc-by-4.0-2.pdf",
116118
"contents_url": "/document-storage/cc-by-4.0-2.md",
117119
"scope": "dataset",
120+
"spdx_identifier": None,
118121
},
119122
],
120123
}
@@ -139,6 +142,7 @@ def test_vocabulary_license(monkeypatch) -> None:
139142
"attachment_url": "/document-storage/cc-by-4.0-1.pdf",
140143
"contents_url": "/document-storage/cc-by-4.0-1.md",
141144
"scope": "dataset",
145+
"spdx_identifier": "CC-BY-4.0",
142146
}
143147

144148

0 commit comments

Comments
 (0)