Skip to content

Commit b6fb1e4

Browse files
author
CommanderKeynes
committed
Add tests
1 parent 8558a46 commit b6fb1e4

File tree

1 file changed

+39
-1
lines changed

1 file changed

+39
-1
lines changed

tests/test_connect.py

+39-1
Original file line numberDiff line numberDiff line change
@@ -1265,7 +1265,7 @@ def test_connect_connection_service_file(self):
12651265
connection_service_file.close()
12661266
os.chmod(connection_service_file.name, stat.S_IWUSR | stat.S_IRUSR)
12671267
try:
1268-
# passfile path in env
1268+
# Test connection service file with dbname
12691269
self.run_testcase({
12701270
'dsn': 'postgresql://?service=test_service_dbname',
12711271
'env': {
@@ -1283,6 +1283,7 @@ def test_connect_connection_service_file(self):
12831283
}
12841284
)
12851285
})
1286+
# Test connection service file with database
12861287
self.run_testcase({
12871288
'dsn': 'postgresql://?service=test_service_database',
12881289
'env': {
@@ -1300,6 +1301,43 @@ def test_connect_connection_service_file(self):
13001301
}
13011302
)
13021303
})
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+
})
13031341
finally:
13041342
os.unlink(connection_service_file.name)
13051343

0 commit comments

Comments
 (0)