27
27
import mock
28
28
29
29
from influxdb import InfluxDBClient
30
- from influxdb .client import session
31
30
32
31
33
32
def _build_response_object (status_code = 200 , content = "" ):
@@ -37,7 +36,7 @@ def _build_response_object(status_code=200, content=""):
37
36
return resp
38
37
39
38
40
- def _mocked_session (method = "GET" , status_code = 200 , content = "" ):
39
+ def _mocked_session (cli , method = "GET" , status_code = 200 , content = "" ):
41
40
42
41
method = method .upper ()
43
42
@@ -66,7 +65,7 @@ def request(*args, **kwargs):
66
65
return _build_response_object (status_code = status_code , content = c )
67
66
68
67
mocked = patch .object (
69
- session ,
68
+ cli . _session ,
70
69
'request' ,
71
70
side_effect = request
72
71
)
@@ -164,8 +163,8 @@ def test_write_points(self):
164
163
165
164
@unittest .skip ('Not implemented for 0.9' )
166
165
def test_write_points_batch (self ):
167
- with _mocked_session ( 'post ' , 200 , self . dummy_points ):
168
- cli = InfluxDBClient ( 'host' , 8086 , 'username ' , 'password' , 'db' )
166
+ cli = InfluxDBClient ( 'host ' , 8086 , 'username' , 'password' , 'db' )
167
+ with _mocked_session ( cli , 'post ' , 200 , self . dummy_points ):
169
168
assert cli .write_points (
170
169
data = self .dummy_points ,
171
170
batch_size = 2
@@ -209,8 +208,8 @@ def test_write_bad_precision_udp(self):
209
208
210
209
@raises (Exception )
211
210
def test_write_points_fails (self ):
212
- with _mocked_session ( 'post ' , 500 ):
213
- cli = InfluxDBClient ( 'host' , 8086 , 'username ' , 'password' , 'db' )
211
+ cli = InfluxDBClient ( 'host ' , 8086 , 'username' , 'password' , 'db' )
212
+ with _mocked_session ( cli , 'post ' , 500 ):
214
213
cli .write_points ([])
215
214
216
215
def test_write_points_with_precision (self ):
@@ -248,8 +247,8 @@ def test_write_points_bad_precision(self):
248
247
249
248
@raises (Exception )
250
249
def test_write_points_with_precision_fails (self ):
251
- with _mocked_session ( 'post ' , 500 ):
252
- cli = InfluxDBClient ( 'host' , 8086 , 'username ' , 'password' , 'db' )
250
+ cli = InfluxDBClient ( 'host ' , 8086 , 'username' , 'password' , 'db' )
251
+ with _mocked_session ( cli , 'post ' , 500 ):
253
252
cli .write_points_with_precision ([])
254
253
255
254
def test_query (self ):
@@ -309,7 +308,7 @@ def test_query_chunked(self):
309
308
310
309
@raises (Exception )
311
310
def test_query_fail (self ):
312
- with _mocked_session ('get' , 401 ):
311
+ with _mocked_session (self . cli , 'get' , 401 ):
313
312
self .cli .query ('select column_one from foo;' )
314
313
315
314
def test_create_database (self ):
@@ -327,7 +326,7 @@ def test_create_database(self):
327
326
328
327
@raises (Exception )
329
328
def test_create_database_fails (self ):
330
- with _mocked_session ('post' , 401 ):
329
+ with _mocked_session (self . cli , 'post' , 401 ):
331
330
self .cli .create_database ('new_db' )
332
331
333
332
def test_drop_database (self ):
@@ -345,25 +344,25 @@ def test_drop_database(self):
345
344
346
345
@raises (Exception )
347
346
def test_drop_database_fails (self ):
348
- with _mocked_session ( 'delete ' , 401 ):
349
- cli = InfluxDBClient ( 'host' , 8086 , 'username ' , 'password' , 'db' )
347
+ cli = InfluxDBClient ( 'host ' , 8086 , 'username' , 'password' , 'db' )
348
+ with _mocked_session ( cli , 'delete ' , 401 ):
350
349
cli .drop_database ('old_db' )
351
350
352
351
def test_get_list_database (self ):
353
352
data = {'results' : [{'series' : [
354
353
{'name' : 'databases' , 'columns' : ['name' ],
355
354
'values' : [['mydb' ], ['myotherdb' ]]}]}]}
356
355
357
- with _mocked_session ('get' , 200 , json .dumps (data )):
356
+ with _mocked_session (self . cli , 'get' , 200 , json .dumps (data )):
358
357
self .assertListEqual (
359
358
self .cli .get_list_database (),
360
359
['mydb' , 'myotherdb' ]
361
360
)
362
361
363
362
@raises (Exception )
364
363
def test_get_list_database_fails (self ):
365
- with _mocked_session ( 'get ' , 401 ):
366
- cli = InfluxDBClient ( 'host' , 8086 , 'username ' , 'password' )
364
+ cli = InfluxDBClient ( 'host ' , 8086 , 'username' , 'password' )
365
+ with _mocked_session ( cli , 'get ' , 401 ):
367
366
cli .get_list_database ()
368
367
369
368
def test_get_list_series (self ):
0 commit comments