Skip to content

Commit

Permalink
Use black 21
Browse files Browse the repository at this point in the history
  • Loading branch information
moradology committed Jul 7, 2021
1 parent 85fce67 commit 29108d8
Show file tree
Hide file tree
Showing 20 changed files with 153 additions and 42 deletions.
8 changes: 7 additions & 1 deletion stac_fastapi/api/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
]

extra_reqs = {
"dev": ["pytest", "pytest-cov", "pytest-asyncio", "pre-commit", "requests",],
"dev": [
"pytest",
"pytest-cov",
"pytest-asyncio",
"pre-commit",
"requests",
],
"docs": ["mkdocs", "mkdocs-material", "pdocs"],
}

Expand Down
3 changes: 2 additions & 1 deletion stac_fastapi/api/stac_fastapi/api/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ def request_validation_exception_handler(
request: Request, exc: RequestValidationError
) -> JSONResponse:
return JSONResponse(
status_code=status.HTTP_400_BAD_REQUEST, content={"detail": exc.errors()},
status_code=status.HTTP_400_BAD_REQUEST,
content={"detail": exc.errors()},
)

app.add_exception_handler(
Expand Down
6 changes: 4 additions & 2 deletions stac_fastapi/api/stac_fastapi/api/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ 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 @@ -72,7 +73,8 @@ 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
8 changes: 7 additions & 1 deletion stac_fastapi/extensions/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,13 @@
]

extra_reqs = {
"dev": ["pytest", "pytest-cov", "pytest-asyncio", "pre-commit", "requests",],
"dev": [
"pytest",
"pytest-cov",
"pytest-asyncio",
"pre-commit",
"requests",
],
"docs": ["mkdocs", "mkdocs-material", "pdocs"],
"tiles": ["titiler==0.2.*"],
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ 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 @@ -65,7 +66,8 @@ 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 @@ -76,7 +78,8 @@ 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
14 changes: 11 additions & 3 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,11 @@ 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 @@ -205,11 +209,15 @@ 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: 8 additions & 2 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/db.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,16 @@
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
17 changes: 13 additions & 4 deletions stac_fastapi/pgstac/stac_fastapi/pgstac/models/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,10 @@ 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 @@ -176,7 +179,11 @@ 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 @@ -234,7 +241,8 @@ 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 @@ -272,7 +280,8 @@ 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
19 changes: 15 additions & 4 deletions stac_fastapi/pgstac/tests/clients/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,10 @@
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,7 +57,10 @@ 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 @@ -105,10 +111,15 @@ 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: 8 additions & 2 deletions stac_fastapi/pgstac/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,14 +127,20 @@ 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: 18 additions & 5 deletions stac_fastapi/pgstac/tests/resources/test_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
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 @@ -51,15 +54,23 @@ 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 @@ -74,6 +85,8 @@ 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: 23 additions & 6 deletions stac_fastapi/pgstac/tests/resources/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@
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 @@ -59,7 +62,10 @@ 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 @@ -114,10 +120,15 @@ 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 @@ -132,10 +143,16 @@ 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
4 changes: 3 additions & 1 deletion stac_fastapi/sqlalchemy/alembic/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ def run_migrations_online():
configuration = config.get_section(config.config_ini_section)
configuration["sqlalchemy.url"] = get_connection_url()
connectable = engine_from_config(
configuration, prefix="sqlalchemy.", poolclass=pool.NullPool,
configuration,
prefix="sqlalchemy.",
poolclass=pool.NullPool,
)

with connectable.connect() as connection:
Expand Down
8 changes: 7 additions & 1 deletion stac_fastapi/sqlalchemy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,13 @@
]

extra_reqs = {
"dev": ["pytest", "pytest-cov", "pytest-asyncio", "pre-commit", "requests",],
"dev": [
"pytest",
"pytest-cov",
"pytest-asyncio",
"pre-commit",
"requests",
],
"docs": ["mkdocs", "mkdocs-material", "pdocs"],
"server": ["uvicorn[standard]>=0.12.0,<0.14.0"],
}
Expand Down
3 changes: 2 additions & 1 deletion stac_fastapi/sqlalchemy/stac_fastapi/sqlalchemy/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,8 @@ def post_search(
if search_request.sortby:
sort_fields = [
getattr(
self.item_table.get_field(sort.field), sort.direction.value,
self.item_table.get_field(sort.field),
sort.direction.value,
)()
for sort in search_request.sortby
]
Expand Down
Loading

0 comments on commit 29108d8

Please sign in to comment.