diff --git a/lib/bootstrapper/index.ts b/lib/bootstrapper/index.ts index 7ac8968..e4cd30d 100644 --- a/lib/bootstrapper/index.ts +++ b/lib/bootstrapper/index.ts @@ -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. diff --git a/lib/ingestor-api/runtime/src/collection.py b/lib/ingestor-api/runtime/src/collection.py index d6f11fa..7e6c2a5 100644 --- a/lib/ingestor-api/runtime/src/collection.py +++ b/lib/ingestor-api/runtime/src/collection.py @@ -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}") diff --git a/lib/ingestor-api/runtime/tests/conftest.py b/lib/ingestor-api/runtime/tests/conftest.py index f2d357e..e7309ba 100644 --- a/lib/ingestor-api/runtime/tests/conftest.py +++ b/lib/ingestor-api/runtime/tests/conftest.py @@ -248,7 +248,7 @@ 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) @@ -256,20 +256,7 @@ def client_authenticated(app): 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 diff --git a/lib/ingestor-api/runtime/tests/test_collection.py b/lib/ingestor-api/runtime/tests/test_collection.py new file mode 100644 index 0000000..6141342 --- /dev/null +++ b/lib/ingestor-api/runtime/tests/test_collection.py @@ -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, + )