Skip to content

Commit

Permalink
use singular for enums (#258)
Browse files Browse the repository at this point in the history
* use singular for enums

* Update CHANGES.md

Co-authored-by: Kyle Barron <kylebarron2@gmail.com>

* s/Mime/Media/g

Co-authored-by: Kyle Barron <kylebarron2@gmail.com>
  • Loading branch information
vincentsarago and kylebarron authored Mar 5, 2021
1 parent 54d2b20 commit 989d1b4
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 42 deletions.
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
* update FastAPI requirements
* update minimal python version to 3.6

**breaking change**

* renamed `OptionalHeaders`, `MimeTypes` and `ImageDrivers` enums to the singular form. (https://github.com/developmentseed/titiler/pull/258)
* renamed `MimeType` to `MediaType` (https://github.com/developmentseed/titiler/pull/258)

## 0.1.0 (2021-02-17)

* update FastAPI requirements
Expand Down
8 changes: 4 additions & 4 deletions tests/test_enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


@pytest.mark.parametrize(
"value,driver,mimetype",
"value,driver,mediatype",
[
("png", "PNG", "image/png"),
("npy", "NPY", "application/x-binary"),
Expand All @@ -18,10 +18,10 @@
("pngraw", "PNG", "image/png"),
],
)
def test_imagetype(value, driver, mimetype):
"""Test driver and mimetype values."""
def test_imagetype(value, driver, mediatype):
"""Test driver and mediatype values."""
assert ImageType[value].driver == driver
assert ImageType[value].mimetype == mimetype
assert ImageType[value].mediatype == mediatype


def test_imageprofile():
Expand Down
6 changes: 3 additions & 3 deletions tests/test_factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

from titiler.dependencies import TMSParams, WebMercatorTMSParams
from titiler.endpoints import factory
from titiler.resources.enums import OptionalHeaders
from titiler.resources.enums import OptionalHeader

from .conftest import DATA_DIR

Expand All @@ -30,7 +30,7 @@ def test_TilerFactory():
assert len(cog.router.routes) == 17

app = FastAPI()
cog = factory.TilerFactory(optional_headers=[OptionalHeaders.server_timing])
cog = factory.TilerFactory(optional_headers=[OptionalHeader.server_timing])
app.include_router(cog.router)
client = TestClient(app)

Expand Down Expand Up @@ -87,7 +87,7 @@ def tmpmosaic():
def test_MosaicTilerFactory():
"""Test MosaicTilerFactory class."""
mosaic = factory.MosaicTilerFactory(
optional_headers=[OptionalHeaders.server_timing, OptionalHeaders.x_assets],
optional_headers=[OptionalHeader.server_timing, OptionalHeader.x_assets],
router_prefix="mosaic",
)
assert len(mosaic.router.routes) == 19
Expand Down
39 changes: 17 additions & 22 deletions titiler/endpoints/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,7 @@
)
from ..models.mapbox import TileJSON
from ..models.OGC import TileMatrixSetList
from ..resources.enums import (
ImageType,
MimeTypes,
OptionalHeaders,
PixelSelectionMethod,
)
from ..resources.enums import ImageType, MediaType, OptionalHeader, PixelSelectionMethod
from ..resources.responses import GeoJSONResponse, XMLResponse
from ..templates import templates

Expand Down Expand Up @@ -106,7 +101,7 @@ class BaseTilerFactory(metaclass=abc.ABCMeta):
gdal_config: Dict = field(default_factory=dict)

# add additional headers in response
optional_headers: List[OptionalHeaders] = field(default_factory=list)
optional_headers: List[OptionalHeader] = field(default_factory=list)

def __post_init__(self):
"""Post Init: register route and configure specific options."""
Expand Down Expand Up @@ -349,12 +344,12 @@ def tile(
)
timings.append(("format", round(t.elapsed * 1000, 2)))

if OptionalHeaders.server_timing in self.optional_headers:
if OptionalHeader.server_timing in self.optional_headers:
headers["Server-Timing"] = ", ".join(
[f"{name};dur={time}" for (name, time) in timings]
)

return Response(content, media_type=format.mimetype, headers=headers)
return Response(content, media_type=format.mediatype, headers=headers)

def tilejson(self): # noqa: C901
"""Register /tilejson.json endpoint."""
Expand Down Expand Up @@ -514,9 +509,9 @@ def wmts(
"tms": tms,
"title": "Cloud Optimized GeoTIFF",
"layer_name": "cogeo",
"media_type": tile_format.mimetype,
"media_type": tile_format.mediatype,
},
media_type=MimeTypes.xml.value,
media_type=MediaType.xml.value,
)

############################################################################
Expand Down Expand Up @@ -553,7 +548,7 @@ def point(
)
timings.append(("dataread", round(t.elapsed * 1000, 2)))

if OptionalHeaders.server_timing in self.optional_headers:
if OptionalHeader.server_timing in self.optional_headers:
response.headers["Server-Timing"] = ", ".join(
[f"{name};dur={time}" for (name, time) in timings]
)
Expand Down Expand Up @@ -616,12 +611,12 @@ def preview(
)
timings.append(("format", round(t.elapsed * 1000, 2)))

if OptionalHeaders.server_timing in self.optional_headers:
if OptionalHeader.server_timing in self.optional_headers:
headers["Server-Timing"] = ", ".join(
[f"{name};dur={time}" for (name, time) in timings]
)

return Response(content, media_type=format.mimetype, headers=headers)
return Response(content, media_type=format.mediatype, headers=headers)

############################################################################
# /crop (Optional)
Expand Down Expand Up @@ -684,12 +679,12 @@ def part(
)
timings.append(("format", round(t.elapsed * 1000, 2)))

if OptionalHeaders.server_timing in self.optional_headers:
if OptionalHeader.server_timing in self.optional_headers:
headers["Server-Timing"] = ", ".join(
[f"{name};dur={time}" for (name, time) in timings]
)

return Response(content, media_type=format.mimetype, headers=headers)
return Response(content, media_type=format.mediatype, headers=headers)


@dataclass
Expand Down Expand Up @@ -1140,15 +1135,15 @@ def tile(
)
timings.append(("format", round(t.elapsed * 1000, 2)))

if OptionalHeaders.server_timing in self.optional_headers:
if OptionalHeader.server_timing in self.optional_headers:
headers["Server-Timing"] = ", ".join(
[f"{name};dur={time}" for (name, time) in timings]
)

if OptionalHeaders.x_assets in self.optional_headers:
if OptionalHeader.x_assets in self.optional_headers:
headers["X-Assets"] = ",".join(data.assets)

return Response(content, media_type=format.mimetype, headers=headers)
return Response(content, media_type=format.mediatype, headers=headers)

def tilejson(self): # noqa: C901
"""Add tilejson endpoint."""
Expand Down Expand Up @@ -1306,9 +1301,9 @@ def wmts(
"tms": tms,
"title": "Cloud Optimized GeoTIFF",
"layer_name": "cogeo",
"media_type": tile_format.mimetype,
"media_type": tile_format.mediatype,
},
media_type=MimeTypes.xml.value,
media_type=MediaType.xml.value,
)

