From 3819ed3390bc3cdc9df832193ee08ac6c297a0b5 Mon Sep 17 00:00:00 2001 From: Oliver Lambson Date: Mon, 27 May 2024 23:08:08 +0100 Subject: [PATCH 1/2] add failing test --- modules/postgres/tests/test_postgres.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/modules/postgres/tests/test_postgres.py b/modules/postgres/tests/test_postgres.py index 528403617..38c856bf9 100644 --- a/modules/postgres/tests/test_postgres.py +++ b/modules/postgres/tests/test_postgres.py @@ -97,3 +97,27 @@ def test_show_how_to_initialize_db_via_initdb_dir(): result = result.fetchall() assert len(result) == 1 assert result[0] == (1, "sally", "sells seashells") + + +def test_none_driver_urls(): + user = "root" + password = "pass" + kwargs = { + "username": user, + "password": password, + } + with PostgresContainer("postgres:16-alpine", driver=None, **kwargs) as container: + port = container.get_exposed_port(5432) + host = container.get_container_host_ip() + expected_url = f"postgresql://{user}:{password}@{host}:{port}/test" + + url = container.get_connection_url() + assert url == expected_url + + with PostgresContainer("postgres:16-alpine", **kwargs) as container: + port = container.get_exposed_port(5432) + host = container.get_container_host_ip() + expected_url = f"postgresql://{user}:{password}@{host}:{port}/test" + + url = container.get_connection_url(driver=None) + assert url == expected_url From beaab595856b46821f43701be39c9de6b16f6022 Mon Sep 17 00:00:00 2001 From: Oliver Lambson Date: Mon, 27 May 2024 23:08:51 +0100 Subject: [PATCH 2/2] pass test --- modules/postgres/testcontainers/postgres/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/postgres/testcontainers/postgres/__init__.py b/modules/postgres/testcontainers/postgres/__init__.py index 9b347aa61..80baef752 100644 --- a/modules/postgres/testcontainers/postgres/__init__.py +++ b/modules/postgres/testcontainers/postgres/__init__.py @@ -79,7 +79,7 @@ def get_connection_url(self, host: Optional[str] = None, driver: Optional[str] = driver. The optional driver argument to :code:`get_connection_url` overwrites the constructor set value. Pass :code:`driver=None` to get URLs without a driver. """ - driver_str = self.driver if driver is _UNSET else f"+{driver}" + driver_str = "" if driver is None else self.driver if driver is _UNSET else f"+{driver}" return super()._create_connection_url( dialect=f"postgresql{driver_str}", username=self.username,