Skip to content

Commit bc90e45

Browse files
author
aviau
committed
Added test_write_points_udp
1 parent 1202aad commit bc90e45

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

tests/influxdb/client_test.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"""
55
import json
66
import requests
7+
import socket
78
from nose.tools import raises
89
from mock import patch
910

@@ -36,7 +37,7 @@ def request(*args, **kwargs):
3637
assert isinstance(data, str)
3738

3839
# Data must be a JSON string
39-
assert c == json.loads(data)
40+
assert c == json.loads(data, strict=True)
4041

4142
c = data
4243

@@ -91,6 +92,27 @@ def test_write_points(self):
9192
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
9293
assert cli.write_points(data) is True
9394

95+
def test_write_points_udp(self):
96+
data = [
97+
{
98+
"points": [
99+
["1", 1, 1.0],
100+
["2", 2, 2.0]
101+
],
102+
"name": "foo",
103+
"columns": ["column_one", "column_two", "column_three"]
104+
}
105+
]
106+
107+
s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
108+
s.bind(('0.0.0.0', 4444))
109+
110+
cli = InfluxDBClient('localhost', 8086, 'root', 'root', 'test', use_udp=True, udp_port=4444)
111+
cli.write_points(data)
112+
113+
received_data, addr = s.recvfrom(1024)
114+
assert data == json.loads(received_data.decode(), strict=True)
115+
94116
@raises(Exception)
95117
def test_write_points_fails(self):
96118
with _mocked_session('post', 500) as mocked:
@@ -273,4 +295,4 @@ def test_delete_database_user(self):
273295
@raises(NotImplementedError)
274296
def test_update_permission(self):
275297
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
276-
cli.update_permission('admin', [])
298+
cli.update_permission('admin', [])

0 commit comments

Comments
 (0)