Skip to content

Commit

Permalink
add test fixtures and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
hrodmn committed Nov 22, 2023
1 parent 188e54d commit d2993da
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
52 changes: 52 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,8 @@ async def lifespan(app: FastAPI):
exclude_functions=db_settings.exclude_functions,
exclude_function_schemas=db_settings.exclude_function_schemas,
spatial=db_settings.only_spatial_tables,
spatial_extent=db_settings.spatial_extent,
datetime_extent=db_settings.datetime_extent,
)
yield
await close_db_connection(app)
Expand Down Expand Up @@ -333,6 +335,56 @@ def app_myschema_public(database_url, monkeypatch):
yield client


@pytest.fixture
def app_no_extents(database_url, monkeypatch):
"""Create APP with tables from `myschema` and `public` schema but without
calculating the spatial/datetime extents.
Available tables should come from `myschema` and `public` and functions from `pg_temp`.
"""
postgres_settings = PostgresSettings(database_url=database_url)
db_settings = DatabaseSettings(
schemas=["myschema", "public"],
spatial_extent=False,
datetime_extent=False,
)
sql_settings = CustomSQLSettings(custom_sql_directory=SQL_FUNCTIONS_DIRECTORY)

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_no_spatial_extent(database_url, monkeypatch):
"""Create APP with tables from `myschema` and `public` schema but without
calculating the spatial/datetime extents.
Available tables should come from `myschema` and `public` and functions from `pg_temp`.
"""
postgres_settings = PostgresSettings(database_url=database_url)
db_settings = DatabaseSettings(
schemas=["myschema", "public"],
spatial_extent=False,
datetime_extent=True,
)
sql_settings = CustomSQLSettings(custom_sql_directory=SQL_FUNCTIONS_DIRECTORY)

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_myschema_public_functions(database_url, monkeypatch):
"""Create APP with only tables from `myschema` schema and functions from `public` schema.
Expand Down
33 changes: 33 additions & 0 deletions tests/routes/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,36 @@ def test_collections_empty(app_empty):
assert response.status_code == 200
body = response.json()
assert not body["collections"]


def test_collections_no_extents(app_no_extents):
"""Test /collections endpoint."""
response = app_no_extents.get("/collections/public.landsat_wrs")
assert response.status_code == 200
body = response.json()
assert body["crs"] == ["http://www.opengis.net/def/crs/OGC/1.3/CRS84"]
assert body["extent"].get("spatial").get("bbox") == [
[
-180,
-90,
180,
90,
]
] # default value
assert not body["extent"].get("temporal")


def test_collections_no_spatial_extent(app_no_spatial_extent):
"""Test /collections endpoint."""
response = app_no_spatial_extent.get("/collections/public.canada")
assert response.status_code == 200
body = response.json()
assert body["crs"] == ["http://www.opengis.net/def/crs/OGC/1.3/CRS84"]
assert body["extent"].get("spatial").get("bbox") == [
[
-180,
-90,
180,
90,
]
]

0 comments on commit d2993da

Please sign in to comment.