Skip to content

fix function based collections without params #96

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

Merged
merged 4 commits into from
Jul 25, 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
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Note: Minor version `0.X.0` update might break the API, It's recommended to pin
- added `python-dotenv` dependency via `pydantic[dotenv]`
- `type` query parameter to filter collections based on their type (`Function` or `Table`)
- fixed a small bug in the `tipg_properties` SQL function where the bounds property was not properly transformed to 4326 (author @RemcoMeeuwissen, https://github.com/developmentseed/tipg/pull/87)
- handling functions that are interpreted as collections but lack parameters (author @jackharrhy, https://github.com/developmentseed/tipg/pull/96)

### Added

Expand Down
29 changes: 29 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ def database_url(test_db):
).scalar()
assert count_landsat == count_landsat_schema

# add a `userschema` schema
test_db.create_schema("userschema")
assert test_db.has_schema("userschema")

test_db.connection.execute(
"CREATE OR REPLACE FUNCTION userschema.test_no_params() RETURNS TABLE(foo integer, location geometry) AS 'SELECT 1, ST_MakePoint(0,0);' LANGUAGE SQL;"
)

return str(test_db.connection.engine.url)


Expand Down Expand Up @@ -334,6 +342,27 @@ def app_myschema_public_order(database_url, monkeypatch):
yield client


@pytest.fixture
def app_user_schema(database_url):
"""Create APP with only tables from `userschema` schemas."""
postgres_settings = PostgresSettings(database_url=database_url)
db_settings = DatabaseSettings(
schemas=["userschema"],
exclude_table_schemas=["public"],
only_spatial_tables=False,
)
sql_settings = CustomSQLSettings(custom_sql_directory=None)

app = create_tipg_app(
postgres_settings=postgres_settings,
db_settings=db_settings,
sql_settings=sql_settings,
)

with TestClient(app) as client:
yield client


@pytest.fixture
def app_middleware_refresh(database_url, monkeypatch):
"""Create APP with CatalogUpdateMiddleware middleware."""
Expand Down
21 changes: 21 additions & 0 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,3 +147,24 @@ def test_myschema_and_public_order(app_myschema_public_order):
assert "public.st_hexagongrid" not in ids

assert body["numberMatched"] == collection_number


def test_user_schema(app_user_schema):
"""Test Function without parameters."""
collection_number = 1

response = app_user_schema.get("/collections")
assert response.status_code == 200
body = response.json()
ids = [x["id"] for x in body["collections"]]

assert len(ids) == collection_number
assert "userschema.test_no_params" in ids

response = app_user_schema.get("/collections/userschema.test_no_params/queryables")
assert response.status_code == 200

response = app_user_schema.get("/collections/userschema.test_no_params/items")
assert response.status_code == 200
body = response.json()
assert body["numberMatched"] == 1
2 changes: 1 addition & 1 deletion tipg/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -980,7 +980,7 @@ async def get_collection_index( # noqa: C901
properties=properties,
datetime_column=datetime_column,
geometry_column=geometry_column,
parameters=table.get("parameters", []),
parameters=table.get("parameters") or [],
)

return Catalog(collections=catalog, last_updated=datetime.datetime.now())
Expand Down