MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / test_connect_pgpass_regular

Method test_connect_pgpass_regular

tests/test_connect.py:1375–1546  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

1373 os.unlink(connection_service_file.name)
1374
1375 def test_connect_pgpass_regular(self):
1376 passfile = tempfile.NamedTemporaryFile('w+t', delete=False)
1377 passfile.write(textwrap.dedent(R'''
1378 abc:*:*:user:password from pgpass for user@abc
1379 localhost:*:*:*:password from pgpass for localhost
1380 cde:5433:*:*:password from pgpass for cde:5433
1381
1382 *:*:*:testuser:password from pgpass for testuser
1383 *:*:testdb:*:password from pgpass for testdb
1384 # comment
1385 *:*:test\:db:test\\:password from pgpass with escapes
1386 '''))
1387 passfile.close()
1388 os.chmod(passfile.name, stat.S_IWUSR | stat.S_IRUSR)
1389
1390 try:
1391 # passfile path in env
1392 self.run_testcase({
1393 'env': {
1394 'PGPASSFILE': passfile.name
1395 },
1396 'host': 'abc',
1397 'user': 'user',
1398 'database': 'db',
1399 'result': (
1400 [('abc', 5432)],
1401 {
1402 'password': 'password from pgpass for user@abc',
1403 'user': 'user',
1404 'database': 'db',
1405 'target_session_attrs': 'any',
1406 }
1407 )
1408 })
1409
1410 # passfile path as explicit arg
1411 self.run_testcase({
1412 'host': 'abc',
1413 'user': 'user',
1414 'database': 'db',
1415 'passfile': passfile.name,
1416 'result': (
1417 [('abc', 5432)],
1418 {
1419 'password': 'password from pgpass for user@abc',
1420 'user': 'user',
1421 'database': 'db',
1422 'target_session_attrs': 'any',
1423 }
1424 )
1425 })
1426
1427 # passfile path in dsn
1428 self.run_testcase({
1429 'dsn': 'postgres://user@abc/db?passfile={}'.format(
1430 passfile.name),
1431 'result': (
1432 [('abc', 5432)],

Callers

nothing calls this directly

Calls 3

run_testcaseMethod · 0.95
writeMethod · 0.80
closeMethod · 0.45

Tested by

no test coverage detected