Skip to content

Commit 4f2bb5e

Browse files
author
aviau
committed
Added tests for influxdata#78 + fixed related issues
1 parent e379926 commit 4f2bb5e

File tree

2 files changed

+62
-38
lines changed

2 files changed

+62
-38
lines changed

influxdb/client.py

Lines changed: 11 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -324,8 +324,6 @@ def query(self, query, time_precision='s', chunked=False):
324324

325325
return response.json()
326326

327-
328-
329327
# Creating and Dropping Databases
330328
#
331329
# ### create a database
@@ -417,55 +415,30 @@ def delete_series(self, series):
417415

418416
return True
419417

420-
def get_series_list(self):
418+
def get_list_series(self):
421419
"""
422-
Querying all time series in a database
420+
Get a list of all time series in a database
423421
"""
424422

425-
url = "db/{0}/series".format(self._database)
423+
response = self.query('list series')
426424

427-
params = {
428-
'q': 'list series'
429-
'time_precision': 's',
430-
'chunked': 'false'
431-
}
432-
433-
response = self.request(
434-
url=url,
435-
method='GET',
436-
params=params,
437-
status_code=200
438-
)
439425
series_list = []
440-
for series in response.json()[0]['points']:
426+
for series in response[0]['points']:
441427
series_list.append(series[1])
442428

443429
return series_list
444430

445-
def get_continuous_list(self):
431+
def get_list_continuous_queries(self):
446432
"""
447-
Querying all time series in a database
433+
Get a list of continuous queries
448434
"""
449435

450-
url = "db/{0}/series".format(self._database)
451-
452-
params = {
453-
'q': 'list continuous queries'
454-
'time_precision': 's',
455-
'chunked': 'false'
456-
}
436+
response = self.query('list continuous queries')
437+
queries_list = []
438+
for query in response[0]['points']:
439+
queries_list.append(query[2])
457440

458-
response = self.request(
459-
url=url,
460-
method='GET',
461-
params=params,
462-
status_code=200
463-
)
464-
series_list = []
465-
for series in response.json()[0]['points']:
466-
series_list.append(series[1])
467-
468-
return series_list
441+
return queries_list
469442

470443
# Security
471444
# get list of cluster admins

tests/influxdb/client_test.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,57 @@ def test_delete_series_fails(self):
285285
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
286286
cli.delete_series('old_series')
287287

288+
def test_get_series_list(self):
289+
cli = InfluxDBClient(database='db')
290+
291+
with requests_mock.Mocker() as m:
292+
example_response = \
293+
'[{"name":"list_series_result","columns":' \
294+
'["time","name"],"points":[[0,"foo"],[0,"bar"]]}]'
295+
296+
m.register_uri(
297+
requests_mock.GET,
298+
"http://localhost:8086/db/db/series",
299+
text=example_response
300+
)
301+
302+
self.assertListEqual(
303+
cli.get_list_series(),
304+
['foo', 'bar']
305+
)
306+
307+
def test_get_continuous_queries(self):
308+
cli = InfluxDBClient(database='db')
309+
310+
with requests_mock.Mocker() as m:
311+
312+
# Tip: put this in a json linter!
313+
example_response = '[ { "name": "continuous queries", "columns"' \
314+
': [ "time", "id", "query" ], "points": [ [ ' \
315+
'0, 1, "select foo(bar,95) from \\"foo_bar' \
316+
's\\" group by time(5m) into response_times.' \
317+
'percentiles.5m.95" ], [ 0, 2, "select perce' \
318+
'ntile(value,95) from \\"response_times\\" g' \
319+
'roup by time(5m) into response_times.percen' \
320+
'tiles.5m.95" ] ] } ]'
321+
322+
m.register_uri(
323+
requests_mock.GET,
324+
"http://localhost:8086/db/db/series",
325+
text=example_response
326+
)
327+
328+
self.assertListEqual(
329+
cli.get_list_continuous_queries(),
330+
[
331+
'select foo(bar,95) from "foo_bars" group '
332+
'by time(5m) into response_times.percentiles.5m.95',
333+
334+
'select percentile(value,95) from "response_times" group '
335+
'by time(5m) into response_times.percentiles.5m.95'
336+
]
337+
)
338+
288339
def test_get_list_cluster_admins(self):
289340
pass
290341

0 commit comments

Comments
 (0)