11import asyncio
22import json
3+ import logging
34import os
45import time
56from typing import Callable , Dict
3334from stac_fastapi .pgstac .transactions import BulkTransactionsClient , TransactionsClient
3435from stac_fastapi .pgstac .types .search import PgstacSearch
3536
37+ logger = logging .getLogger (__name__ )
38+
3639DATA_DIR = os .path .join (os .path .dirname (__file__ ), "data" )
3740
3841settings = Settings (testing = True )
@@ -46,7 +49,7 @@ def event_loop():
4649
4750@pytest .fixture (scope = "session" )
4851async def pg ():
49- print (f"Connecting to write database { settings .writer_connection_string } " )
52+ logger . info (f"Connecting to write database { settings .writer_connection_string } " )
5053 os .environ ["orig_postgres_dbname" ] = settings .postgres_dbname
5154 conn = await asyncpg .connect (dsn = settings .writer_connection_string )
5255 try :
@@ -64,21 +67,20 @@ async def pg():
6467 "ALTER DATABASE pgstactestdb SET search_path to pgstac, public;"
6568 )
6669 await conn .close ()
67- print ("migrating..." )
70+ logger . info ("migrating..." )
6871 os .environ ["postgres_dbname" ] = "pgstactestdb"
6972 conn = await asyncpg .connect (dsn = settings .testing_connection_string )
70- val = await conn .fetchval ("SELECT true" )
71- print (val )
73+ await conn .execute ("SELECT true" )
7274 await conn .close ()
7375 db = PgstacDB (dsn = settings .testing_connection_string )
7476 migrator = Migrate (db )
7577 version = migrator .run_migration ()
7678 db .close ()
77- print (f"PGStac Migrated to { version } " )
79+ logger . info (f"PGStac Migrated to { version } " )
7880
7981 yield settings .testing_connection_string
8082
81- print ("Getting rid of test database" )
83+ logger . info ("Getting rid of test database" )
8284 os .environ ["postgres_dbname" ] = os .environ ["orig_postgres_dbname" ]
8385 conn = await asyncpg .connect (dsn = settings .writer_connection_string )
8486 try :
@@ -94,9 +96,9 @@ async def pg():
9496
9597@pytest .fixture (autouse = True )
9698async def pgstac (pg ):
97- print (f"{ os .environ ['postgres_dbname' ]} " )
99+ logger . info (f"{ os .environ ['postgres_dbname' ]} " )
98100 yield
99- print ("Truncating Data" )
101+ logger . info ("Truncating Data" )
100102 conn = await asyncpg .connect (dsn = settings .testing_connection_string )
101103 await conn .execute (
102104 """
@@ -107,7 +109,7 @@ async def pgstac(pg):
107109 with PgstacDB (dsn = settings .testing_connection_string ) as db :
108110 migrator = Migrate (db )
109111 version = migrator .run_migration ()
110- print (f"PGStac Migrated to { version } " )
112+ logger . info (f"PGStac Migrated to { version } " )
111113
112114
113115# Run all the tests that use the api_client in both db hydrate and api hydrate mode
@@ -126,7 +128,7 @@ def api_client(request, pg):
126128 api_settings .openapi_url = prefix + api_settings .openapi_url
127129 api_settings .docs_url = prefix + api_settings .docs_url
128130
129- print (
131+ logger . info (
130132 "creating client with settings, hydrate: {}, router prefix: '{}'" .format (
131133 api_settings .use_api_hydrate , prefix
132134 )
@@ -159,7 +161,7 @@ def api_client(request, pg):
159161
160162@pytest .fixture (scope = "function" )
161163async def app (api_client ):
162- print ("Creating app Fixture" )
164+ logger . info ("Creating app Fixture" )
163165 time .time ()
164166 app = api_client .app
165167 await connect_to_db (app )
@@ -168,12 +170,12 @@ async def app(api_client):
168170
169171 await close_db_connection (app )
170172
171- print ("Closed Pools." )
173+ logger . info ("Closed Pools." )
172174
173175
174176@pytest .fixture (scope = "function" )
175177async def app_client (app ):
176- print ("creating app_client" )
178+ logger . info ("creating app_client" )
177179
178180 base_url = "http://test"
179181 if app .state .router_prefix != "" :
0 commit comments