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 ,
@@ -189,7 +189,7 @@ def api_client(request):
189189 search_get_request_model = search_get_request_model ,
190190 search_post_request_model = search_post_request_model ,
191191 collections_get_request_model = collection_search_extension .GET ,
192- response_class = ORJSONResponse ,
192+ response_class = JSONResponse ,
193193 router = APIRouter (prefix = prefix ),
194194 health_check = health_check ,
195195 )
@@ -290,14 +290,11 @@ async def load_test2_item(app_client, load_test_data, load_test2_collection):
290290 return Item .model_validate (resp .json ())
291291
292292
293- @pytest .fixture (
294- scope = "session" ,
295- )
296- def api_client_no_ext ():
297- api_settings = Settings (
298- testing = True ,
299- )
300- 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 (
301298 settings = api_settings ,
302299 extensions = [
303300 TransactionExtension (client = TransactionsClient (), settings = api_settings )
@@ -306,9 +303,6 @@ def api_client_no_ext():
306303 health_check = health_check ,
307304 )
308305
309-
310- @pytest .fixture (scope = "function" )
311- async def app_no_ext (api_client_no_ext , database ):
312306 postgres_settings = PostgresSettings (
313307 postgres_user = database .user ,
314308 postgres_pass = database .password ,
@@ -319,12 +313,9 @@ async def app_no_ext(api_client_no_ext, database):
319313 )
320314 logger .info ("Creating app Fixture" )
321315 time .time ()
322- app = api_client_no_ext .app
323- await connect_to_db (app , postgres_settings = postgres_settings )
324-
325- yield app
326-
327- 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 )
328319
329320 logger .info ("Closed Pools." )
330321
@@ -336,3 +327,70 @@ async def app_client_no_ext(app_no_ext):
336327 transport = ASGITransport (app = app_no_ext ), base_url = "http://test"
337328 ) as c :
338329 yield c
330+
331+
332+ @pytest .fixture (scope = "function" )
333+ async def app_no_transaction (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 ,
341+ )
342+
343+ postgres_settings = PostgresSettings (
344+ postgres_user = database .user ,
345+ postgres_pass = database .password ,
346+ postgres_host_reader = database .host ,
347+ postgres_host_writer = database .host ,
348+ postgres_port = database .port ,
349+ postgres_dbname = database .dbname ,
350+ )
351+ logger .info ("Creating app Fixture" )
352+ time .time ()
353+ await connect_to_db (api .app , postgres_settings = postgres_settings )
354+ yield api .app
355+ await close_db_connection (api .app )
356+
357+ logger .info ("Closed Pools." )
358+
359+
360+ @pytest .fixture (scope = "function" )
361+ async def app_client_no_transaction (app_no_transaction ):
362+ logger .info ("creating app_client" )
363+ async with AsyncClient (
364+ transport = ASGITransport (app = app_no_transaction ), base_url = "http://test"
365+ ) as c :
366+ yield c
367+
368+
369+ @pytest .fixture (scope = "function" )
370+ async def default_app (database , monkeypatch ):
371+ """Test default stac-fastapi-pgstac application."""
372+ monkeypatch .setenv ("POSTGRES_USER" , database .user )
373+ monkeypatch .setenv ("POSTGRES_PASS" , database .password )
374+ monkeypatch .setenv ("POSTGRES_HOST_READER" , database .host )
375+ monkeypatch .setenv ("POSTGRES_HOST_WRITER" , database .host )
376+ monkeypatch .setenv ("POSTGRES_PORT" , str (database .port ))
377+ monkeypatch .setenv ("POSTGRES_DBNAME" , database .dbname )
378+ monkeypatch .delenv ("ENABLED_EXTENSIONS" , raising = False )
379+
380+ monkeypatch .setenv ("ENABLE_TRANSACTIONS_EXTENSIONS" , "TRUE" )
381+ monkeypatch .setenv ("USE_API_HYDRATE" , "TRUE" )
382+ monkeypatch .setenv ("ENABLE_RESPONSE_MODELS" , "TRUE" )
383+
384+ from stac_fastapi .pgstac .app import app
385+
386+ await connect_to_db (app )
387+ yield app
388+ await close_db_connection (app )
389+
390+
391+ @pytest .fixture (scope = "function" )
392+ async def default_client (default_app ):
393+ async with AsyncClient (
394+ transport = ASGITransport (app = default_app ), base_url = "http://test"
395+ ) as c :
396+ yield c
0 commit comments