Skip to content

Commit 3ec4e64

Browse files
authored
Encode spaces in urls for SMK (#3439)
* Encode spaces in urls for smk * Undo change to default for missing urls * Make a separate test for spaces * Undo change to legacy test
1 parent ee77ef5 commit 3ec4e64

File tree

4 files changed

+47
-1
lines changed

4 files changed

+47
-1
lines changed

catalog/dags/providers/provider_api_scripts/smk.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,8 @@ def get_record_data(self, data: dict) -> dict | None:
126126
return None
127127

128128
thumbnail_url = data.get("image_thumbnail")
129+
if thumbnail_url:
130+
thumbnail_url = thumbnail_url.replace(" ", "%20")
129131
height = data.get("image_height")
130132
width = data.get("image_width")
131133
filesize = data.get("image_size") or data.get("size")
@@ -135,7 +137,7 @@ def get_record_data(self, data: dict) -> dict | None:
135137
"foreign_landing_url": foreign_landing_url,
136138
"license_info": license_info,
137139
"title": self._get_title(data),
138-
"url": url,
140+
"url": url.replace(" ", "%20"),
139141
"thumbnail_url": thumbnail_url,
140142
"height": height,
141143
"width": width,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"filesize": 11784886,
3+
"height": 1059,
4+
"url": "https://api.smk.dk/api/v1/thumbnail/KKSgb5743%20verso.jpg",
5+
"thumbnail_url": "https://api.smk.dk/api/v1/thumbnail/KKSgb5743%20verso.jpg",
6+
"width": 3887,
7+
"creator": null,
8+
"foreign_identifier": "1170012466_object",
9+
"foreign_landing_url": "https://open.smk.dk/en/artwork/image/KKSgb5743%20verso",
10+
"meta_data": {},
11+
"title": null
12+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"alternative_images": [
3+
{
4+
"height": 1576,
5+
"iiif_id": "https://iip.smk.dk/iiif/jp2/KKSgb6458.tif.jp2",
6+
"iiif_info": "https://iip.smk.dk/iiif/jp2/KKSgb6458.tif.jp2/info.json",
7+
"mime_type": "image/tiff",
8+
"native": "https://iip.smk.dk/iiif/jp2/KKSgb6458.tif.jp2/full/full/0/native.jpg",
9+
"orientation": "landscape",
10+
"size": 19269857,
11+
"thumbnail": "https://iip-thumb.smk.dk/iiif/jp2/KKSgb6458.tif.jp2/full/!1024,/0/default.jpg",
12+
"width": 4073
13+
}
14+
],
15+
"id": "1170012466_object",
16+
"object_number": "KKSgb5743 verso",
17+
"image_height": 1059,
18+
"image_native": "https://api.smk.dk/api/v1/thumbnail/KKSgb5743 verso.jpg",
19+
"image_size": 11784886,
20+
"image_thumbnail": "https://api.smk.dk/api/v1/thumbnail/KKSgb5743 verso.jpg",
21+
"image_width": 3887,
22+
"rights": "https://creativecommons.org/share-your-work/public-domain/cc0/"
23+
}

catalog/tests/dags/providers/provider_api_scripts/test_smk.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,12 @@ def test_get_record_data_returns_none_with_falsy_required_property(property_name
177177
item[prop] = ""
178178

179179
assert smk.get_record_data(item) is None
180+
181+
182+
def test_get_record_data_with_spaces_in_urls():
183+
item = _get_resource_json("image_data_spaces.json")
184+
expected_image_data = _get_resource_json("expected_image_data_spaces.json")
185+
expected_record_data = {**expected_image_data, "license_info": CC0_SMK}
186+
actual_record_data = smk.get_record_data(item)
187+
188+
assert actual_record_data == expected_record_data

0 commit comments

Comments
 (0)