9
9
import asyncpg
10
10
import pytest
11
11
from fastapi import APIRouter
12
- from fastapi .responses import ORJSONResponse
13
12
from httpx import ASGITransport , AsyncClient
14
13
from pypgstac import __version__ as pgstac_version
15
14
from pypgstac .db import PgstacDB
18
17
from stac_fastapi .api .app import StacApi
19
18
from stac_fastapi .api .models import (
20
19
ItemCollectionUri ,
20
+ JSONResponse ,
21
21
create_get_request_model ,
22
22
create_post_request_model ,
23
23
create_request_model ,
@@ -189,7 +189,7 @@ def api_client(request):
189
189
search_get_request_model = search_get_request_model ,
190
190
search_post_request_model = search_post_request_model ,
191
191
collections_get_request_model = collection_search_extension .GET ,
192
- response_class = ORJSONResponse ,
192
+ response_class = JSONResponse ,
193
193
router = APIRouter (prefix = prefix ),
194
194
health_check = health_check ,
195
195
)
@@ -290,14 +290,11 @@ async def load_test2_item(app_client, load_test_data, load_test2_collection):
290
290
return Item .model_validate (resp .json ())
291
291
292
292
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 (
301
298
settings = api_settings ,
302
299
extensions = [
303
300
TransactionExtension (client = TransactionsClient (), settings = api_settings )
@@ -306,9 +303,6 @@ def api_client_no_ext():
306
303
health_check = health_check ,
307
304
)
308
305
309
-
310
- @pytest .fixture (scope = "function" )
311
- async def app_no_ext (api_client_no_ext , database ):
312
306
postgres_settings = PostgresSettings (
313
307
postgres_user = database .user ,
314
308
postgres_pass = database .password ,
@@ -319,12 +313,9 @@ async def app_no_ext(api_client_no_ext, database):
319
313
)
320
314
logger .info ("Creating app Fixture" )
321
315
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 )
328
319
329
320
logger .info ("Closed Pools." )
330
321
@@ -336,3 +327,70 @@ async def app_client_no_ext(app_no_ext):
336
327
transport = ASGITransport (app = app_no_ext ), base_url = "http://test"
337
328
) as c :
338
329
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