Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: collection title escaped unicode TDE-594 #288

Merged
merged 2 commits into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions scripts/collection_from_items.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
from boto3 import client
from linz_logger import get_log

from scripts.files.fs import write
from scripts.files.fs_s3 import bucket_name_from_path, get_object_parallel_multithreading, list_json_in_uri
from scripts.logging.time_helper import time_in_ms
from scripts.stac.imagery.collection import ImageryCollection
Expand Down Expand Up @@ -62,7 +61,7 @@ def main() -> None:
)

destination = os.path.join(uri, "collection.json")
write(destination, json.dumps(collection.stac).encode("utf-8"))
collection.write_to(destination)
get_log().info("collection written", destination=destination)


Expand Down
5 changes: 5 additions & 0 deletions scripts/stac/imagery/collection.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import json
from datetime import datetime
from typing import Any, Dict, List, Optional

import ulid

from scripts.files.fs import write
from scripts.stac.util.STAC_VERSION import STAC_VERSION


Expand Down Expand Up @@ -110,3 +112,6 @@ def update_extent(self, bbox: Optional[List[float]] = None, interval: Optional[L
self.stac["extent"]["spatial"]["bbox"] = [bbox]
if interval:
self.stac["extent"]["temporal"]["interval"] = [interval]

def write_to(self, destination: str) -> None:
write(destination, json.dumps(self.stac, ensure_ascii=False).encode("utf-8"))
27 changes: 27 additions & 0 deletions scripts/stac/tests/collection_test.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
import json
import os
from shutil import rmtree
from tempfile import mkdtemp
from typing import Generator

import pytest

from scripts.files.fs import read
from scripts.stac.imagery.collection import ImageryCollection
from scripts.stac.imagery.item import ImageryItem

Expand Down Expand Up @@ -90,3 +95,25 @@ def test_add_item(mocker, setup_collection: ImageryCollection) -> None: # type:
assert {"rel": "item", "href": "./BR34_5000_0304.json", "type": "application/json"} in collection.stac["links"]
assert collection.stac["extent"]["temporal"]["interval"] == [[start_datetime, end_datetime]]
assert collection.stac["extent"]["spatial"]["bbox"] == [bbox]


def test_write_collection(setup_collection: ImageryCollection) -> None:
target = mkdtemp()
collection_target = os.path.join(target, "collection.json")
setup_collection.write_to(collection_target)
collection = json.loads(read(collection_target))
rmtree(target)

assert collection["title"] == setup_collection.stac["title"]


def test_write_collection_special_chars(setup_collection: ImageryCollection) -> None:
target = mkdtemp()
title = "Manawatū-Whanganui"
setup_collection.stac["title"] = title
collection_target = os.path.join(target, "collection.json")
setup_collection.write_to(collection_target)
collection = json.loads(read(collection_target))
rmtree(target)

assert collection["title"] == title