Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Jul 7, 2021
1 parent 74c6868 commit d13108e
Show file tree
Hide file tree
Showing 15 changed files with 58 additions and 125 deletions.
2 changes: 1 addition & 1 deletion stac_fastapi/api/stac_fastapi/api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
from fastapi import APIRouter, FastAPI
from fastapi.openapi.utils import get_openapi
from stac_pydantic import Collection, Item, ItemCollection
from stac_pydantic.api.collections import Collections
from stac_pydantic.api import ConformanceClasses, LandingPage
from stac_pydantic.api.collections import Collections
from stac_pydantic.version import STAC_VERSION

from stac_fastapi.api.errors import DEFAULT_STATUS_CODES, add_exception_handlers
Expand Down
6 changes: 2 additions & 4 deletions stac_fastapi/api/stac_fastapi/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ def _endpoint(
else:

def _endpoint(
request: Request,
request_data: request_model, # type:ignore
request: Request, request_data: request_model, # type:ignore
):
"""Endpoint."""
resp = func(request_data, request=request)
Expand All @@ -73,8 +72,7 @@ async def _endpoint(
else:

async def _endpoint(
request: Request,
request_data: request_model, # type:ignore
request: Request, request_data: request_model, # type:ignore
):
"""Endpoint."""
resp = await func(request_data, request=request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from fastapi import FastAPI
from pydantic import BaseModel
from stac_pydantic.collection import SpatialExtent
from stac_pydantic.shared import MimeTypes
from stac_pydantic.links import Link, Relations
from stac_pydantic.shared import MimeTypes
from starlette.requests import Request
from starlette.responses import HTMLResponse, RedirectResponse

Expand Down Expand Up @@ -45,8 +45,7 @@ class TileLinks:
def __attrs_post_init__(self):
"""Post init handler."""
self.item_uri = urljoin(
self.base_url,
f"collections/{self.collection_id}/items/{self.item_id}",
self.base_url, f"collections/{self.collection_id}/items/{self.item_id}",
)

def tiles(self) -> OGCTileLink:
Expand All @@ -66,8 +65,7 @@ def viewer(self) -> OGCTileLink:
"""Create viewer link."""
return OGCTileLink(
href=urljoin(
self.base_url,
f"{self.route_prefix}/viewer?url={self.item_uri}",
self.base_url, f"{self.route_prefix}/viewer?url={self.item_uri}",
),
rel=Relations.alternate,
type=MimeTypes.html,
Expand All @@ -78,8 +76,7 @@ def tilejson(self) -> OGCTileLink:
"""Create tilejson link."""
return OGCTileLink(
href=urljoin(
self.base_url,
f"{self.route_prefix}/tilejson.json?url={self.item_uri}",
self.base_url, f"{self.route_prefix}/tilejson.json?url={self.item_uri}",
),
rel=Relations.alternate,
type=MimeTypes.json,
Expand Down
36 changes: 21 additions & 15 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@
from fastapi.responses import ORJSONResponse
from stac_pydantic import Collection, Item, ItemCollection
from stac_pydantic.api import ConformanceClasses, LandingPage
from stac_pydantic.shared import MimeTypes
from stac_pydantic.api.collections import Collections
from stac_pydantic.links import Link, Relations
from stac_pydantic.shared import MimeTypes

from stac_fastapi.pgstac.models.links import CollectionLinks, ItemLinks, PagingLinks
from stac_fastapi.pgstac.types.search import PgstacSearch
Expand Down Expand Up @@ -39,11 +40,7 @@ async def landing_page(self, **kwargs) -> ORJSONResponse:
title="Arturo STAC API",
description="Arturo raster datastore",
links=[
Link(
rel=Relations.self,
type=MimeTypes.json,
href=str(base_url),
),
Link(rel=Relations.self, type=MimeTypes.json, href=str(base_url),),
Link(
rel=Relations.docs,
type=MimeTypes.html,
Expand Down Expand Up @@ -112,10 +109,23 @@ async def _all_collections_func(self, **kwargs) -> List[Collection]:

async def all_collections(self, **kwargs) -> ORJSONResponse:
"""Get all collections."""
request = kwargs["request"]
base_url = str(request.base_url)
url = str(request.url)
collections = await self._all_collections_func(**kwargs)
if collections is None or len(collections) < 1:
return ORJSONResponse([])
return ORJSONResponse([c.dict(exclude_none=True) for c in collections])
links = [
Link(rel=Relations.self, type=MimeTypes.json, href=url),
Link(rel=Relations.parent, type=MimeTypes.json, href=base_url),
Link(rel=Relations.root, type=MimeTypes.json, href=base_url),
]
if collections is None:
return ORJSONResponse(Collections(collections=[], links=links))
return ORJSONResponse(
Collections(
collections=[c.dict(exclude_none=True) for c in collections],
links=links,
)
)

async def get_collection(self, id: str, **kwargs) -> ORJSONResponse:
"""Get collection by id.
Expand Down Expand Up @@ -195,15 +205,11 @@ async def _search_base(
include = search_request.fields.include
if len(include) == 0:
include = None
feature = feature.dict(
exclude_none=True,
)
feature = feature.dict(exclude_none=True,)
cleaned_features.append(feature)
collection.features = cleaned_features
collection.links = await PagingLinks(
request=request,
next=next,
prev=prev,
request=request, next=next, prev=prev,
).get_links()
return collection

Expand Down
10 changes: 2 additions & 8 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,10 @@
async def con_init(conn):
"""Use orjson for json returns."""
await conn.set_type_codec(
"json",
encoder=orjson.dumps,
decoder=orjson.loads,
schema="pg_catalog",
"json", encoder=orjson.dumps, decoder=orjson.loads, schema="pg_catalog",
)
await conn.set_type_codec(
"jsonb",
encoder=orjson.dumps,
decoder=orjson.loads,
schema="pg_catalog",
"jsonb", encoder=orjson.dumps, decoder=orjson.loads, schema="pg_catalog",
)


Expand Down
19 changes: 5 additions & 14 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/models/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@

import attr
from stac_pydantic.api.extensions.paging import PaginationLink
from stac_pydantic.shared import MimeTypes
from stac_pydantic.links import Link, Relations
from stac_pydantic.shared import MimeTypes
from starlette.requests import Request

from stac_fastapi.extensions.third_party.tiles import OGCTileLink
Expand Down Expand Up @@ -113,10 +113,7 @@ def link_next(self) -> PaginationLink:
if method == "GET":
href = merge_params(self.url, {"token": f"next:{self.next}"})
link = PaginationLink(
rel=Relations.next,
type=MimeTypes.json,
method=method,
href=href,
rel=Relations.next, type=MimeTypes.json, method=method, href=href,
)
return link
if method == "POST":
Expand Down Expand Up @@ -179,11 +176,7 @@ def link_self(self) -> Link:

def link_parent(self) -> Link:
"""Create the `parent` link."""
return Link(
rel=Relations.parent,
type=MimeTypes.json,
href=self.base_url,
)
return Link(rel=Relations.parent, type=MimeTypes.json, href=self.base_url,)

def link_items(self) -> Link:
"""Create the `item` link."""
Expand Down Expand Up @@ -241,8 +234,7 @@ class TileLinks:
def __post_init__(self):
"""Post init handler."""
self.item_uri = urljoin(
self.base_url,
f"/collections/{self.collection_id}/items/{self.item_id}",
self.base_url, f"/collections/{self.collection_id}/items/{self.item_id}",
)

def link_tiles(self) -> OGCTileLink:
Expand Down Expand Up @@ -280,8 +272,7 @@ def link_wmts(self) -> OGCTileLink:
"""Create wmts capabilities link."""
return OGCTileLink(
href=urljoin(
self.base_url,
f"/titiler/WMTSCapabilities.xml?url={self.item_uri}",
self.base_url, f"/titiler/WMTSCapabilities.xml?url={self.item_uri}",
),
rel=Relations.alternate,
type=MimeTypes.xml,
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/pgstac/stac_fastapi/pgstac/models/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
from pydantic import BaseModel
from stac_pydantic import Collection as CollectionBase
from stac_pydantic import Item as ItemBase
from stac_pydantic.shared import DATETIME_RFC339
from stac_pydantic.links import Link
from stac_pydantic.shared import DATETIME_RFC339

# Be careful: https://github.com/samuelcolvin/pydantic/issues/1423#issuecomment-642797287
NumType = Union[float, int]
Expand Down
19 changes: 4 additions & 15 deletions stac_fastapi/pgstac/tests/clients/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@
async def test_create_collection(app_client, load_test_data: Callable):
in_json = load_test_data("test_collection.json")
in_coll = Collection.parse_obj(in_json)
resp = await app_client.post(
"/collections",
json=in_json,
)
resp = await app_client.post("/collections", json=in_json,)
assert resp.status_code == 200
post_coll = Collection.parse_obj(resp.json())
assert in_coll.dict(exclude={"links"}) == post_coll.dict(exclude={"links"})
Expand Down Expand Up @@ -57,10 +54,7 @@ async def test_create_item(app_client, load_test_data: Callable, load_test_colle

in_json = load_test_data("test_item.json")
in_item = Item.parse_obj(in_json)
resp = await app_client.post(
"/collections/{coll.id}/items",
json=in_json,
)
resp = await app_client.post("/collections/{coll.id}/items", json=in_json,)
assert resp.status_code == 200

post_item = Item.parse_obj(resp.json())
Expand Down Expand Up @@ -111,15 +105,10 @@ async def test_get_collection_items(app_client, load_test_collection, load_test_

for _ in range(4):
item.id = str(uuid.uuid4())
resp = await app_client.post(
f"/collections/{coll.id}/items",
json=item.dict(),
)
resp = await app_client.post(f"/collections/{coll.id}/items", json=item.dict(),)
assert resp.status_code == 200

resp = await app_client.get(
f"/collections/{coll.id}/items",
)
resp = await app_client.get(f"/collections/{coll.id}/items",)
assert resp.status_code == 200
fc = resp.json()
assert "features" in fc
Expand Down
10 changes: 2 additions & 8 deletions stac_fastapi/pgstac/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,20 +127,14 @@ def load_file(filename: str) -> Dict:
@pytest.fixture
async def load_test_collection(app_client, load_test_data):
data = load_test_data("test_collection.json")
resp = await app_client.post(
"/collections",
json=data,
)
resp = await app_client.post("/collections", json=data,)
assert resp.status_code == 200
return Collection.parse_obj(resp.json())


@pytest.fixture
async def load_test_item(app_client, load_test_data, load_test_collection):
data = load_test_data("test_item.json")
resp = await app_client.post(
"/collections/{coll.id}/items",
json=data,
)
resp = await app_client.post("/collections/{coll.id}/items", json=data,)
assert resp.status_code == 200
return Item.parse_obj(resp.json())
23 changes: 5 additions & 18 deletions stac_fastapi/pgstac/tests/resources/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
async def test_create_collection(app_client, load_test_data: Callable):
in_json = load_test_data("test_collection.json")
in_coll = Collection.parse_obj(in_json)
resp = await app_client.post(
"/collections",
json=in_json,
)
resp = await app_client.post("/collections", json=in_json,)
assert resp.status_code == 200
post_coll = Collection.parse_obj(resp.json())
assert in_coll.dict(exclude={"links"}) == post_coll.dict(exclude={"links"})
Expand Down Expand Up @@ -54,23 +51,15 @@ async def test_delete_collection(
async def test_create_collection_conflict(app_client, load_test_data: Callable):
in_json = load_test_data("test_collection.json")
Collection.parse_obj(in_json)
resp = await app_client.post(
"/collections",
json=in_json,
)
resp = await app_client.post("/collections", json=in_json,)
assert resp.status_code == 200
Collection.parse_obj(resp.json())
resp = await app_client.post(
"/collections",
json=in_json,
)
resp = await app_client.post("/collections", json=in_json,)
assert resp.status_code == 409


@pytest.mark.asyncio
async def test_delete_missing_collection(
app_client,
):
async def test_delete_missing_collection(app_client,):
resp = await app_client.delete("/collections")
assert resp.status_code == 405

Expand All @@ -85,8 +74,6 @@ async def test_update_new_collection(app_client, load_test_collection):


@pytest.mark.asyncio
async def test_nocollections(
app_client,
):
async def test_nocollections(app_client,):
resp = await app_client.get("/collections")
assert resp.status_code == 200
29 changes: 6 additions & 23 deletions stac_fastapi/pgstac/tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
async def test_create_collection(app_client, load_test_data: Callable):
in_json = load_test_data("test_collection.json")
in_coll = Collection.parse_obj(in_json)
resp = await app_client.post(
"/collections",
json=in_json,
)
resp = await app_client.post("/collections", json=in_json,)
assert resp.status_code == 200
post_coll = Collection.parse_obj(resp.json())
assert in_coll.dict(exclude={"links"}) == post_coll.dict(exclude={"links"})
Expand Down Expand Up @@ -62,10 +59,7 @@ async def test_create_item(app_client, load_test_data: Callable, load_test_colle

in_json = load_test_data("test_item.json")
in_item = Item.parse_obj(in_json)
resp = await app_client.post(
"/collections/{coll.id}/items",
json=in_json,
)
resp = await app_client.post("/collections/{coll.id}/items", json=in_json,)
assert resp.status_code == 200

post_item = Item.parse_obj(resp.json())
Expand Down Expand Up @@ -120,15 +114,10 @@ async def test_get_collection_items(app_client, load_test_collection, load_test_

for _ in range(4):
item.id = str(uuid.uuid4())
resp = await app_client.post(
f"/collections/{coll.id}/items",
json=item.dict(),
)
resp = await app_client.post(f"/collections/{coll.id}/items", json=item.dict(),)
assert resp.status_code == 200

resp = await app_client.get(
f"/collections/{coll.id}/items",
)
resp = await app_client.get(f"/collections/{coll.id}/items",)
assert resp.status_code == 200
fc = resp.json()
assert "features" in fc
Expand All @@ -143,16 +132,10 @@ async def test_create_item_conflict(

in_json = load_test_data("test_item.json")
Item.parse_obj(in_json)
resp = await app_client.post(
"/collections/{coll.id}/items",
json=in_json,
)
resp = await app_client.post("/collections/{coll.id}/items", json=in_json,)
assert resp.status_code == 200

resp = await app_client.post(
"/collections/{coll.id}/items",
json=in_json,
)
resp = await app_client.post("/collections/{coll.id}/items", json=in_json,)
assert resp.status_code == 409


Expand Down
Loading

0 comments on commit d13108e

Please sign in to comment.