Skip to content

Commit f9f0da7

Browse files
flierjvshahid
authored andcommitted
Close influxdata#19. support to delete points with test cases. Thanks @flier
1 parent 4b86da4 commit f9f0da7

File tree

2 files changed

+32
-11
lines changed

2 files changed

+32
-11
lines changed

influxdb/client.py

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,25 @@ def write_points_with_precision(self, data, time_precision='s'):
9292

9393
# One Time Deletes
9494

95-
def delete_points(self, name,
96-
regex=None, start_epoch=None, end_epoch=None):
95+
def delete_points(self, name):
9796
"""
98-
TODO: Delete a range of data
99-
100-
2013-11-08: This endpoint has not been implemented yet in ver0.0.8,
101-
but it is documented in http://influxdb.org/docs/api/http.html.
102-
See also: src/api/http/api.go:l57
97+
Delete an entire series
10398
"""
104-
raise NotImplementedError()
99+
url_format = "{0}/db/{1}/series/{2}?u={3}&p={4}"
100+
101+
response = session.delete(url_format.format(
102+
self._baseurl,
103+
self._database,
104+
name,
105+
self._username,
106+
self._password),
107+
headers=self._headers)
108+
109+
if response.status_code == 204:
110+
return True
111+
else:
112+
raise Exception(
113+
"{0}: {1}".format(response.status_code, response.content))
105114

106115
# Regularly Scheduled Deletes
107116

tests/influxdb/client_test.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,22 @@ def test_write_points_with_precision_fails(self):
7777
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
7878
cli.write_points_with_precision([])
7979

80-
@raises(NotImplementedError)
8180
def test_delete_points(self):
82-
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
83-
cli.delete_points([])
81+
with patch.object(session, 'delete') as mocked_post:
82+
mocked_post.return_value = _build_response_object(status_code=204)
83+
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
84+
assert cli.delete_points("foo") is True
85+
86+
assert len(mocked_post.call_args_list) == 1
87+
args, kwds = mocked_post.call_args_list[0]
88+
assert args[0].endswith('/db/db/series/foo?u=username&p=password')
89+
90+
@raises(Exception)
91+
def test_delete_points_with_wrong_name(self):
92+
with patch.object(session, 'delete') as mocked_post:
93+
mocked_post.return_value = _build_response_object(status_code=400)
94+
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
95+
cli.delete_points("nonexist")
8496

8597
@raises(NotImplementedError)
8698
def test_create_scheduled_delete(self):

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