33
44from urllib3 import Timeout
55
6+ import crate .client .exceptions
67from crate .client import connect
78from crate .client .connection import Connection
89from crate .client .http import Client
@@ -21,21 +22,27 @@ def test_connection_mock(self):
2122 """
2223
2324 class MyConnectionClient :
24- active_servers = ["localhost:4200" ]
25+ active_servers = [crate_host ]
2526
2627 def __init__ (self ):
2728 pass
2829
2930 def server_infos (self , server ):
30- return ("localhost:4200" , "my server" , "0.42.0" )
31+ return (crate_host , "my server" , "0.42.0" )
3132
3233 connection = connect ([crate_host ], client = MyConnectionClient ())
3334 self .assertIsInstance (connection , Connection )
3435 self .assertEqual (
3536 connection .client .server_infos ("foo" ),
36- ("localhost:4200" , "my server" , "0.42.0" ),
37+ (crate_host , "my server" , "0.42.0" ),
3738 )
3839
40+ def test_invalid_server_address (self ):
41+ client = Client (servers = "localhost:4202" )
42+ with self .assertRaises (crate .client .exceptions .ConnectionError ) as ex :
43+ connect (client = client )
44+ self .assertIn ("Server not available" , ex .exception .message )
45+
3946 def test_lowest_server_version (self ):
4047 infos = [
4148 (None , None , "0.42.3" ),
@@ -50,14 +57,14 @@ def test_lowest_server_version(self):
5057 connection .close ()
5158
5259 def test_invalid_server_version (self ):
53- client = Client (servers = "localhost:4200" )
60+ client = Client (servers = crate_host )
5461 client .server_infos = lambda server : (None , None , "No version" )
5562 connection = connect (client = client )
5663 self .assertEqual ((0 , 0 , 0 ), connection .lowest_server_version .version )
5764 connection .close ()
5865
5966 def test_context_manager (self ):
60- with connect ("localhost:4200" ) as conn :
67+ with connect (crate_host ) as conn :
6168 pass
6269 self .assertEqual (conn ._closed , True )
6370
@@ -70,7 +77,7 @@ def test_with_timezone(self):
7077 """
7178
7279 tz_mst = datetime .timezone (datetime .timedelta (hours = 7 ), name = "MST" )
73- connection = connect ("localhost:4200" , time_zone = tz_mst )
80+ connection = connect (crate_host , time_zone = tz_mst )
7481 cursor = connection .cursor ()
7582 self .assertEqual (cursor .time_zone .tzname (None ), "MST" )
7683 self .assertEqual (
@@ -88,20 +95,20 @@ def test_timeout_float(self):
8895 """
8996 Verify setting the timeout value as a scalar (float) works.
9097 """
91- with connect ("localhost:4200" , timeout = 2.42 ) as conn :
98+ with connect (crate_host , timeout = 2.42 ) as conn :
9299 self .assertEqual (conn .client ._pool_kw ["timeout" ], 2.42 )
93100
94101 def test_timeout_string (self ):
95102 """
96103 Verify setting the timeout value as a scalar (string) works.
97104 """
98- with connect ("localhost:4200" , timeout = "2.42" ) as conn :
105+ with connect (crate_host , timeout = "2.42" ) as conn :
99106 self .assertEqual (conn .client ._pool_kw ["timeout" ], 2.42 )
100107
101108 def test_timeout_object (self ):
102109 """
103110 Verify setting the timeout value as a Timeout object works.
104111 """
105112 timeout = Timeout (connect = 2.42 , read = 0.01 )
106- with connect ("localhost:4200" , timeout = timeout ) as conn :
113+ with connect (crate_host , timeout = timeout ) as conn :
107114 self .assertEqual (conn .client ._pool_kw ["timeout" ], timeout )
0 commit comments