Skip to content
Open
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
19 changes: 15 additions & 4 deletions testcontainers/clickhouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import os
import warnings

import clickhouse_driver
from clickhouse_driver.errors import Error
Expand Down Expand Up @@ -41,25 +42,35 @@ class ClickHouseContainer(DbContainer):
def __init__(
self,
image="clickhouse/clickhouse-server:latest",
port=9000,
http_port=8123,
native_port=9000,
port=None,
user=None,
password=None,
dbname=None
):
if port is not None:
warnings.warn(
"The `port` parameter is deprecated. Use `http_port` and `native_port` instead.",
category=DeprecationWarning,
)
native_port = port
super().__init__(image=image)

self.CLICKHOUSE_USER = user or self.CLICKHOUSE_USER
self.CLICKHOUSE_PASSWORD = password or self.CLICKHOUSE_PASSWORD
self.CLICKHOUSE_DB = dbname or self.CLICKHOUSE_DB
self.port_to_expose = port
self.port_to_expose = native_port # TODO: deprecated, remove
self.http_port = http_port
self.native_port = native_port
self.with_exposed_ports(self.http_port, self.native_port)

@wait_container_is_ready(Error, EOFError)
def _connect(self):
with clickhouse_driver.Client.from_url(self.get_connection_url()) as client:
client.execute("SELECT version()")

def _configure(self):
self.with_exposed_ports(self.port_to_expose)
self.with_env("CLICKHOUSE_USER", self.CLICKHOUSE_USER)
self.with_env("CLICKHOUSE_PASSWORD", self.CLICKHOUSE_PASSWORD)
self.with_env("CLICKHOUSE_DB", self.CLICKHOUSE_DB)
Expand All @@ -71,5 +82,5 @@ def get_connection_url(self, host=None):
password=self.CLICKHOUSE_PASSWORD,
db_name=self.CLICKHOUSE_DB,
host=host,
port=self.port_to_expose,
port=self.native_port,
)