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

add support for get_database_list method #12

Merged
merged 3 commits into from
Mar 3, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class InfluxDBClient(object):
InfluxDB Client
"""

def __init__(self, host, port, username, password, database):
def __init__(self, host='localhost', port=8086, username='root',
password='root', database=None):
"""
Initialize client
"""
Expand Down Expand Up @@ -243,6 +244,24 @@ def delete_database(self, database):
raise Exception(
"{0}: {1}".format(response.status_code, response.content))

# ### get list of databases
# curl -X GET http://localhost:8086/db

def get_database_list(self):
"""
Get the list of databases
"""
response = session.get("{0}/db?u={1}&p={2}".format(
self._baseurl,
self._username,
self._password))

if response.status_code == 200:
return json.loads(response.content)
else:
raise Exception(
"{0}: {1}".format(response.status_code, response.content))

# Security
# get list of cluster admins
# curl http://localhost:8086/cluster_admins?u=root&p=root
Expand Down
15 changes: 15 additions & 0 deletions tests/influxdb/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,21 @@ def test_delete_database_fails(self):
cli = InfluxDBClient('host', 8086, 'username', 'password', 'db')
cli.delete_database('old_db')

def test_get_database_list(self):
with patch.object(session, 'get') as mocked_get:
mocked_get.return_value = _build_response_object(
status_code=200, content='[{"name": "a_db"}]')
cli = InfluxDBClient('host', 8086, 'username', 'password')
assert len(cli.get_database_list()) == 1
assert cli.get_database_list()[0]['name'] == 'a_db'

@raises(Exception)
def test_get_database_list_fails(self):
with patch.object(session, 'get') as mocked_get:
mocked_get.return_value = _build_response_object(status_code=401)
cli = InfluxDBClient('host', 8086, 'username', 'password')
cli.get_database_list()

def test_get_list_cluster_admins(self):
pass

Expand Down
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