Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed Sep 12, 2024
1 parent 3ce7ac9 commit 78e5ba7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 15 deletions.
10 changes: 7 additions & 3 deletions stac_api/runtime/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -208,7 +210,7 @@
}


@pytest.fixture
@pytest.fixture(autouse=True)
def test_environ():
"""
Set up the test environment with mocked AWS and PostgreSQL credentials.
Expand Down Expand Up @@ -250,7 +252,7 @@ def override_validated_token():


@pytest.fixture
def app(test_environ):
async def app():
"""
Fixture to initialize the FastAPI application.
Expand All @@ -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")
Expand Down
24 changes: 12 additions & 12 deletions stac_api/runtime/tests/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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

0 comments on commit 78e5ba7

Please sign in to comment.