diff --git a/tests/conftest.py b/tests/conftest.py index 1c74129c..0d127a11 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) @@ -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. diff --git a/tests/routes/test_collections.py b/tests/routes/test_collections.py index 4d631c67..0aedf49c 100644 --- a/tests/routes/test_collections.py +++ b/tests/routes/test_collections.py @@ -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, + ] + ]