1
1
import asyncio
2
2
import json
3
+ import logging
3
4
import os
4
5
import time
5
6
from typing import Callable , Dict
33
34
from stac_fastapi .pgstac .transactions import BulkTransactionsClient , TransactionsClient
34
35
from stac_fastapi .pgstac .types .search import PgstacSearch
35
36
37
+ logger = logging .getLogger (__name__ )
38
+
36
39
DATA_DIR = os .path .join (os .path .dirname (__file__ ), "data" )
37
40
38
41
settings = Settings (testing = True )
@@ -46,7 +49,7 @@ def event_loop():
46
49
47
50
@pytest .fixture (scope = "session" )
48
51
async 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 } " )
50
53
os .environ ["orig_postgres_dbname" ] = settings .postgres_dbname
51
54
conn = await asyncpg .connect (dsn = settings .writer_connection_string )
52
55
try :
@@ -64,21 +67,20 @@ async def pg():
64
67
"ALTER DATABASE pgstactestdb SET search_path to pgstac, public;"
65
68
)
66
69
await conn .close ()
67
- print ("migrating..." )
70
+ logger . info ("migrating..." )
68
71
os .environ ["postgres_dbname" ] = "pgstactestdb"
69
72
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" )
72
74
await conn .close ()
73
75
db = PgstacDB (dsn = settings .testing_connection_string )
74
76
migrator = Migrate (db )
75
77
version = migrator .run_migration ()
76
78
db .close ()
77
- print (f"PGStac Migrated to { version } " )
79
+ logger . info (f"PGStac Migrated to { version } " )
78
80
79
81
yield settings .testing_connection_string
80
82
81
- print ("Getting rid of test database" )
83
+ logger . info ("Getting rid of test database" )
82
84
os .environ ["postgres_dbname" ] = os .environ ["orig_postgres_dbname" ]
83
85
conn = await asyncpg .connect (dsn = settings .writer_connection_string )
84
86
try :
@@ -94,9 +96,9 @@ async def pg():
94
96
95
97
@pytest .fixture (autouse = True )
96
98
async def pgstac (pg ):
97
- print (f"{ os .environ ['postgres_dbname' ]} " )
99
+ logger . info (f"{ os .environ ['postgres_dbname' ]} " )
98
100
yield
99
- print ("Truncating Data" )
101
+ logger . info ("Truncating Data" )
100
102
conn = await asyncpg .connect (dsn = settings .testing_connection_string )
101
103
await conn .execute (
102
104
"""
@@ -107,7 +109,7 @@ async def pgstac(pg):
107
109
with PgstacDB (dsn = settings .testing_connection_string ) as db :
108
110
migrator = Migrate (db )
109
111
version = migrator .run_migration ()
110
- print (f"PGStac Migrated to { version } " )
112
+ logger . info (f"PGStac Migrated to { version } " )
111
113
112
114
113
115
# 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):
126
128
api_settings .openapi_url = prefix + api_settings .openapi_url
127
129
api_settings .docs_url = prefix + api_settings .docs_url
128
130
129
- print (
131
+ logger . info (
130
132
"creating client with settings, hydrate: {}, router prefix: '{}'" .format (
131
133
api_settings .use_api_hydrate , prefix
132
134
)
@@ -159,7 +161,7 @@ def api_client(request, pg):
159
161
160
162
@pytest .fixture (scope = "function" )
161
163
async def app (api_client ):
162
- print ("Creating app Fixture" )
164
+ logger . info ("Creating app Fixture" )
163
165
time .time ()
164
166
app = api_client .app
165
167
await connect_to_db (app )
@@ -168,12 +170,12 @@ async def app(api_client):
168
170
169
171
await close_db_connection (app )
170
172
171
- print ("Closed Pools." )
173
+ logger . info ("Closed Pools." )
172
174
173
175
174
176
@pytest .fixture (scope = "function" )
175
177
async def app_client (app ):
176
- print ("creating app_client" )
178
+ logger . info ("creating app_client" )
177
179
178
180
base_url = "http://test"
179
181
if app .state .router_prefix != "" :
0 commit comments