Skip to content

Commit

Permalink
add ping method to the client (influxdata#409)
Browse files Browse the repository at this point in the history
* add ping method to the client

* capitalize and pep257 compliance

* one more try for pep257 compliance for the ping function

* Update client.py

* Update client_test.py

fixing up failing CI tests

* Update client_test.py

fixing up failing CI tests
  • Loading branch information
pmenglund authored and xginn8 committed Nov 16, 2017
1 parent 2b95797 commit 16c02ec
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions influxdb/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,19 @@ def write_points(self,
retention_policy=retention_policy,
tags=tags, protocol=protocol)

def ping(self):
"""Check connectivity to InfluxDB.
:returns: The version of the InfluxDB the client is connected to
"""
response = self.request(
url="ping",
method='GET',
expected_response_code=204
)

return response.headers['X-Influxdb-Version']

@staticmethod
def _batches(iterable, size):
for i in xrange(0, len(iterable), size):
Expand Down
12 changes: 12 additions & 0 deletions influxdb/tests/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,18 @@ def test_query_fail(self):
with _mocked_session(self.cli, 'get', 401):
self.cli.query('select column_one from foo;')

def test_ping(self):
"""Test ping querying InfluxDB version."""
with requests_mock.Mocker() as m:
m.register_uri(
requests_mock.GET,
"http://localhost:8086/ping",
status_code=204,
headers={'X-Influxdb-Version': '1.2.3'}
)
version = self.cli.ping()
self.assertEqual(version, '1.2.3')

def test_create_database(self):
"""Test create database for TestInfluxDBClient object."""
with requests_mock.Mocker() as m:
Expand Down

0 comments on commit 16c02ec

Please sign in to comment.