diff --git a/stac_api/runtime/tests/conftest.py b/stac_api/runtime/tests/conftest.py index dc349055..6c3c3074 100644 --- a/stac_api/runtime/tests/conftest.py +++ b/stac_api/runtime/tests/conftest.py @@ -11,6 +11,8 @@ import pytest from httpx import ASGITransport, AsyncClient +from stac_fastapi.pgstac.db import close_db_connection, connect_to_db + VALID_COLLECTION = { "id": "CMIP245-winter-median-pr", "type": "Collection", @@ -208,7 +210,7 @@ } -@pytest.fixture +@pytest.fixture(autouse=True) def test_environ(): """ Set up the test environment with mocked AWS and PostgreSQL credentials. @@ -250,7 +252,7 @@ def override_validated_token(): @pytest.fixture -def app(test_environ): +async def app(): """ Fixture to initialize the FastAPI application. @@ -265,7 +267,9 @@ def app(test_environ): """ from src.app import app - return app + await connect_to_db(app) + yield app + await close_db_connection(app) @pytest.fixture(scope="function") diff --git a/stac_api/runtime/tests/test_transactions.py b/stac_api/runtime/tests/test_transactions.py index 6a5cd8e3..4961f287 100644 --- a/stac_api/runtime/tests/test_transactions.py +++ b/stac_api/runtime/tests/test_transactions.py @@ -53,59 +53,59 @@ def setup( self.invalid_stac_collection = invalid_stac_collection self.invalid_stac_item = invalid_stac_item - def test_post_invalid_collection(self): + async def test_post_invalid_collection(self): """ Test the API's response to posting an invalid STAC collection. Asserts that the response status code is 422 and the detail is "Validation Error". """ - response = self.api_client.post( + response = await self.api_client.post( collections_endpoint, json=self.invalid_stac_collection ) assert response.json()["detail"] == "Validation Error" assert response.status_code == 422 - def test_post_valid_collection(self): + async def test_post_valid_collection(self): """ Test the API's response to posting a valid STAC collection. Asserts that the response status code is 200. """ - response = self.api_client.post( + response = await self.api_client.post( collections_endpoint, json=self.valid_stac_collection ) # assert response.json() == {} assert response.status_code == 200 - def test_post_invalid_item(self): + async def test_post_invalid_item(self): """ Test the API's response to posting an invalid STAC item. Asserts that the response status code is 422 and the detail is "Validation Error". """ - response = self.api_client.post( + response = await self.api_client.post( items_endpoint.format(self.invalid_stac_item["collection"]), json=self.invalid_stac_item, ) assert response.json()["detail"] == "Validation Error" assert response.status_code == 422 - def test_post_valid_item(self): + async def test_post_valid_item(self): """ Test the API's response to posting a valid STAC item. Asserts that the response status code is 200. """ - response = self.api_client.post( + response = await self.api_client.post( items_endpoint.format(self.valid_stac_item["collection"]), json=self.valid_stac_item, ) # assert response.json() == {} assert response.status_code == 200 - def test_post_invalid_bulk_items(self): + async def test_post_invalid_bulk_items(self): """ Test the API's response to posting invalid bulk STAC items. @@ -117,12 +117,12 @@ def test_post_invalid_bulk_items(self): "items": {item_id: self.invalid_stac_item}, "method": "upsert", } - response = self.api_client.post( + response = await self.api_client.post( bulk_endpoint.format(collection_id), json=invalid_request ) assert response.status_code == 422 - def test_post_valid_bulk_items(self): + async def test_post_valid_bulk_items(self): """ Test the API's response to posting valid bulk STAC items. @@ -131,7 +131,7 @@ def test_post_valid_bulk_items(self): item_id = self.valid_stac_item["id"] collection_id = self.valid_stac_item["collection"] valid_request = {"items": {item_id: self.valid_stac_item}, "method": "upsert"} - response = self.api_client.post( + response = await self.api_client.post( bulk_endpoint.format(collection_id), json=valid_request ) assert response.status_code == 200