Skip to content

Commit

Permalink
fix typing errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dionhaefner committed Aug 10, 2023
1 parent 75435db commit bbeb12a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion terracotta/scripts/click_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class PathlibPath(click.Path):
"""Converts a string to a pathlib.Path object"""

def convert(self, *args: Any) -> pathlib.Path:
return pathlib.Path(super().convert(*args))
return pathlib.Path(str(super().convert(*args)))


RasterPatternType = Tuple[List[str], Dict[Tuple[str, ...], str]]
Expand Down
28 changes: 17 additions & 11 deletions terracotta/server/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from flask import jsonify, Response, request

from terracotta.server.flask_api import METADATA_API
from terracotta.exceptions import InvalidArgumentsError


class MetadataSchema(Schema):
Expand Down Expand Up @@ -63,17 +64,17 @@ class MetadataColumnsSchema(Schema):
@pre_load
def validate_columns(
self, data: Mapping[str, Any], **kwargs: Any
) -> Dict[str, Any] | Mapping[str, Any]:
columns = data.get("columns")

if columns:
data = dict(data.items())

) -> Dict[str, Any]:
data = dict(data.items())
var = "columns"
val = data.get(var)
if val:
try:
data["columns"] = json.loads(columns)
data[var] = json.loads(val)
except json.decoder.JSONDecodeError as exc:
raise ValidationError("columns must be a JSON list") from exc

raise ValidationError(

Check warning on line 75 in terracotta/server/metadata.py

View check run for this annotation

Codecov / codecov/patch

terracotta/server/metadata.py#L72-L75

Added lines #L72 - L75 were not covered by tests
f"Could not decode value for {var} as JSON"
) from exc
return data


Expand Down Expand Up @@ -147,11 +148,16 @@ def get_multiple_metadata() -> Response:
"""
from terracotta.handlers.metadata import multiple_metadata

Check warning on line 149 in terracotta/server/metadata.py

View check run for this annotation

Codecov / codecov/patch

terracotta/server/metadata.py#L149

Added line #L149 was not covered by tests

request_body = request.json

Check warning on line 151 in terracotta/server/metadata.py

View check run for this annotation

Codecov / codecov/patch

terracotta/server/metadata.py#L151

Added line #L151 was not covered by tests
if not isinstance(request_body, dict):
raise InvalidArgumentsError("Request body must be a JSON object")

Check warning on line 153 in terracotta/server/metadata.py

View check run for this annotation

Codecov / codecov/patch

terracotta/server/metadata.py#L153

Added line #L153 was not covered by tests

datasets_schema = MultipleMetadataDatasetsSchema()
datasets = datasets_schema.load(request.json or {}).get("keys")
datasets = datasets_schema.load(request_body).get("keys")

Check warning on line 156 in terracotta/server/metadata.py

View check run for this annotation

Codecov / codecov/patch

terracotta/server/metadata.py#L155-L156

Added lines #L155 - L156 were not covered by tests

columns_schema = MetadataColumnsSchema()
columns = columns_schema.load(request.args).get("columns")

Check warning on line 159 in terracotta/server/metadata.py

View check run for this annotation

Codecov / codecov/patch

terracotta/server/metadata.py#L158-L159

Added lines #L158 - L159 were not covered by tests

payload = multiple_metadata(columns, datasets)
schema = MetadataSchema(many=True, partial=columns is not None)

Check warning on line 162 in terracotta/server/metadata.py

View check run for this annotation

Codecov / codecov/patch

terracotta/server/metadata.py#L161-L162

Added lines #L161 - L162 were not covered by tests
return jsonify(schema.load(multiple_metadata(columns, datasets)))
return jsonify(schema.load(payload))

0 comments on commit bbeb12a

Please sign in to comment.