Skip to content

Commit 09d2d40

Browse files
committed
Merge branch 'db-list'
2 parents 86ca09b + fb67cbe commit 09d2d40

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

influxdb/client.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ class InfluxDBClient(object):
1515
InfluxDB Client
1616
"""
1717

18-
def __init__(self, host, port, username, password, database):
18+
def __init__(self, host='localhost', port=8086, username='root',
19+
password='root', database=None):
1920
"""
2021
Initialize client
2122
"""
@@ -243,6 +244,24 @@ def delete_database(self, database):
243244
raise Exception(
244245
"{0}: {1}".format(response.status_code, response.content))
245246

247+
# ### get list of databases
248+
# curl -X GET http://localhost:8086/db
249+
250+
def get_database_list(self):
251+
"""
252+
Get the list of databases
253+
"""
254+
response = session.get("{0}/db?u={1}&p={2}".format(
255+
self._baseurl,
256+
self._username,
257+
self._password))
258+
259+
if response.status_code == 200:
260+
return json.loads(response.content)
261+
else:
262+
raise Exception(
263+
"{0}: {1}".format(response.status_code, response.content))
264+
246265
# Security
247266
# get list of cluster admins
248267
# curl http://localhost:8086/cluster_admins?u=root&p=root

tests/influxdb/client_test.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,21 @@ def test_delete_database_fails(self):
143143
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
144144
cli.delete_database('old_db')
145145

146+
def test_get_database_list(self):
147+
with patch.object(session, 'get') as mocked_get:
148+
mocked_get.return_value = _build_response_object(
149+
status_code=200, content='[{"name": "a_db"}]')
150+
cli = InfluxDBClient('host', 8086, 'username', 'password')
151+
assert len(cli.get_database_list()) == 1
152+
assert cli.get_database_list()[0]['name'] == 'a_db'
153+
154+
@raises(Exception)
155+
def test_get_database_list_fails(self):
156+
with patch.object(session, 'get') as mocked_get:
157+
mocked_get.return_value = _build_response_object(status_code=401)
158+
cli = InfluxDBClient('host', 8086, 'username', 'password')
159+
cli.get_database_list()
160+
146161
def test_get_list_cluster_admins(self):
147162
pass
148163

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