29
29
from influxdb import InfluxDBClient , InfluxDBClusterClient
30
30
from influxdb .client import InfluxDBServerError
31
31
32
- DSN_STRING = 'influxdb://uSr:pWd@host:1886/db'
33
- CLUSTER_DSN_STRING = 'influxdb://uSr:pWd@host1:8086,uSr:pWd@host2:8086/db'
34
-
35
32
36
33
def _build_response_object (status_code = 200 , content = "" ):
37
34
resp = requests .Response ()
@@ -98,6 +95,8 @@ def setUp(self):
98
95
}
99
96
]
100
97
98
+ self .dsn_string = 'influxdb://uSr:pWd@host:1886/db'
99
+
101
100
def test_scheme (self ):
102
101
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'database' )
103
102
self .assertEqual ('http://host:8086' , cli ._baseurl )
@@ -108,20 +107,20 @@ def test_scheme(self):
108
107
self .assertEqual ('https://host:8086' , cli ._baseurl )
109
108
110
109
def test_dsn (self ):
111
- cli = InfluxDBClient .from_DSN (DSN_STRING )
110
+ cli = InfluxDBClient .from_DSN (self . dsn_string )
112
111
self .assertEqual ('http://host:1886' , cli ._baseurl )
113
112
self .assertEqual ('uSr' , cli ._username )
114
113
self .assertEqual ('pWd' , cli ._password )
115
114
self .assertEqual ('db' , cli ._database )
116
115
self .assertFalse (cli .use_udp )
117
116
118
- cli = InfluxDBClient .from_DSN ('udp+' + DSN_STRING )
117
+ cli = InfluxDBClient .from_DSN ('udp+' + self . dsn_string )
119
118
self .assertTrue (cli .use_udp )
120
119
121
- cli = InfluxDBClient .from_DSN ('https+' + DSN_STRING )
120
+ cli = InfluxDBClient .from_DSN ('https+' + self . dsn_string )
122
121
self .assertEqual ('https://host:1886' , cli ._baseurl )
123
122
124
- cli = InfluxDBClient .from_DSN ('https+' + DSN_STRING ,
123
+ cli = InfluxDBClient .from_DSN ('https+' + self . dsn_string ,
125
124
** {'ssl' : False })
126
125
self .assertEqual ('http://host:1886' , cli ._baseurl )
127
126
@@ -745,6 +744,7 @@ def setUp(self):
745
744
warnings .simplefilter ('error' , FutureWarning )
746
745
747
746
self .hosts = [('host1' , 8086 ), ('host2' , 8086 ), ('host3' , 8086 )]
747
+ self .dsn_string = 'influxdb://uSr:pWd@host1:8086,uSr:pWd@host2:8086/db'
748
748
749
749
def test_init (self ):
750
750
cluster = InfluxDBClusterClient (hosts = self .hosts ,
@@ -811,7 +811,7 @@ def test_recovery(self):
811
811
self .assertEqual (2 , len (cluster .bad_clients ))
812
812
813
813
def test_dsn (self ):
814
- cli = InfluxDBClusterClient .from_DSN (CLUSTER_DSN_STRING )
814
+ cli = InfluxDBClusterClient .from_DSN (self . dsn_string )
815
815
self .assertEqual (2 , len (cli .clients ))
816
816
self .assertEqual ('http://host1:8086' , cli .clients [0 ]._baseurl )
817
817
self .assertEqual ('uSr' , cli .clients [0 ]._username )
@@ -824,15 +824,15 @@ def test_dsn(self):
824
824
self .assertEqual ('db' , cli .clients [1 ]._database )
825
825
self .assertFalse (cli .clients [1 ].use_udp )
826
826
827
- cli = InfluxDBClusterClient .from_DSN ('udp+' + CLUSTER_DSN_STRING )
827
+ cli = InfluxDBClusterClient .from_DSN ('udp+' + self . dsn_string )
828
828
self .assertTrue (cli .clients [0 ].use_udp )
829
829
self .assertTrue (cli .clients [1 ].use_udp )
830
830
831
- cli = InfluxDBClusterClient .from_DSN ('https+' + CLUSTER_DSN_STRING )
831
+ cli = InfluxDBClusterClient .from_DSN ('https+' + self . dsn_string )
832
832
self .assertEqual ('https://host1:8086' , cli .clients [0 ]._baseurl )
833
833
self .assertEqual ('https://host2:8086' , cli .clients [1 ]._baseurl )
834
834
835
- cli = InfluxDBClusterClient .from_DSN ('https+' + CLUSTER_DSN_STRING ,
835
+ cli = InfluxDBClusterClient .from_DSN ('https+' + self . dsn_string ,
836
836
** {'ssl' : False })
837
837
self .assertEqual ('http://host1:8086' , cli .clients [0 ]._baseurl )
838
838
self .assertEqual ('http://host2:8086' , cli .clients [1 ]._baseurl )
0 commit comments