6
6
import unittest
7
7
8
8
import httpretty
9
+ import rx
9
10
10
11
import influxdb2
11
12
from influxdb2 import WritePrecision , WriteService
13
+ from influxdb2 .client .write .point import Point
12
14
from influxdb2 .client .write_api import WriteOptions , WriteApiClient
13
15
from influxdb2_test .base_test import BaseTest
14
16
@@ -132,7 +134,6 @@ def test_batch_size_group_by(self):
132
134
pass
133
135
134
136
def test_recover_from_error (self ):
135
-
136
137
httpretty .register_uri (httpretty .POST , uri = "http://localhost/write" , status = 204 )
137
138
httpretty .register_uri (httpretty .POST , uri = "http://localhost/write" , status = 400 )
138
139
@@ -152,10 +153,48 @@ def test_recover_from_error(self):
152
153
153
154
pass
154
155
155
- @unittest .skip (reason = "TODO" )
156
156
def test_record_types (self ):
157
- self .assertTrue (False , msg = "TODO" )
158
- self .assertTrue (False , msg = "Add observable" )
157
+ httpretty .register_uri (httpretty .POST , uri = "http://localhost/write" , status = 204 )
158
+
159
+ # Record item
160
+ _record = "h2o_feet,location=coyote_creek level\\ water_level=1.0 1"
161
+ self ._write_client .write ("my-bucket" , "my-org" , _record )
162
+
163
+ # Point item
164
+ _point = Point ("h2o_feet" ).tag ("location" , "coyote_creek" ).field ("level water_level" , 2.0 ).time (2 )
165
+ self ._write_client .write ("my-bucket" , "my-org" , _point )
166
+
167
+ # Record list
168
+ self ._write_client .write ("my-bucket" , "my-org" ,
169
+ ["h2o_feet,location=coyote_creek level\\ water_level=3.0 3" ,
170
+ "h2o_feet,location=coyote_creek level\\ water_level=4.0 4" ])
171
+
172
+ # Point list
173
+ _point1 = Point ("h2o_feet" ).tag ("location" , "coyote_creek" ).field ("level water_level" , 5.0 ).time (5 )
174
+ _point2 = Point ("h2o_feet" ).tag ("location" , "coyote_creek" ).field ("level water_level" , 6.0 ).time (6 )
175
+ self ._write_client .write ("my-bucket" , "my-org" , [_point1 , _point2 ])
176
+
177
+ # Observable
178
+ _recordObs = "h2o_feet,location=coyote_creek level\\ water_level=7.0 7"
179
+ _pointObs = Point ("h2o_feet" ).tag ("location" , "coyote_creek" ).field ("level water_level" , 8.0 ).time (8 )
180
+
181
+ self ._write_client .write ("my-bucket" , "my-org" , rx .of (_recordObs , _pointObs ))
182
+
183
+ time .sleep (1 )
184
+
185
+ _requests = httpretty .httpretty .latest_requests
186
+
187
+ self .assertEqual (4 , len (_requests ))
188
+
189
+ self .assertEqual ("h2o_feet,location=coyote_creek level\\ water_level=1.0 1\n "
190
+ "h2o_feet,location=coyote_creek level\\ water_level=2.0 2" , _requests [0 ].parsed_body )
191
+ self .assertEqual ("h2o_feet,location=coyote_creek level\\ water_level=3.0 3\n "
192
+ "h2o_feet,location=coyote_creek level\\ water_level=4.0 4" , _requests [1 ].parsed_body )
193
+ self .assertEqual ("h2o_feet,location=coyote_creek level\\ water_level=5.0 5\n "
194
+ "h2o_feet,location=coyote_creek level\\ water_level=6.0 6" , _requests [2 ].parsed_body )
195
+ self .assertEqual ("h2o_feet,location=coyote_creek level\\ water_level=7.0 7\n "
196
+ "h2o_feet,location=coyote_creek level\\ water_level=8.0 8" , _requests [3 ].parsed_body )
197
+
159
198
pass
160
199
161
200
def test_write_result (self ):
0 commit comments