Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

postgresql: better --host option support #170

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pifpaf/drivers/postgresql.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,15 @@ def get_options(cls):
def __init__(self, port=DEFAULT_PORT, host=DEFAULT_HOST,
sync=DEFAULT_SYNC, **kwargs):
"""Create a new PostgreSQL instance."""
super(PostgreSQLDriver, self).__init__(**kwargs)
super().__init__(**kwargs)
self.port = port
self.host = host
self.sync = sync

def _setUp(self):
super(PostgreSQLDriver, self)._setUp()
super()._setUp()
self.putenv("PGPORT", str(self.port), True)
self.putenv("PGHOST", self.tempdir, True)
self.putenv("PGHOST", self.host or self.tempdir, True)
self.putenv("PGDATA", self.tempdir, True)
self.putenv("PGDATABASE", "postgres", True)
_, pgbindir = self._exec(["pg_config", "--bindir"], stdout=True)
Expand All @@ -65,6 +65,9 @@ def _setUp(self):
% (self.tempdir, self.port, self.host),
"start"], allow_debug=False)
self.addCleanup(self._exec, [pgctl, "-w", "stop"])

self.url = "postgresql://localhost/postgres?host=%s&port=%d" % (
self.tempdir, self.port)
if self.host:
self.url = "postgresql://%s:%d/postgres" % (self.host, self.port)
self.putenv("URL", self.url)
11 changes: 11 additions & 0 deletions pifpaf/tests/test_drivers.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ def test_postgresql(self):
os.getenv("PIFPAF_URL"))
self._run("psql template1 -c 'CREATE TABLE FOOBAR();'")

@testtools.skipUnless(spawn.find_executable("pg_config"),
"pg_config not found")
def test_postgresql_host(self):
host = "127.0.98.25"
port = 9825
self.useFixture(postgresql.PostgreSQLDriver(host=host, port=port))
self.assertEqual(
"postgresql://%s:%d/postgres" % (host, port),
os.getenv("PIFPAF_URL"))
self._run("psql template1 -c 'CREATE TABLE FOOBAR();'")

@testtools.skipUnless(spawn.find_executable("pg_config"),
"pg_config not found")
def test_postgresql_async(self):
Expand Down
Loading