Skip to content
This repository was archived by the owner on Oct 29, 2024. It is now read-only.

Commit be476a4

Browse files
author
aviau
committed
Added write function
1 parent 3de06c1 commit be476a4

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

influxdb/client.py

+10
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ def request(self, url, method='GET', params=None, data=None,
173173
else:
174174
raise InfluxDBClientError(response.content, response.status_code)
175175

176+
def write(self, data):
177+
self.request(
178+
url="write",
179+
method='POST',
180+
params=None,
181+
data=data,
182+
expected_response_code=200
183+
)
184+
return True
185+
176186
# Writing Data
177187
#
178188
# Assuming you have a database named foo_production you can write data

tests/influxdb/client_test.py

+29
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,35 @@ def test_switch_user(self):
102102
assert cli._username == 'another_username'
103103
assert cli._password == 'another_password'
104104

105+
def test_write(self):
106+
with requests_mock.Mocker() as m:
107+
m.register_uri(
108+
requests_mock.POST,
109+
"http://localhost:8086/write"
110+
)
111+
112+
cli = InfluxDBClient(database='db')
113+
cli.write(
114+
{"database": "mydb",
115+
"retentionPolicy": "mypolicy",
116+
"points": [{"name": "cpu_load_short",
117+
"tags": {"host": "server01",
118+
"region": "us-west"},
119+
"timestamp": "2009-11-10T23:00:00Z",
120+
"values": {"value": 0.64}}]}
121+
)
122+
123+
self.assertEqual(
124+
json.loads(m.last_request.body),
125+
{"database": "mydb",
126+
"retentionPolicy": "mypolicy",
127+
"points": [{"name": "cpu_load_short",
128+
"tags": {"host": "server01",
129+
"region": "us-west"},
130+
"timestamp": "2009-11-10T23:00:00Z",
131+
"values": {"value": 0.64}}]}
132+
)
133+
105134
def test_write_points(self):
106135
with requests_mock.Mocker() as m:
107136
m.register_uri(

0 commit comments

Comments
 (0)