MCPcopy Index your code
hub / github.com/dbcli/pgcli / test_pg_service_file

Function test_pg_service_file

tests/test_main.py:454–504  ·  view source on GitHub ↗
(tmpdir)

Source from the content-addressed store, hash-verified

452
453
454def test_pg_service_file(tmpdir):
455 with mock.patch.object(PGCli, "connect") as mock_connect:
456 cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile")))
457 with open(tmpdir.join(".pg_service.conf").strpath, "w") as service_conf:
458 service_conf.write(
459 """File begins with a comment
460 that is not a comment
461 # or maybe a comment after all
462 because psql is crazy
463
464 [myservice]
465 host=a_host
466 user=a_user
467 port=5433
468 password=much_secure
469 dbname=a_dbname
470
471 [my_other_service]
472 host=b_host
473 user=b_user
474 port=5435
475 dbname=b_dbname
476 """
477 )
478 os.environ["PGSERVICEFILE"] = tmpdir.join(".pg_service.conf").strpath
479 cli.connect_service("myservice", "another_user")
480 mock_connect.assert_called_with(
481 database="a_dbname",
482 host="a_host",
483 user="another_user",
484 port="5433",
485 passwd="much_secure",
486 )
487
488 with mock.patch.object(PGExecute, "__init__") as mock_pgexecute:
489 mock_pgexecute.return_value = None
490 cli = PGCli(pgclirc_file=str(tmpdir.join("rcfile")))
491 os.environ["PGPASSWORD"] = "very_secure"
492 cli.connect_service("my_other_service", None)
493 mock_pgexecute.assert_called_with(
494 "b_dbname",
495 "b_user",
496 "very_secure",
497 "b_host",
498 "5435",
499 "",
500 notify_callback,
501 application_name="pgcli",
502 )
503 del os.environ["PGPASSWORD"]
504 del os.environ["PGSERVICEFILE"]
505
506
507def test_ssl_db_uri(tmpdir):

Callers

nothing calls this directly

Calls 2

connect_serviceMethod · 0.95
PGCliClass · 0.90

Tested by

no test coverage detected