Skip to content
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
5 changes: 5 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

### Changed

- remove pygstac dependency
- refactor tests fixtures to test multiple version of PgSTAC

## [6.1.1] - 2025-11-20

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ dependencies = [
"buildpg",
"brotli_asgi",
"cql2>=0.3.6",
"pypgstac>=0.9,<0.10",
"hydraters>=0.1.3",
"typing_extensions>=4.9.0",
"jsonpatch>=1.33.0",
Expand All @@ -69,11 +68,12 @@ dev = [
"pytest",
"pytest-cov",
"pytest-asyncio>=0.17,<1.3",
"pre-commit",
"pypgstac>=0.9,<0.10",
"requests",
"shapely",
"httpx",
"psycopg[pool,binary]==3.2.*",
"pre-commit",
"bump-my-version",
]
docs = [
Expand Down
2 changes: 1 addition & 1 deletion stac_fastapi/pgstac/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from buildpg import render
from cql2 import Expr
from fastapi import HTTPException, Request
from hydraters import hydrate
from pydantic import ValidationError
from pypgstac.hydration import hydrate
from stac_fastapi.api.models import JSONResponse
from stac_fastapi.types.core import AsyncBaseCoreClient, Relations
from stac_fastapi.types.errors import InvalidQueryParameter, NotFoundError
Expand Down
49 changes: 26 additions & 23 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
import pytest
from fastapi import Request
from httpx import ASGITransport, AsyncClient
from pypgstac.db import PgstacDB
from pypgstac.load import Loader
from pystac import Collection, Extent, Item, SpatialExtent, TemporalExtent
from stac_fastapi.api.app import StacApi
from stac_fastapi.api.models import create_get_request_model, create_post_request_model
Expand Down Expand Up @@ -701,7 +699,7 @@ async def search(query: Dict[str, Any]) -> List[Item]:


@pytest.mark.asyncio
async def test_wrapped_function(load_test_data, database) -> None:
async def test_wrapped_function(load_test_data, pgstac) -> None:
# Ensure wrappers, e.g. Planetary Computer's rate limiting, work.
# https://github.com/gadomski/planetary-computer-apis/blob/2719ccf6ead3e06de0784c39a2918d4d1811368b/pccommon/pccommon/redis.py#L205-L238

Expand Down Expand Up @@ -740,11 +738,11 @@ async def get_collection(
)

postgres_settings = PostgresSettings(
pguser=database.user,
pgpassword=database.password,
pghost=database.host,
pgport=database.port,
pgdatabase=database.dbname,
pguser=pgstac.user,
pgpassword=pgstac.password,
pghost=pgstac.host,
pgport=pgstac.port,
pgdatabase=pgstac.dbname,
)

extensions = [
Expand Down Expand Up @@ -797,29 +795,23 @@ async def get_collection(
@pytest.mark.asyncio
@pytest.mark.parametrize("validation", [True, False])
@pytest.mark.parametrize("hydrate", [True, False])
async def test_no_extension(
hydrate, validation, load_test_data, database, pgstac
) -> None:
async def test_no_extension(hydrate, validation, load_test_data, pgstac) -> None:
"""test PgSTAC with no extension."""
connection = f"postgresql://{database.user}:{quote_plus(database.password)}@{database.host}:{database.port}/{database.dbname}"
with PgstacDB(dsn=connection) as db:
loader = Loader(db=db)
loader.load_collections(os.path.join(DATA_DIR, "test_collection.json"))
loader.load_items(os.path.join(DATA_DIR, "test_item.json"))

settings = Settings(
testing=True,
use_api_hydrate=hydrate,
enable_response_models=validation,
)
postgres_settings = PostgresSettings(
pguser=database.user,
pgpassword=database.password,
pghost=database.host,
pgport=database.port,
pgdatabase=database.dbname,
pguser=pgstac.user,
pgpassword=pgstac.password,
pghost=pgstac.host,
pgport=pgstac.port,
pgdatabase=pgstac.dbname,
)
extensions = []
extensions = [
TransactionExtension(client=TransactionsClient(), settings=settings),
]
post_request_model = create_post_request_model(extensions, base_model=PgstacSearch)
api = StacApi(
client=CoreCrudClient(pgstac_search_model=post_request_model),
Expand All @@ -835,6 +827,17 @@ async def test_no_extension(
)
try:
async with AsyncClient(transport=ASGITransport(app=app)) as client:
response = await client.post(
"http://test/collections",
json=load_test_data("test_collection.json"),
)
assert response.status_code == 201
response = await client.post(
"http://test/collections/test-collection/items",
json=load_test_data("test_item.json"),
)
assert response.status_code == 201

landing = await client.get("http://test/")
assert landing.status_code == 200, landing.text
assert "Queryables" not in [
Expand Down
12 changes: 6 additions & 6 deletions tests/api/test_links_with_root_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@


@pytest.fixture(scope="function")
async def app_with_root_path(database, monkeypatch):
async def app_with_root_path(pgstac, monkeypatch):
"""
Provides the global stac_fastapi.pgstac.app.app instance, configured with a
specific ROOT_PATH environment variable and connected to the test database.
"""

monkeypatch.setenv("ROOT_PATH", ROOT_PATH)
monkeypatch.setenv("PGUSER", database.user)
monkeypatch.setenv("PGPASSWORD", database.password)
monkeypatch.setenv("PGHOST", database.host)
monkeypatch.setenv("PGPORT", str(database.port))
monkeypatch.setenv("PGDATABASE", database.dbname)
monkeypatch.setenv("PGUSER", pgstac.user)
monkeypatch.setenv("PGPASSWORD", pgstac.password)
monkeypatch.setenv("PGHOST", pgstac.host)
monkeypatch.setenv("PGPORT", str(pgstac.port))
monkeypatch.setenv("PGDATABASE", pgstac.dbname)
monkeypatch.setenv("ENABLE_TRANSACTIONS_EXTENSIONS", "TRUE")

# Reload the app module to pick up the new environment variables
Expand Down
24 changes: 12 additions & 12 deletions tests/clients/test_postgres.py
Original file line number Diff line number Diff line change
Expand Up @@ -539,13 +539,13 @@ async def test_create_bulk_items_id_mismatch(
# assert item.collection == coll.id


async def test_db_setup_works_with_env_vars(api_client, database, monkeypatch):
async def test_db_setup_works_with_env_vars(api_client, pgstac, monkeypatch):
"""Test that the application starts successfully if the POSTGRES_* environment variables are set"""
monkeypatch.setenv("PGUSER", database.user)
monkeypatch.setenv("PGPASSWORD", database.password)
monkeypatch.setenv("PGHOST", database.host)
monkeypatch.setenv("PGPORT", str(database.port))
monkeypatch.setenv("PGDATABASE", database.dbname)
monkeypatch.setenv("PGUSER", pgstac.user)
monkeypatch.setenv("PGPASSWORD", pgstac.password)
monkeypatch.setenv("PGHOST", pgstac.host)
monkeypatch.setenv("PGPORT", str(pgstac.port))
monkeypatch.setenv("PGDATABASE", pgstac.dbname)

await connect_to_db(api_client.app)
await close_db_connection(api_client.app)
Expand Down Expand Up @@ -573,16 +573,16 @@ async def custom_get_connection(

class TestDbConnect:
@pytest.fixture
async def app(self, api_client, database):
async def app(self, api_client, pgstac):
"""
app fixture override to setup app with a customized db connection getter
"""
postgres_settings = PostgresSettings(
pguser=database.user,
pgpassword=database.password,
pghost=database.host,
pgport=database.port,
pgdatabase=database.dbname,
pguser=pgstac.user,
pgpassword=pgstac.password,
pghost=pgstac.host,
pgport=pgstac.port,
pgdatabase=pgstac.dbname,
)

logger.debug("Customizing app setup")
Expand Down
Loading