Skip to content

use specific ENV ENABLE_TRANSACTIONS_EXTENSIONS for transactions #239

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
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
2 changes: 1 addition & 1 deletion .github/workflows/cicd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ jobs:
PGDATABASE: postgis
APP_HOST: 0.0.0.0
APP_PORT: 8080
ENABLED_EXTENSIONS: transaction,bulk_transactions,query,sort,fields,filter,pagination,collection_search
ENABLE_TRANSACTIONS_EXTENSIONS: TRUE

test-docs:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- DB_MIN_CONN_SIZE=1
- DB_MAX_CONN_SIZE=1
- USE_API_HYDRATE=${USE_API_HYDRATE:-false}
- ENABLED_EXTENSIONS=transaction,bulk_transactions,query,sort,fields,filter,pagination,collection_search
- ENABLE_TRANSACTIONS_EXTENSIONS=TRUE
ports:
- "8082:8082"
volumes:
Expand Down
4 changes: 1 addition & 3 deletions stac_fastapi/pgstac/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,7 @@

application_extensions = []

# transaction extensions
if "transaction" in enabled_extensions:
if os.environ.get("ENABLE_TRANSACTIONS_EXTENSIONS", "").lower() in ["yes", "true", "1"]:
application_extensions.append(
TransactionExtension(
client=TransactionsClient(),
Expand All @@ -105,7 +104,6 @@
),
)

if "bulk_transactions" in enabled_extensions:
application_extensions.append(
BulkTransactionExtension(client=BulkTransactionsClient()),
)
Expand Down
43 changes: 41 additions & 2 deletions tests/api/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,13 @@


async def test_default_app_no_transactions(
default_app_client, load_test_data, load_test_collection
app_client_no_transaction, load_test_data, load_test_collection
):
coll = load_test_collection
item = load_test_data("test_item.json")
resp = await default_app_client.post(f"/collections/{coll['id']}/items", json=item)
resp = await app_client_no_transaction.post(
f"/collections/{coll['id']}/items", json=item
)

# the default application does not have the transaction extensions enabled!
assert resp.status_code == 405
Expand Down Expand Up @@ -903,3 +905,40 @@ async def test_no_extension(

finally:
await close_db_connection(app)


async def test_default_app(default_client, default_app, load_test_data):
api_routes = {
f"{list(route.methods)[0]} {route.path}" for route in default_app.routes
}
assert set(STAC_CORE_ROUTES).issubset(api_routes)
assert set(STAC_TRANSACTION_ROUTES).issubset(api_routes)

# Load collections
col = load_test_data("test_collection.json")
resp = await default_client.post("/collections", json=col)
assert resp.status_code == 201

# Load items
item = load_test_data("test_item.json")
resp = await default_client.post(f"/collections/{col['id']}/items", json=item)
assert resp.status_code == 201

resp = await default_client.get("/conformance")
assert resp.status_code == 200
conf = resp.json()["conformsTo"]
assert (
"https://api.stacspec.org/v1.0.0/ogcapi-features/extensions/transaction" in conf
)
assert "https://api.stacspec.org/v1.0.0/collections/extensions/transaction" in conf
assert "http://www.opengis.net/spec/cql2/1.0/conf/basic-cql2" in conf
assert "http://www.opengis.net/spec/ogcapi-common-2/1.0/conf/simple-query" in conf
assert "http://www.opengis.net/spec/ogcapi-features-1/1.0/conf/core" in conf
assert (
"http://www.opengis.net/spec/ogcapi-features-3/1.0/conf/features-filter" in conf
)
assert "http://www.opengis.net/spec/ogcapi-features-3/1.0/conf/filter" in conf
assert "https://api.stacspec.org/v1.0.0-rc.1/collection-search" in conf
assert "https://api.stacspec.org/v1.0.0/collections" in conf
assert "https://api.stacspec.org/v1.0.0/ogcapi-features#query" in conf
assert "https://api.stacspec.org/v1.0.0/ogcapi-features#sort" in conf
34 changes: 32 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ async def app_client_no_ext(app_no_ext):


@pytest.fixture(scope="function")
async def default_app(database):
async def app_no_transaction(database):
"""Default stac-fastapi-pgstac application without any extensions."""
api_settings = Settings(testing=True)
api = StacApi(
Expand Down Expand Up @@ -358,8 +358,38 @@ async def default_app(database):


@pytest.fixture(scope="function")
async def default_app_client(default_app):
async def app_client_no_transaction(app_no_transaction):
logger.info("creating app_client")
async with AsyncClient(
transport=ASGITransport(app=app_no_transaction), base_url="http://test"
) as c:
yield c


@pytest.fixture(scope="function")
async def default_app(database, monkeypatch):
"""Test default stac-fastapi-pgstac application."""
monkeypatch.setenv("POSTGRES_USER", database.user)
monkeypatch.setenv("POSTGRES_PASS", database.password)
monkeypatch.setenv("POSTGRES_HOST_READER", database.host)
monkeypatch.setenv("POSTGRES_HOST_WRITER", database.host)
monkeypatch.setenv("POSTGRES_PORT", str(database.port))
monkeypatch.setenv("POSTGRES_DBNAME", database.dbname)
monkeypatch.delenv("ENABLED_EXTENSIONS", raising=False)

monkeypatch.setenv("ENABLE_TRANSACTIONS_EXTENSIONS", "TRUE")
monkeypatch.setenv("USE_API_HYDRATE", "TRUE")
monkeypatch.setenv("ENABLE_RESPONSE_MODELS", "TRUE")

from stac_fastapi.pgstac.app import app

await connect_to_db(app)
yield app
await close_db_connection(app)


@pytest.fixture(scope="function")
async def default_client(default_app):
async with AsyncClient(
transport=ASGITransport(app=default_app), base_url="http://test"
) as c:
Expand Down