99import asyncpg
1010import pytest
1111from fastapi import APIRouter
12- from fastapi .responses import ORJSONResponse
1312from httpx import ASGITransport , AsyncClient
1413from pypgstac import __version__ as pgstac_version
1514from pypgstac .db import PgstacDB
1817from stac_fastapi .api .app import StacApi
1918from stac_fastapi .api .models import (
2019 ItemCollectionUri ,
20+ JSONResponse ,
2121 create_get_request_model ,
2222 create_post_request_model ,
2323 create_request_model ,
4141from stac_fastapi .extensions .third_party import BulkTransactionExtension
4242from stac_pydantic import Collection , Item
4343
44- from stac_fastapi .pgstac .app import api as default_api
4544from stac_fastapi .pgstac .config import PostgresSettings , Settings
4645from stac_fastapi .pgstac .core import CoreCrudClient , health_check
4746from stac_fastapi .pgstac .db import close_db_connection , connect_to_db
@@ -190,7 +189,7 @@ def api_client(request):
190189 search_get_request_model = search_get_request_model ,
191190 search_post_request_model = search_post_request_model ,
192191 collections_get_request_model = collection_search_extension .GET ,
193- response_class = ORJSONResponse ,
192+ response_class = JSONResponse ,
194193 router = APIRouter (prefix = prefix ),
195194 health_check = health_check ,
196195 )
@@ -291,14 +290,11 @@ async def load_test2_item(app_client, load_test_data, load_test2_collection):
291290 return Item .model_validate (resp .json ())
292291
293292
294- @pytest .fixture (
295- scope = "session" ,
296- )
297- def api_client_no_ext ():
298- api_settings = Settings (
299- testing = True ,
300- )
301- return StacApi (
293+ @pytest .fixture (scope = "function" )
294+ async def app_no_ext (database ):
295+ """Default stac-fastapi-pgstac application without only the transaction extensions."""
296+ api_settings = Settings (testing = True )
297+ api_client_no_ext = StacApi (
302298 settings = api_settings ,
303299 extensions = [
304300 TransactionExtension (client = TransactionsClient (), settings = api_settings )
@@ -307,9 +303,6 @@ def api_client_no_ext():
307303 health_check = health_check ,
308304 )
309305
310-
311- @pytest .fixture (scope = "function" )
312- async def app_no_ext (api_client_no_ext , database ):
313306 postgres_settings = PostgresSettings (
314307 postgres_user = database .user ,
315308 postgres_pass = database .password ,
@@ -320,12 +313,9 @@ async def app_no_ext(api_client_no_ext, database):
320313 )
321314 logger .info ("Creating app Fixture" )
322315 time .time ()
323- app = api_client_no_ext .app
324- await connect_to_db (app , postgres_settings = postgres_settings )
325-
326- yield app
327-
328- await close_db_connection (app )
316+ await connect_to_db (api_client_no_ext .app , postgres_settings = postgres_settings )
317+ yield api_client_no_ext .app
318+ await close_db_connection (api_client_no_ext .app )
329319
330320 logger .info ("Closed Pools." )
331321
@@ -340,18 +330,16 @@ async def app_client_no_ext(app_no_ext):
340330
341331
342332@pytest .fixture (scope = "function" )
343- async def default_client_app ():
344- api_settings = Settings (
345- testing = True ,
333+ async def default_app (database ):
334+ """Default stac-fastapi-pgstac application without any extensions."""
335+ api_settings = Settings (testing = True )
336+ api = StacApi (
337+ settings = api_settings ,
338+ extensions = [],
339+ client = CoreCrudClient (),
340+ health_check = health_check ,
346341 )
347- api = default_api
348- api .settings = api_settings
349-
350- return api
351342
352-
353- @pytest .fixture (scope = "function" )
354- async def default_app (default_client_app , database ):
355343 postgres_settings = PostgresSettings (
356344 postgres_user = database .user ,
357345 postgres_pass = database .password ,
@@ -362,12 +350,9 @@ async def default_app(default_client_app, database):
362350 )
363351 logger .info ("Creating app Fixture" )
364352 time .time ()
365- app = default_client_app .app
366- await connect_to_db (app , postgres_settings = postgres_settings )
367-
368- yield app
369-
370- await close_db_connection (app )
353+ await connect_to_db (api .app , postgres_settings = postgres_settings )
354+ yield api .app
355+ await close_db_connection (api .app )
371356
372357 logger .info ("Closed Pools." )
373358
0 commit comments