1
1
import base64
2
2
import logging
3
+ import os
3
4
from datetime import datetime , timezone
4
5
from typing import Sequence , Tuple
5
6
21
22
from mcbackend .test_utils import CheckBehavior , CheckPerformance , make_runmeta
22
23
23
24
try :
24
- client = clickhouse_driver .Client ("localhost" )
25
+ DB_HOST = os .environ .get ("CLICKHOUSE_HOST" , "localhost" )
26
+ DB_PASS = os .environ .get ("CLICKHOUSE_PASS" , None )
27
+ DB_PORT = os .environ .get ("CLICKHOUSE_PORT" , None )
28
+ DB_KWARGS = dict (host = DB_HOST , port = DB_PORT , password = DB_PASS )
29
+ client = clickhouse_driver .Client (** DB_KWARGS )
25
30
client .execute ("SHOW DATABASES;" )
26
31
HAS_REAL_DB = True
27
32
except :
@@ -51,7 +56,7 @@ def fully_initialized(
51
56
52
57
@pytest .mark .skipif (
53
58
condition = not HAS_REAL_DB ,
54
- reason = "Integration tests need a ClickHouse server on localhost:9000 without authentication ." ,
59
+ reason = "Integration tests need a ClickHouse server." ,
55
60
)
56
61
class TestClickHouseBackendInitialization :
57
62
"""This is separate because ``TestClickHouseBackend.setup_method`` depends on these things."""
@@ -63,12 +68,12 @@ def test_exceptions(self):
63
68
64
69
def test_backend_from_client_object (self ):
65
70
db = "testing_" + hagelkorn .random ()
66
- _client_main = clickhouse_driver .Client ("localhost" )
71
+ _client_main = clickhouse_driver .Client (** DB_KWARGS )
67
72
_client_main .execute (f"CREATE DATABASE { db } ;" )
68
73
69
74
try :
70
75
# When created from a client object, all chains share the client
71
- backend = ClickHouseBackend (client = clickhouse_driver .Client ("localhost" , database = db ))
76
+ backend = ClickHouseBackend (client = clickhouse_driver .Client (** DB_KWARGS , database = db ))
72
77
assert callable (backend ._client_fn )
73
78
run = backend .init_run (make_runmeta ())
74
79
c1 = run .init_chain (0 )
@@ -81,11 +86,11 @@ def test_backend_from_client_object(self):
81
86
82
87
def test_backend_from_client_function (self ):
83
88
db = "testing_" + hagelkorn .random ()
84
- _client_main = clickhouse_driver .Client ("localhost" )
89
+ _client_main = clickhouse_driver .Client (** DB_KWARGS )
85
90
_client_main .execute (f"CREATE DATABASE { db } ;" )
86
91
87
92
def client_fn ():
88
- return clickhouse_driver .Client ("localhost" , database = db )
93
+ return clickhouse_driver .Client (** DB_KWARGS , database = db )
89
94
90
95
try :
91
96
# When created from a client function, each chain has its own client
@@ -108,7 +113,7 @@ def client_fn():
108
113
109
114
@pytest .mark .skipif (
110
115
condition = not HAS_REAL_DB ,
111
- reason = "Integration tests need a ClickHouse server on localhost:9000 without authentication ." ,
116
+ reason = "Integration tests need a ClickHouse server." ,
112
117
)
113
118
class TestClickHouseBackend (CheckBehavior , CheckPerformance ):
114
119
cls_backend = ClickHouseBackend
@@ -118,11 +123,11 @@ class TestClickHouseBackend(CheckBehavior, CheckPerformance):
118
123
def setup_method (self , method ):
119
124
"""Initializes a fresh database just for this test method."""
120
125
self ._db = "testing_" + hagelkorn .random ()
121
- self ._client_main = clickhouse_driver .Client ("localhost" )
126
+ self ._client_main = clickhouse_driver .Client (** DB_KWARGS )
122
127
self ._client_main .execute (f"CREATE DATABASE { self ._db } ;" )
123
- self ._client = clickhouse_driver .Client ("localhost" , database = self ._db )
128
+ self ._client = clickhouse_driver .Client (** DB_KWARGS , database = self ._db )
124
129
self .backend = ClickHouseBackend (
125
- client_fn = lambda : clickhouse_driver .Client ("localhost" , database = self ._db )
130
+ client_fn = lambda : clickhouse_driver .Client (** DB_KWARGS , database = self ._db )
126
131
)
127
132
return
128
133
0 commit comments