@@ -204,12 +204,33 @@ def test_write_points_toplevel_attributes(self):
204
204
json .loads (m .last_request .body )
205
205
)
206
206
207
- @unittest .skip ('Not implemented for 0.9' )
208
207
def test_write_points_batch (self ):
209
- cli = InfluxDBClient ('host' , 8086 , 'username' , 'password' , 'db' )
210
- with _mocked_session (cli , 'post' , 200 , self .dummy_points ):
211
- self .assertTrue (cli .write_points (data = self .dummy_points ,
212
- batch_size = 2 ))
208
+ dummy_points = [
209
+ {"name" : "cpu_usage" , "tags" : {"unit" : "percent" },
210
+ "timestamp" : "2009-11-10T23:00:00Z" , "fields" : {"value" : 12.34 }},
211
+ {"name" : "network" , "tags" : {"direction" : "in" },
212
+ "timestamp" : "2009-11-10T23:00:00Z" , "fields" : {"value" : 123.00 }},
213
+ {"name" : "network" , "tags" : {"direction" : "out" },
214
+ "timestamp" : "2009-11-10T23:00:00Z" , "fields" : {"value" : 12.00 }}
215
+ ]
216
+ expected_last_body = {"tags" : {"host" : "server01" ,
217
+ "region" : "us-west" },
218
+ "database" : "db" ,
219
+ "points" : [{"name" : "network" ,
220
+ "tags" : {"direction" : "out" },
221
+ "timestamp" : "2009-11-10T23:00:00Z" ,
222
+ "fields" : {"value" : 12.00 }}]}
223
+ with requests_mock .Mocker () as m :
224
+ m .register_uri (requests_mock .POST ,
225
+ "http://localhost:8086/write" )
226
+ cli = InfluxDBClient (database = 'db' )
227
+ cli .write_points (points = dummy_points ,
228
+ database = 'db' ,
229
+ tags = {"host" : "server01" ,
230
+ "region" : "us-west" },
231
+ batch_size = 2 )
232
+ self .assertEqual (m .call_count , 2 )
233
+ self .assertEqual (expected_last_body , m .last_request .json ())
213
234
214
235
def test_write_points_udp (self ):
215
236
s = socket .socket (socket .AF_INET , socket .SOCK_DGRAM )
0 commit comments