diff options
| author | Julian Mehnle <julian@mehnle.net> | 2019-03-21 17:54:22 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2019-03-24 12:03:28 -0400 |
| commit | a31da95e002e34d639daef27d972eb364a1ebd13 (patch) | |
| tree | 9504073515f0310fc8898291fc5a3cdd955e2fa4 /test/dialect/postgresql | |
| parent | 8acbc2624fb4b457e47fab93e6a44a1e37caeddc (diff) | |
| download | sqlalchemy-a31da95e002e34d639daef27d972eb364a1ebd13.tar.gz | |
Support DNS-less connections for psycopg2
Added support for parameter-less connection URLs for the psycopg2 dialect,
meaning, the URL can be passed to :func:`.create_engine` as
``"postgresql+psycopg2://"`` with no additional arguments to indicate an
empty DSN passed to libpq, which indicates to connect to "localhost" with
no username, password, or database given. Pull request courtesy Julian
Mehnle.
Fixes: #4562
Closes: #4563
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/4563
Pull-request-sha: 8a05c96944a0523b06e9772cfe1832e500a43641
Change-Id: Ib6fca3c3c9eebeaf590d7f7fb0bc8cd4b6e4a55a
Diffstat (limited to 'test/dialect/postgresql')
| -rw-r--r-- | test/dialect/postgresql/test_dialect.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/dialect/postgresql/test_dialect.py b/test/dialect/postgresql/test_dialect.py index cadcbdc1c..8c19e31bb 100644 --- a/test/dialect/postgresql/test_dialect.py +++ b/test/dialect/postgresql/test_dialect.py @@ -27,6 +27,7 @@ from sqlalchemy import testing from sqlalchemy import text from sqlalchemy import TypeDecorator from sqlalchemy.dialects.postgresql import base as postgresql +from sqlalchemy.dialects.postgresql import psycopg2 as psycopg2_dialect from sqlalchemy.engine import engine_from_config from sqlalchemy.engine import url from sqlalchemy.testing import engines @@ -114,6 +115,20 @@ class DialectTest(fixtures.TestBase): e = engine_from_config(config, _initialize=False) eq_(e.dialect.use_native_unicode, True) + def test_psycopg2_empty_connection_string(self): + dialect = psycopg2_dialect.dialect() + u = url.make_url("postgresql://") + cargs, cparams = dialect.create_connect_args(u) + eq_(cargs, ['']) + eq_(cparams, {}) + + def test_psycopg2_nonempty_connection_string(self): + dialect = psycopg2_dialect.dialect() + u = url.make_url("postgresql://host") + cargs, cparams = dialect.create_connect_args(u) + eq_(cargs, []) + eq_(cparams, {"host": "host"}) + class BatchInsertsTest(fixtures.TablesTest): __only_on__ = "postgresql+psycopg2" |
