Skip to content

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

Lines changed: 10 additions & 0 deletions
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

Lines changed: 29 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy