9
9
from mock import patch
10
10
11
11
from influxdb import InfluxDBClient
12
+ from influxdb .client import session
12
13
13
14
14
15
def _build_response_object (status_code = 200 , content = "" ):
@@ -42,14 +43,14 @@ def test_write_points(self):
42
43
}
43
44
]
44
45
45
- with patch .object (requests , 'post' ) as mocked_post :
46
+ with patch .object (session , 'post' ) as mocked_post :
46
47
mocked_post .return_value = _build_response_object (status_code = 200 )
47
48
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
48
49
assert cli .write_points (data ) is True
49
50
50
51
@raises (Exception )
51
52
def test_write_points_fails (self ):
52
- with patch .object (requests , 'post' ) as mocked_post :
53
+ with patch .object (session , 'post' ) as mocked_post :
53
54
mocked_post .return_value = _build_response_object (status_code = 500 )
54
55
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
55
56
cli .write_points ([])
@@ -66,14 +67,14 @@ def test_write_points_with_precision(self):
66
67
}
67
68
]
68
69
69
- with patch .object (requests , 'post' ) as mocked_post :
70
+ with patch .object (session , 'post' ) as mocked_post :
70
71
mocked_post .return_value = _build_response_object (status_code = 200 )
71
72
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
72
73
assert cli .write_points_with_precision (data ) is True
73
74
74
75
@raises (Exception )
75
76
def test_write_points_with_precision_fails (self ):
76
- with patch .object (requests , 'post' ) as mocked_post :
77
+ with patch .object (session , 'post' ) as mocked_post :
77
78
mocked_post .return_value = _build_response_object (status_code = 500 )
78
79
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
79
80
cli .write_points_with_precision ([])
@@ -100,7 +101,7 @@ def test_remove_scheduled_delete(self):
100
101
101
102
def test_query (self ):
102
103
expected = """[{"name":"foo","columns":["time","sequence_number","column_one"],"points":[[1383876043,16,"2"],[1383876043,15,"1"],[1383876035,14,"2"],[1383876035,13,"1"]]}]"""
103
- with patch .object (requests , 'get' ) as mocked_get :
104
+ with patch .object (session , 'get' ) as mocked_get :
104
105
mocked_get .return_value = _build_response_object (
105
106
status_code = 200 ,
106
107
content = expected )
@@ -110,33 +111,33 @@ def test_query(self):
110
111
111
112
@raises (Exception )
112
113
def test_query_fail (self ):
113
- with patch .object (requests , 'get' ) as mocked_get :
114
+ with patch .object (session , 'get' ) as mocked_get :
114
115
mocked_get .return_value = _build_response_object (status_code = 401 )
115
116
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
116
117
cli .query ('select column_one from foo;' )
117
118
118
119
def test_create_database (self ):
119
- with patch .object (requests , 'post' ) as mocked_post :
120
+ with patch .object (session , 'post' ) as mocked_post :
120
121
mocked_post .return_value = _build_response_object (status_code = 201 )
121
122
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
122
123
assert cli .create_database ('new_db' ) is True
123
124
124
125
@raises (Exception )
125
126
def test_creata_database_fails (self ):
126
- with patch .object (requests , 'post' ) as mocked_post :
127
+ with patch .object (session , 'post' ) as mocked_post :
127
128
mocked_post .return_value = _build_response_object (status_code = 401 )
128
129
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
129
130
cli .create_database ('new_db' )
130
131
131
132
def test_delete_database (self ):
132
- with patch .object (requests , 'delete' ) as mocked_post :
133
+ with patch .object (session , 'delete' ) as mocked_post :
133
134
mocked_post .return_value = _build_response_object (status_code = 204 )
134
135
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
135
136
assert cli .delete_database ('old_db' ) is True
136
137
137
138
@raises (Exception )
138
139
def test_delete_database_fails (self ):
139
- with patch .object (requests , 'delete' ) as mocked_post :
140
+ with patch .object (session , 'delete' ) as mocked_post :
140
141
mocked_post .return_value = _build_response_object (status_code = 401 )
141
142
cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
142
143
cli .delete_database ('old_db' )
0 commit comments