Skip to content

Commit

Permalink
fix(bootstraper): fix version inconsistencies and #19 regressions (#34)
Browse files Browse the repository at this point in the history
* bump default pypgstac version in bootstrapper

* fix regression introduced by #19

* convert StacCollection object to list of Dict to comply with pypgstac expectations

* format

* add unit test that verifies the call to pypgstac.load.Loader.load_collections to avoid future regressions

* format

* clean up conftest StacCollection generator, make use of it in new test

* remove unused import
  • Loading branch information
emileten authored Apr 14, 2023
1 parent d6ce600 commit ebeac2a
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 17 deletions.
2 changes: 1 addition & 1 deletion lib/bootstrapper/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function hasVpc(
return (instance as aws_rds.DatabaseInstance).vpc !== undefined;
}

const DEFAULT_PGSTAC_VERSION = "0.6.8";
const DEFAULT_PGSTAC_VERSION = "0.6.13";

/**
* Bootstraps a database instance, installing pgSTAC onto the database.
Expand Down
5 changes: 4 additions & 1 deletion lib/ingestor-api/runtime/src/collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ def ingest(collection: StacCollection):
creds = get_db_credentials(os.environ["DB_SECRET_ARN"])
with PgstacDB(dsn=creds.dsn_string, debug=True) as db:
loader = Loader(db=db)
loader.load_collection(file=collection, insert_mode=Methods.upsert)
collection = [
collection.to_dict()
] # pypgstac wants either a string or an Iterable of dicts.
loader.load_collections(file=collection, insert_mode=Methods.upsert)
except Exception as e:
print(f"Encountered failure loading collection into pgSTAC: {e}")

Expand Down
17 changes: 2 additions & 15 deletions lib/ingestor-api/runtime/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,28 +248,15 @@ def client_authenticated(app):
"""
from src.dependencies import get_username

app.dependency_overrides[get_username] = lambda: 'test_user'
app.dependency_overrides[get_username] = lambda: "test_user"
return TestClient(app)


@pytest.fixture
def stac_collection(example_stac_collection):
from src import schemas

return schemas.StacCollection(
id=example_stac_collection["id"],
type=example_stac_collection["type"],
stac_extensions=example_stac_collection["stac_extensions"],
item_assets=example_stac_collection["item_assets"],
stac_version=example_stac_collection["stac_version"],
description=example_stac_collection["description"],
title=example_stac_collection["title"],
providers=example_stac_collection["providers"],
extent=example_stac_collection["extent"],
license=example_stac_collection["license"],
summaries=example_stac_collection["summaries"],
links=example_stac_collection["links"],
)
return schemas.StacCollection(**example_stac_collection)


@pytest.fixture
Expand Down
35 changes: 35 additions & 0 deletions lib/ingestor-api/runtime/tests/test_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
from unittest.mock import Mock, patch
import pytest
from pypgstac.load import Methods
from src.utils import DbCreds
import src.collection as collection
import os


@pytest.fixture()
def loader():
with patch("src.collection.Loader", autospec=True) as m:
yield m


@pytest.fixture()
def pgstacdb():
with patch("src.collection.PgstacDB", autospec=True) as m:
m.return_value.__enter__.return_value = Mock()
yield m


def test_load_collections(stac_collection, loader, pgstacdb):
with patch(
"src.collection.get_db_credentials",
return_value=DbCreds(
username="", password="", host="", port=1, dbname="", engine=""
),
):
os.environ["DB_SECRET_ARN"] = ""
collection.ingest(stac_collection)

loader.return_value.load_collections.assert_called_once_with(
file=[stac_collection.to_dict()],
insert_mode=Methods.upsert,
)

0 comments on commit ebeac2a

Please sign in to comment.