############################################################################
Expand Down Expand Up @@ -1354,7 +1349,7 @@ def point(
)
timings.append(("dataread", round((t.elapsed - mosaic_read) * 1000, 2)))

if OptionalHeaders.server_timing in self.optional_headers:
if OptionalHeader.server_timing in self.optional_headers:
response.headers["Server-Timing"] = ", ".join(
[f"{name};dur={time}" for (name, time) in timings]
)
Expand Down
4 changes: 2 additions & 2 deletions titiler/models/OGC.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from pydantic import AnyHttpUrl, BaseModel

from ..resources.enums import MimeTypes
from ..resources.enums import MediaType


class TileMatrixSetLink(BaseModel):
Expand All @@ -18,7 +18,7 @@ class TileMatrixSetLink(BaseModel):

href: AnyHttpUrl
rel: str = "item"
type: MimeTypes = MimeTypes.json
type: MediaType = MediaType.json

class Config:
"""Config for model."""
Expand Down
22 changes: 11 additions & 11 deletions titiler/resources/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from rio_tiler.profiles import img_profiles


class MimeTypes(str, Enum):
"""Responses MineTypes."""
class MediaType(str, Enum):
"""Responses Media types formerly known as MIME types."""

tif = "image/tiff; application=geotiff"
jp2 = "image/jp2"
Expand All @@ -24,8 +24,8 @@ class MimeTypes(str, Enum):
text = "text/plain"


class ImageDrivers(str, Enum):
"""Rio-tiler supported output drivers."""
class ImageDriver(str, Enum):
"""Supported output GDAL drivers."""

jpeg = "JPEG"
png = "PNG"
Expand Down Expand Up @@ -55,16 +55,16 @@ def profile(self):
@DynamicClassAttribute
def driver(self):
"""Return rio-tiler image default profile."""
return ImageDrivers[self._name_].value
return ImageDriver[self._name_].value

@DynamicClassAttribute
def mimetype(self):
"""Return image mimetype."""
return MimeTypes[self._name_].value
def mediatype(self):
"""Return image media type."""
return MediaType[self._name_].value


class PixelSelectionMethod(str, Enum):
"""rio-tiler-mosaic pixel selection methods"""
"""rio-tiler.mosaic pixel selection methods"""

first = "first"
highest = "highest"
Expand All @@ -79,8 +79,8 @@ def method(self):
return getattr(defaults, f"{self._value_.title()}Method")


class OptionalHeaders(str, Enum):
"""Optional Headers in responses."""
class OptionalHeader(str, Enum):
"""Optional Header to add in responses."""

server_timing = "Server-Timing"
x_assets = "X-Assets"

0 comments on commit 989d1b4

Please sign in to comment.