@@ -1265,7 +1265,7 @@ def test_connect_connection_service_file(self):
1265
1265
connection_service_file .close ()
1266
1266
os .chmod (connection_service_file .name , stat .S_IWUSR | stat .S_IRUSR )
1267
1267
try :
1268
- # passfile path in env
1268
+ # Test connection service file with dbname
1269
1269
self .run_testcase ({
1270
1270
'dsn' : 'postgresql://?service=test_service_dbname' ,
1271
1271
'env' : {
@@ -1283,6 +1283,7 @@ def test_connect_connection_service_file(self):
1283
1283
}
1284
1284
)
1285
1285
})
1286
+ # Test connection service file with database
1286
1287
self .run_testcase ({
1287
1288
'dsn' : 'postgresql://?service=test_service_database' ,
1288
1289
'env' : {
@@ -1300,6 +1301,43 @@ def test_connect_connection_service_file(self):
1300
1301
}
1301
1302
)
1302
1303
})
1304
+ # Test that envvars are overridden by service file
1305
+ self .run_testcase ({
1306
+ 'dsn' : 'postgresql://?service=test_service_dbname' ,
1307
+ 'env' : {
1308
+ 'PGUSER' : 'user' ,
1309
+ 'PGSERVICEFILE' : connection_service_file .name
1310
+ },
1311
+ 'result' : (
1312
+ [('somehost' , 5433 )],
1313
+ {
1314
+ 'user' : 'admin' ,
1315
+ 'password' : 'test_password' ,
1316
+ 'database' : 'test_dbname' ,
1317
+ 'target_session_attrs' : 'primary' ,
1318
+ 'krbsrvname' : 'fakekrbsrvname' ,
1319
+ 'gsslib' : 'sspi' ,
1320
+ }
1321
+ )
1322
+ })
1323
+ # Test that dsn params overwrite service file
1324
+ self .run_testcase ({
1325
+ 'dsn' : 'postgresql://?service=test_service_dbname&dbname=test_dbname_dsn' ,
1326
+ 'env' : {
1327
+ 'PGSERVICEFILE' : connection_service_file .name
1328
+ },
1329
+ 'result' : (
1330
+ [('somehost' , 5433 )],
1331
+ {
1332
+ 'user' : 'admin' ,
1333
+ 'password' : 'test_password' ,
1334
+ 'database' : 'test_dbname_dsn' ,
1335
+ 'target_session_attrs' : 'primary' ,
1336
+ 'krbsrvname' : 'fakekrbsrvname' ,
1337
+ 'gsslib' : 'sspi' ,
1338
+ }
1339
+ )
1340
+ })
1303
1341
finally :
1304
1342
os .unlink (connection_service_file .name )
1305
1343
0 commit comments