(tmpdir)
| 452 | |
| 453 | |
| 454 | def 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 | |
| 507 | def test_ssl_db_uri(tmpdir): |
nothing calls this directly
no test coverage detected