Skip to content

Commit a17e743

Browse files
author
aviau
committed
Fixed tests for new line protocol
1 parent 2ea2437 commit a17e743

File tree

2 files changed

+13
-18
lines changed

2 files changed

+13
-18
lines changed

tests/influxdb/client_test.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -207,13 +207,11 @@ def test_write_points_batch(self):
207207
{"measurement": "network", "tags": {"direction": "out"},
208208
"time": "2009-11-10T23:00:00Z", "fields": {"value": 12.00}}
209209
]
210-
expected_last_body = {"tags": {"host": "server01",
211-
"region": "us-west"},
212-
"database": "db",
213-
"points": [{"measurement": "network",
214-
"tags": {"direction": "out"},
215-
"time": "2009-11-10T23:00:00Z",
216-
"fields": {"value": 12.00}}]}
210+
expected_last_body = (
211+
"network,direction=out,host=server01,region=us-west "
212+
"value=12.0 1257894000000000000\n"
213+
)
214+
217215
with requests_mock.Mocker() as m:
218216
m.register_uri(requests_mock.POST,
219217
"http://localhost:8086/write",
@@ -225,7 +223,7 @@ def test_write_points_batch(self):
225223
"region": "us-west"},
226224
batch_size=2)
227225
self.assertEqual(m.call_count, 2)
228-
self.assertEqual(expected_last_body, m.last_request.json())
226+
self.assertEqual(expected_last_body, m.last_request.body)
229227

230228
def test_write_points_udp(self):
231229
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
@@ -240,12 +238,10 @@ def test_write_points_udp(self):
240238

241239
received_data, addr = s.recvfrom(1024)
242240

243-
self.assertDictEqual(
244-
{
245-
"points": self.dummy_points,
246-
"database": "test"
247-
},
248-
json.loads(received_data.decode(), strict=True)
241+
self.assertEqual(
242+
"cpu_load_short,host=server01,region=us-west "
243+
"value=0.64 1257894000000000000\n",
244+
received_data.decode()
249245
)
250246

251247
def test_write_bad_precision_udp(self):

tests/influxdb/dataframe_client_test.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -142,16 +142,15 @@ def test_write_points_from_dataframe_with_time_precision(self):
142142
measurement = "foo"
143143

144144
cli.write_points(dataframe, measurement, time_precision='s')
145-
points.update(precision='s')
146-
self.assertEqual(json.loads(m.last_request.body), points)
145+
self.assertEqual(m.last_request.qs['precision'], ['s'])
147146

148147
cli.write_points(dataframe, measurement, time_precision='m')
149148
points.update(precision='m')
150-
self.assertEqual(json.loads(m.last_request.body), points)
149+
self.assertEqual(m.last_request.qs['precision'], ['m'])
151150

152151
cli.write_points(dataframe, measurement, time_precision='u')
153152
points.update(precision='u')
154-
self.assertEqual(json.loads(m.last_request.body), points)
153+
self.assertEqual(m.last_request.qs['precision'], ['u'])
155154

156155
@raises(TypeError)
157156
def test_write_points_from_dataframe_fails_without_time_index(self):

0 commit comments

Comments
 (0)